Skip to content

Commit

Permalink
Update README and example test
Browse files Browse the repository at this point in the history
  • Loading branch information
kanga333 committed Nov 15, 2020
1 parent 4ae1352 commit f7e9750
Show file tree
Hide file tree
Showing 2 changed files with 194 additions and 0 deletions.
78 changes: 78 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
116 changes: 116 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

0 comments on commit f7e9750

Please sign in to comment.