Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 22 additions & 14 deletions .github/workflows/integration-test.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: 'integration-test'
name: integration test
on: # rebuild any PRs and main branch changes
pull_request:
push:
Expand All @@ -9,11 +9,13 @@ jobs:
test: # make sure the action works on a clean machine without building
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v6
with:
persist-credentials: false
- uses: ./
id: run_action
with:
key: 'keyB'
key: "keyB"
map: |
{
"keyA": {
Expand All @@ -33,7 +35,7 @@ jobs:
}
}
export_to: log,env,output
- name: 'Test Actions Parameters'
- name: "Test Actions Parameters"
run: |
test "${{env.env1B}}" = "value1B"
test "${{env.env2B}}" = "value2B"
Expand All @@ -44,9 +46,9 @@ jobs:
test-readme-example1:
runs-on: ubuntu-latest
steps:
- uses: kanga333/variable-mapper@master
- uses: sagansystems/variable-mapper@master
with:
key: '${{github.base_ref}}'
key: "${{github.base_ref}}"
map: |
{
"master": {
Expand All @@ -70,10 +72,10 @@ jobs:
test-readme-example2:
runs-on: ubuntu-latest
steps:
- uses: kanga333/variable-mapper@master
- uses: sagansystems/variable-mapper@master
id: export
with:
key: '${{github.base_ref}}'
key: "${{github.base_ref}}"
map: |
{
"master": {
Expand All @@ -91,11 +93,13 @@ jobs:
test-readme-example3:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v6
with:
persist-credentials: false
- uses: ./
id: export
with:
key: 'first'
key: "first"
map: |
{
"first": {
Expand All @@ -117,11 +121,13 @@ jobs:
test-readme-example4:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v6
with:
persist-credentials: false
- uses: ./
id: export
with:
key: 'first'
key: "first"
map: |
{
"first": {
Expand All @@ -143,11 +149,13 @@ jobs:
test-readme-example5:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v6
with:
persist-credentials: false
- uses: ./
id: export
with:
key: 'first'
key: "first"
map: |
{
"first": {
Expand Down
14 changes: 7 additions & 7 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ on:
branches:
- master
paths:
- 'package.json'
- "package.json"

name: Create Release if version is bumped
jobs:
Expand All @@ -12,13 +12,13 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v6
- run: git fetch --prune --unshallow --tags
- uses: kanga333/config-value-exporter@main
id: version
with:
key: version
file: package.json
- id: version
name: Read version from package.json
run: |
version=$(jq -r '.version' package.json)
echo "result=${version}" >> "$GITHUB_OUTPUT"
- id: tag_check
run: |
git rev-parse v${{steps.version.outputs.result}} 2> /dev/null \
Expand Down
6 changes: 4 additions & 2 deletions .github/workflows/unit-test.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: 'unit-test'
name: unit test
on: # rebuild any PRs and main branch changes
pull_request:
push:
Expand All @@ -9,7 +9,9 @@ jobs:
build_and_test: # make sure build/ci work properly
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v6
with:
persist-credentials: false
- run: |
npm install
npm run all
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -201,3 +201,32 @@ jobs:
```

In this workflow, `env1:value1`, `env2:value2` and `env3:value3` export as env.

### Prefixing exported variable names

Use `variable_prefix` to prepend a string to every exported variable name. This
is useful for namespacing exports to avoid collisions with variables from other
steps. The prefix is concatenated literally, so include any separator yourself.

```yaml
on: [push]
name: Prefixed exports
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: kanga333/variable-mapper@master

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion (consistency): This new example uses kanga333/variable-mapper@master, but the integration-test workflow now uses sagansystems/variable-mapper@master for its readme-example jobs. The rest of the README still references kanga333, so matching the existing convention is defensible — but since you're adding a brand-new section in this PR, it would be a good moment to use sagansystems/variable-mapper@master here (and optionally do a one-pass update of the older examples in the same commit). Folks copy/pasting from README expect the example to point at the fork they're consuming.

with:
key: 'first'
map: |
{
"first": {
"env1": "value1",
"env2": "value2"
}
}
export_to: env

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion (demonstrate the docs claim): The action input description and PR body emphasize that variable_prefix is applied across log, env, and output targets, but this example only exercises env. Consider export_to: log,env,output plus a - run: echo "${{ steps.export.outputs.MYAPP_env1 }}" step (and add an id: to the action step) so the example visibly shows the prefix landing on every destination — matches the testing recipe you already wrote in the PR description.

variable_prefix: 'MYAPP_'
- run: echo $MYAPP_env1 $MYAPP_env2
```

12 changes: 12 additions & 0 deletions __tests__/exporter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,18 @@ describe('exporter', () => {
exporter.exportLog('key', 'value')
assertWriteCalls([`export key: value${os.EOL}`])
})

it('getExporters applies prefix to log exporter', () => {
const [logExporter] = exporter.getExporters('log', 'MYAPP_')
logExporter('key', 'value')
assertWriteCalls([`export MYAPP_key: value${os.EOL}`])
})

it('getExporters omits prefix when empty', () => {
const [logExporter] = exporter.getExporters('log', '')
logExporter('key', 'value')
assertWriteCalls([`export key: value${os.EOL}`])
})

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion (coverage): Both new tests exercise only the log exporter. The withPrefix wrapper is structurally identical for the other two targets, but a regression in the switch-case wiring (e.g., forgetting to wrap core.exportVariable or core.setOutput) wouldn't be caught here. A small jest.spyOn(core, 'exportVariable') / jest.spyOn(core, 'setOutput') test confirming each is called with MYAPP_key/value when getExporters('env,output', 'MYAPP_') is invoked would close that gap and is cheap to add.

})

// Assert that process.stdout.write calls called only with the given arguments.
Expand Down
8 changes: 7 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ inputs:
Specify the behavior of getting the variable. first_match, overwrite and
fill are valid values.
default: 'first_match'
variable_prefix:
description: |
Optional prefix prepended to every exported variable name (across log,
env and output targets). Useful for avoiding collisions. The value is
concatenated literally, so include any separator yourself (e.g. "MYAPP_").
default: ''
runs:
using: 'node20'
using: 'node24'
main: 'dist/index.js'

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: Worth verifying in the testing step that GitHub Actions has Node 24 GA as a supported using: runtime — the docs list node20 as the current default, with node24 recently added. The PR's testing plan covers this ("in the 'Set up job' logs, confirm GitHub reports Node.js 24.x"), so this is just a flag that if Node 24 ends up unavailable on the runner, the action will fail to start with no useful error. If that becomes a problem, node20 would still work.

Loading
Loading