Skip to content
Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
View on Marketplace

Repository files navigation

GitHub Action to simplify variable remapping

Single-Variable-Mapper action maps variable by regular expressions.

Build & DeployCoverage Status

Sample Workflows

Map using regular expression

name: single-variable-mapper exampleon:
workflow_dispatch:
inputs:
env:
description: 'Where to deploy'required: truedefault: 'staging.project.com'type: choiceoptions:
- '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-lateststeps:
- name: Map deployment target to environment configuses: caseycs/single-variable-mapper@masterid: mapperwith:
key: '${{ github.event.inputs.env }}'map: | staging(-\d+)?: staging sandbox(-\d+)?: sandbox project.com: prod - name: Print mapped valuerun: echo ${{ steps.mapper.outputs.value }}# staging for staging-X.project.com or staging.project.com

Remap string value

Also showcasing different output options

- uses: caseycs/single-variable-mapper@masterwith:
key: sandboxmap: | sandbox: preprodexport_to: envexport_to_env_name: mapper_value
- name: Print mapped valuerun: | echo ${{ env.mapper_value }}# preprod

Custom separator

- uses: caseycs/single-variable-mapper@masterid: mapperwith:
key: staging-25map: | staging-\d+|stagingseparator: '|'
- name: Print mapped valuerun: | echo ${{ steps.mapper.outputs.value }}# staging

Pattern Matching Behavior

When 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@masterid: mapperwith:
key: staging-1map: | staging-\d+: env-numbered staging-1: env-specific# Output: env-numbered (first match wins)

Modes

  • fallback-to-default - use default value when no match was found
  • fallback-to-original - use original key when no match was found
  • strict (default) - fail when no match was found
- uses: caseycs/single-variable-mapper@masterid: mapperwith:
key: stagingmap: | sandbox: preprodmode: fallback-to-original
- name: Print mapped valuerun: | echo ${{ steps.mapper.outputs.value }}# staging
- uses: caseycs/single-variable-mapper@masterid: mapperwith:
key: stagingmap: | sandbox: preprodmode: fallback-to-defaultdefault: playground
- name: Print mapped valuerun: | echo ${{ steps.mapper.outputs.value }}# playground

Edge case - map can be empty

Mode strict is not supported in this case

- uses: caseycs/single-variable-mapper@masterid: mapperwith:
key: staging-5map: ''mode: fallback-to-originalallow_empty_map: true
- name: Print mapped valuerun: | echo ${{ steps.mapper.outputs.value }}# staging-5

About

Github action to simplify mapping by a specific key

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages