Single-Variable-Mapper action maps variable by regular expressions.
name: single-variable-mapper example
on:
workflow_dispatch:
inputs:
env:
description: 'Where to deploy'
required: true
default: 'staging.project.com'
type: choice
options:
- 'staging.project.com'
- 'staging-1.project.com'
- 'staging-2.project.com'
- 'sandbox.project.com'
- 'sandbox-1.project.com'
- 'sandbox-2.project.com'
- 'project.com'
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Map deployment target to environment config
uses: caseycs/single-variable-mapper@master
id: mapper
with:
key: '${{ github.event.inputs.env }}'
map: |
staging(-\d+)?: staging
sandbox(-\d+)?: sandbox
project.com: prod
- name: Print mapped value
run: echo ${{ steps.mapper.outputs.value }}
# staging for staging-X.project.com or staging.project.comAlso showcasing different output options
- uses: caseycs/single-variable-mapper@master
with:
key: sandbox
map: |
sandbox: preprod
export_to: env
export_to_env_name: mapper_value
- name: Print mapped value
run: |
echo ${{ env.mapper_value }}
# preprod- uses: caseycs/single-variable-mapper@master
id: mapper
with:
key: staging-25
map: |
staging-\d+|staging
separator: '|'
- name: Print mapped value
run: |
echo ${{ steps.mapper.outputs.value }}
# stagingWhen multiple patterns match the input key, the first matching pattern is used. Patterns are evaluated in the order they appear in the map.
- uses: caseycs/single-variable-mapper@master
id: mapper
with:
key: staging-1
map: |
staging-\d+: env-numbered
staging-1: env-specific
# Output: env-numbered (first match wins)fallback-to-default- use default value when no match was foundfallback-to-original- use original key when no match was foundstrict(default) - fail when no match was found
- uses: caseycs/single-variable-mapper@master
id: mapper
with:
key: staging
map: |
sandbox: preprod
mode: fallback-to-original
- name: Print mapped value
run: |
echo ${{ steps.mapper.outputs.value }}
# staging- uses: caseycs/single-variable-mapper@master
id: mapper
with:
key: staging
map: |
sandbox: preprod
mode: fallback-to-default
default: playground
- name: Print mapped value
run: |
echo ${{ steps.mapper.outputs.value }}
# playgroundMode strict is not supported in this case
- uses: caseycs/single-variable-mapper@master
id: mapper
with:
key: staging-5
map: ''
mode: fallback-to-original
allow_empty_map: true
- name: Print mapped value
run: |
echo ${{ steps.mapper.outputs.value }}
# staging-5