From f7e9750b22bd2e05f6c50982bcf1a4d33bc8c38d Mon Sep 17 00:00:00 2001 From: kanga333 Date: Sun, 15 Nov 2020 21:22:02 +0900 Subject: [PATCH] Update README and example test --- .github/workflows/test.yml | 78 +++++++++++++++++++++++++ README.md | 116 +++++++++++++++++++++++++++++++++++++ 2 files changed, 194 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index ad54895..2014a71 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -114,3 +114,81 @@ jobs: run: | echo ${{ env.environment }} echo ${{ steps.export.outputs.environment }} + test-readme-example3: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - uses: ./ + id: export + with: + key: "first" + map: | + { + "first": { + "env1": "value1", + "env2": "value2" + }, + ".*": { + "env1": "value1_overwrite", + "env3": "value3" + } + } + export_to: env + mode: first_match + - name: Echo environment and output + run: | + test "${{ env.env1 }}" = "value1" + test "${{ env.env2 }}" = "value2" + test "${{ env.env3 }}" = "" + test-readme-example4: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - uses: ./ + id: export + with: + key: "first" + map: | + { + "first": { + "env1": "value1", + "env2": "value2" + }, + ".*": { + "env1": "value1_overwrite", + "env3": "value3" + } + } + export_to: env + mode: overwrite + - name: Echo environment and output + run: | + test "${{ env.env1 }}" = "value1_overwrite" + test "${{ env.env2 }}" = "value2" + test "${{ env.env3 }}" = "value3" + test-readme-example5: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - uses: ./ + id: export + with: + key: "first" + map: | + { + "first": { + "env1": "value1", + "env2": "value2" + }, + ".*": { + "env1": "value1_overwrite", + "env3": "value3" + } + } + export_to: env + mode: fill + - name: Echo environment and output + run: | + test "${{ env.env1 }}" = "value1" + test "${{ env.env2 }}" = "value2" + test "${{ env.env3 }}" = "value3" diff --git a/README.md b/README.md index 9cba1cf..b1ccc27 100644 --- a/README.md +++ b/README.md @@ -77,3 +77,119 @@ jobs: ``` The variables can be exported to log, env and output. (Default is `log,env`) + +### Switching the behavior of getting the variable + +The `mode` option can be used to change the behavior of getting variables. +`first_match`, `overwrite` and `fill` are valid values. + +#### first_match mode (default) + +`first_match` evaluates the regular expression of a key in order from the top and gets the variable for the first key to be matched. + +```yaml +on: [push] +name: Export variables to output and environment and log +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: kanga333/variable-mapper@master + id: export + with: + key: "first" + map: | + { + "first": { + "env1": "value1", + "env2": "value2" + }, + ".*": { + "env1": "value1_overwrite", + "env3": "value3" + } + } + export_to: env + mode: first_match + - name: Echo environment and output + run: | + echo ${{ env.env1 }} + echo ${{ env.env2 }} + echo ${{ env.env3 }} +``` + +In this workflow, only `env1:value1` and `env2:value2` are exported as env. + +#### overwrite mode + +`overwrite` evaluates the regular expression of the keys in order from the top, and then merges the variables associated with the matched keys in turn. If the same variable is defined, the later evaluated value is overwritten. + +```yaml +on: [push] +name: Export variables to output and environment and log +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: kanga333/variable-mapper@master + id: export + with: + key: "first" + map: | + { + "first": { + "env1": "value1", + "env2": "value2" + }, + ".*": { + "env1": "value1_overwrite", + "env3": "value3" + } + } + export_to: env + mode: overwrite + - name: Echo environment and output + run: | + echo ${{ env.env1 }} + echo ${{ env.env2 }} + echo ${{ env.env3 }} +``` + +In this workflow, `env1:value1_overwrite`, `env2:value2` and `env2:value2` export as env. + +#### fill mode + +`fill` evaluates the regular expression of the keys in order from the top, and then merges the variables associated with the matched keys in turn. If the same variable is defined, later evaluated values are ignored and the first evaluated value takes precedence. + +```yaml +on: [push] +name: Export variables to output and environment and log +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: kanga333/variable-mapper@master + id: export + with: + key: "first" + map: | + { + "first": { + "env1": "value1", + "env2": "value2" + }, + ".*": { + "env1": "value1_overwrite", + "env3": "value3" + } + } + export_to: env + mode: overwrite + - name: Echo environment and output + run: | + echo ${{ env.env1 }} + echo ${{ env.env2 }} + echo ${{ env.env3 }} +``` + +In this workflow, `env1:value1`, `env2:value2` and `env2:value2` export as env.