Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue: Environment variables are merged in wrong order #777

Closed
psxcode opened this issue Aug 15, 2021 · 1 comment · Fixed by #832
Closed

Issue: Environment variables are merged in wrong order #777

psxcode opened this issue Aug 15, 2021 · 1 comment · Fixed by #832
Assignees
Labels
kind/bug Something isn't working meta/resolved Issue has been fixed or valid solution has been provided (not workaround)

Comments

@psxcode
Copy link

psxcode commented Aug 15, 2021

System information

- Operating System: macOS
- Architecture: x64 (64-bit)
- Apple M1: no
- Docker version: 20.10.7
- Docker image used in `act`: image=catthehacker/ubuntu:act-latest
- `act` version: 0.2.24

Expected behaviour

Environment variable defined locally in the Step should override the ones defined in Previous Steps.

Actual behaviour

Environment variable defined locally in the Step are ignored when collide with the ones defined in Previous Steps.
Think the incorrect merging happens here

Workflow and/or repository

name: Node.js Package
on:
  push
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      # Setup .npmrc file to publish to npm
      - uses: actions/checkout@v2
      - uses: actions/setup-node@v2
        with:
          node-version: '12.x'
          registry-url: 'https://registry.npmjs.org'
      - run: |
          echo ${NODE_AUTH_TOKEN}
          npm who
        env:
          NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

Here actions/setup-node exports NODE_AUTH_TOKEN set to XXXX-XXXX-XXXX-XXXX.
See the code here
The Next Step has same locally defined variable, set to secrets.NPM_TOKEN.

Steps to reproduce

  1. Create new workflow setup using the example above
  2. Create .secrets file with NPM_TOKEN=<any string>.
  3. Run act
  4. See XXXX-XXXX-XXXX-XXXX instead of <any_string> printed in the log

act output

Log
[Node.js Package/build] 🚀  Start image=catthehacker/ubuntu:act-latest
[Node.js Package/build]   🐳  docker pull catthehacker/ubuntu:act-latest
[Node.js Package/build] Removed container: a0990c4f6f00e1d7a89b07bfebfe043231bd08d1615ca45cb7a09efb022e0ccc
[Node.js Package/build]   🐳  docker volume rm act-Node-js-Package-build
[Node.js Package/build]   🐳  docker create image=catthehacker/ubuntu:act-latest platform= entrypoint=["/usr/bin/tail" "-f" "/dev/null"] cmd=[]
[Node.js Package/build] Created container name=act-Node-js-Package-build id=79b550b28001a48e8c0621709b57da5010b99df821682647872ee54c9f3e5f39 from image catthehacker/ubuntu:act-latest (platform: )
[Node.js Package/build] ENV ==> [RUNNER_TOOL_CACHE=/opt/hostedtoolcache RUNNER_OS=Linux RUNNER_TEMP=/tmp]
[Node.js Package/build]   🐳  docker run image=catthehacker/ubuntu:act-latest platform= entrypoint=["/usr/bin/tail" "-f" "/dev/null"] cmd=[]
[Node.js Package/build] Starting container: 79b550b28001a48e8c0621709b57da5010b99df821682647872ee54c9f3e5f39
[Node.js Package/build] Started container: 79b550b28001a48e8c0621709b57da5010b99df821682647872ee54c9f3e5f39
[Node.js Package/build]   🐳  docker exec cmd=[mkdir -m 0777 -p /var/run/act] user=root
[Node.js Package/build] Exec command '[mkdir -m 0777 -p /var/run/act]'
[Node.js Package/build]   🐳  docker cp src=/Users/psx/dev/act-test/. dst=/Users/psx/dev/act-test
[Node.js Package/build]   🐳  docker exec cmd=[mkdir -p /Users/psx/dev/act-test] user=
[Node.js Package/build] Exec command '[mkdir -p /Users/psx/dev/act-test]'
[Node.js Package/build] Extracting content from '/var/folders/w0/xrh58xjx21bbhkyfcmpsl9t40000gn/T/act283057225' to '/Users/psx/dev/act-test'
[Node.js Package/build] Extracting content to '/var/run/act/'
[Node.js Package/build] setupEnv => map[ACT:true AGENT_TOOLSDIRECTORY:/opt/hostedtoolcache CI:true DEPLOYMENT_BASEPATH:/opt/runner GITHUB_ACTION:0 GITHUB_ACTIONS:true GITHUB_ACTION_REF: GITHUB_ACTION_REPOSITORY: GITHUB_ACTOR:nektos/act GITHUB_API_URL:https://api.github.com GITHUB_BASE_REF: GITHUB_ENV:/var/run/act/workflow/envs.txt GITHUB_EVENT_NAME:push GITHUB_EVENT_PATH:/var/run/act/workflow/event.json GITHUB_GRAPHQL_URL:https://api.github.com/graphql GITHUB_HEAD_REF: GITHUB_JOB:build GITHUB_PATH:/var/run/act/workflow/paths.txt GITHUB_REF:refs/heads/master GITHUB_REPOSITORY:psxcode/act-test GITHUB_REPOSITORY_OWNER:psxcode GITHUB_RETENTION_DAYS:0 GITHUB_RUN_ID:1 GITHUB_RUN_NUMBER:1 GITHUB_SERVER_URL:https://github.com GITHUB_SHA:685afc65211e203a87b1a3e59afff564bc73e235 GITHUB_TOKEN: GITHUB_WORKFLOW:Node.js Package GITHUB_WORKSPACE:/Users/psx/dev/act-test IMAGE_OS:ubuntu20 ImageOS:ubuntu20 LSB_OS_VERSION:2004 LSB_RELEASE:20.04 PATH:/opt/hostedtoolcache/node/14.17.4/x64/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin RUNNER_PERFLOG:/dev/null RUNNER_TRACKING_ID: RUNNER_USER:root RUN_TOOL_CACHE:/opt/hostedtoolcache USER:root]
[Node.js Package/build] ⭐  Run actions/checkout@v2
[Node.js Package/build] Skipping local actions/checkout because workdir was already copied
[Node.js Package/build]   ✅  Success - actions/checkout@v2
[Node.js Package/build] setupEnv => map[ACT:true AGENT_TOOLSDIRECTORY:/opt/hostedtoolcache CI:true DEPLOYMENT_BASEPATH:/opt/runner GITHUB_ACTION:1 GITHUB_ACTIONS:true GITHUB_ACTION_REF: GITHUB_ACTION_REPOSITORY: GITHUB_ACTOR:nektos/act GITHUB_API_URL:https://api.github.com GITHUB_BASE_REF: GITHUB_ENV:/var/run/act/workflow/envs.txt GITHUB_EVENT_NAME:push GITHUB_EVENT_PATH:/var/run/act/workflow/event.json GITHUB_GRAPHQL_URL:https://api.github.com/graphql GITHUB_HEAD_REF: GITHUB_JOB:build GITHUB_PATH:/var/run/act/workflow/paths.txt GITHUB_REF:refs/heads/master GITHUB_REPOSITORY:psxcode/act-test GITHUB_REPOSITORY_OWNER:psxcode GITHUB_RETENTION_DAYS:0 GITHUB_RUN_ID:1 GITHUB_RUN_NUMBER:1 GITHUB_SERVER_URL:https://github.com GITHUB_SHA:685afc65211e203a87b1a3e59afff564bc73e235 GITHUB_TOKEN: GITHUB_WORKFLOW:Node.js Package GITHUB_WORKSPACE:/Users/psx/dev/act-test IMAGE_OS:ubuntu20 INPUT_NODE-VERSION:12.x INPUT_REGISTRY-URL:https://registry.npmjs.org ImageOS:ubuntu20 LSB_OS_VERSION:2004 LSB_RELEASE:20.04 PATH:/opt/hostedtoolcache/node/14.17.4/x64/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin RUNNER_PERFLOG:/dev/null RUNNER_TRACKING_ID: RUNNER_USER:root RUN_TOOL_CACHE:/opt/hostedtoolcache USER:root]
[Node.js Package/build] ⭐  Run actions/setup-node@v2
[Node.js Package/build]   🐳  docker cp src=/Users/psx/.cache/act/actions-setup-node@v2/ dst=/var/run/act/actions/actions-setup-node@v2/
[Node.js Package/build]   🐳  docker exec cmd=[mkdir -p /var/run/act/actions/actions-setup-node@v2/] user=
[Node.js Package/build] Exec command '[mkdir -p /var/run/act/actions/actions-setup-node@v2/]'
[Node.js Package/build] Extracting content from '/var/folders/w0/xrh58xjx21bbhkyfcmpsl9t40000gn/T/act223943444' to '/var/run/act/actions/actions-setup-node@v2/'
[Node.js Package/build]   🐳  docker exec cmd=[node /var/run/act/actions/actions-setup-node@v2/dist/setup/index.js] user=
[Node.js Package/build] Exec command '[node /var/run/act/actions/actions-setup-node@v2/dist/setup/index.js]'
[Node.js Package/build]   💬  ::debug::isExplicit: 
[Node.js Package/build]   💬  ::debug::explicit? false
[Node.js Package/build]   💬  ::debug::isExplicit: 14.17.4
[Node.js Package/build]   💬  ::debug::explicit? true
[Node.js Package/build]   💬  ::debug::evaluating 0 versions
[Node.js Package/build]   💬  ::debug::match not found
[Node.js Package/build]   | Attempting to download 12.x...
[Node.js Package/build]   💬  ::debug::No manifest cached
[Node.js Package/build]   💬  ::debug::Getting manifest from actions/node-versions@main
[Node.js Package/build]   💬  ::debug::check 16.6.2 satisfies 12.x
[Node.js Package/build]   💬  ::debug::check 16.6.1 satisfies 12.x
[Node.js Package/build]   💬  ::debug::check 16.6.0 satisfies 12.x
[Node.js Package/build]   💬  ::debug::check 16.5.0 satisfies 12.x
[Node.js Package/build]   💬  ::debug::check 16.4.2 satisfies 12.x
[Node.js Package/build]   💬  ::debug::check 16.4.1 satisfies 12.x
[Node.js Package/build]   💬  ::debug::check 16.4.0 satisfies 12.x
[Node.js Package/build]   💬  ::debug::check 16.3.0 satisfies 12.x
[Node.js Package/build]   💬  ::debug::check 16.2.0 satisfies 12.x
[Node.js Package/build]   💬  ::debug::check 16.1.0 satisfies 12.x
[Node.js Package/build]   💬  ::debug::check 16.0.0 satisfies 12.x
[Node.js Package/build]   💬  ::debug::check 14.17.5 satisfies 12.x
[Node.js Package/build]   💬  ::debug::check 14.17.4 satisfies 12.x
[Node.js Package/build]   💬  ::debug::check 14.17.3 satisfies 12.x
[Node.js Package/build]   💬  ::debug::check 14.17.2 satisfies 12.x
[Node.js Package/build]   💬  ::debug::check 14.17.1 satisfies 12.x
[Node.js Package/build]   💬  ::debug::check 14.17.0 satisfies 12.x
[Node.js Package/build]   💬  ::debug::check 14.16.1 satisfies 12.x
[Node.js Package/build]   💬  ::debug::check 14.16.0 satisfies 12.x
[Node.js Package/build]   💬  ::debug::check 14.15.5 satisfies 12.x
[Node.js Package/build]   💬  ::debug::check 14.15.4 satisfies 12.x
[Node.js Package/build]   💬  ::debug::check 14.15.3 satisfies 12.x
[Node.js Package/build]   💬  ::debug::check 14.15.2 satisfies 12.x
[Node.js Package/build]   💬  ::debug::check 14.15.1 satisfies 12.x
[Node.js Package/build]   💬  ::debug::check 14.15.0 satisfies 12.x
[Node.js Package/build]   💬  ::debug::check 14.14.0 satisfies 12.x
[Node.js Package/build]   💬  ::debug::check 14.13.1 satisfies 12.x
[Node.js Package/build]   💬  ::debug::check 14.13.0 satisfies 12.x
[Node.js Package/build]   💬  ::debug::check 14.12.0 satisfies 12.x
[Node.js Package/build]   💬  ::debug::check 14.11.0 satisfies 12.x
[Node.js Package/build]   💬  ::debug::check 14.10.1 satisfies 12.x
[Node.js Package/build]   💬  ::debug::check 14.10.0 satisfies 12.x
[Node.js Package/build]   💬  ::debug::check 14.9.0 satisfies 12.x
[Node.js Package/build]   💬  ::debug::check 14.8.0 satisfies 12.x
[Node.js Package/build]   💬  ::debug::check 14.7.0 satisfies 12.x
[Node.js Package/build]   💬  ::debug::check 14.6.0 satisfies 12.x
[Node.js Package/build]   💬  ::debug::check 14.5.0 satisfies 12.x
[Node.js Package/build]   💬  ::debug::check 14.4.0 satisfies 12.x
[Node.js Package/build]   💬  ::debug::check 14.3.0 satisfies 12.x
[Node.js Package/build]   💬  ::debug::check 14.2.0 satisfies 12.x
[Node.js Package/build]   💬  ::debug::check 14.1.0 satisfies 12.x
[Node.js Package/build]   💬  ::debug::check 14.0.0 satisfies 12.x
[Node.js Package/build]   💬  ::debug::check 13.14.0 satisfies 12.x
[Node.js Package/build]   💬  ::debug::check 13.13.0 satisfies 12.x
[Node.js Package/build]   💬  ::debug::check 12.22.5 satisfies 12.x
[Node.js Package/build]   💬  ::debug::x64===x64 && darwin===linux
[Node.js Package/build]   💬  ::debug::x64===x64 && linux===linux
[Node.js Package/build]   💬  ::debug::matched 12.22.5
[Node.js Package/build]   | Acquiring 12.22.5 - x64 from https://github.com/actions/node-versions/releases/download/12.22.5-1122930631/node-12.22.5-linux-x64.tar.gz
[Node.js Package/build]   💬  ::debug::Downloading https://github.com/actions/node-versions/releases/download/12.22.5-1122930631/node-12.22.5-linux-x64.tar.gz
[Node.js Package/build]   💬  ::debug::Destination /tmp/029010c5-1f17-4bc9-87b9-859793a428c2
[Node.js Package/build]   💬  ::debug::download complete
[Node.js Package/build]   | Extracting ...
[Node.js Package/build]   💬  ::debug::Checking tar --version
[Node.js Package/build]   💬  ::debug::tar (GNU tar) 1.30%0ACopyright (C) 2017 Free Software Foundation, Inc.%0ALicense GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.%0AThis is free software: you are free to change and redistribute it.%0AThere is NO WARRANTY, to the extent permitted by law.%0A%0AWritten by John Gilmore and Jay Fenlason.
[Node.js Package/build]   | [command]/usr/bin/tar xz --strip 1 --warning=no-unknown-keyword -C /tmp/d4d103a8-87ae-43a4-9e95-8ef37c27de31 -f /tmp/029010c5-1f17-4bc9-87b9-859793a428c2
[Node.js Package/build]   | Adding to the cache ...
[Node.js Package/build]   💬  ::debug::Caching tool node 12.22.5 x64
[Node.js Package/build]   💬  ::debug::source dir: /tmp/d4d103a8-87ae-43a4-9e95-8ef37c27de31
[Node.js Package/build]   💬  ::debug::destination /opt/hostedtoolcache/node/12.22.5/x64
[Node.js Package/build]   💬  ::debug::finished caching tool
[Node.js Package/build]   | Done
[Node.js Package/build]   💬  ::debug::Setting auth in /tmp/.npmrc
[Node.js Package/build]   ❓  ##[add-matcher]/run/act/actions/actions-setup-node@v2/.github/tsc.json
[Node.js Package/build]   ❓  ##[add-matcher]/run/act/actions/actions-setup-node@v2/.github/eslint-stylish.json
[Node.js Package/build]   ❓  ##[add-matcher]/run/act/actions/actions-setup-node@v2/.github/eslint-compact.json
[Node.js Package/build]   ✅  Success - actions/setup-node@v2
[Node.js Package/build] setupEnv => map[ACT:true AGENT_TOOLSDIRECTORY:/opt/hostedtoolcache CI:true DEPLOYMENT_BASEPATH:/opt/runner GITHUB_ACTION:2 GITHUB_ACTIONS:true GITHUB_ACTION_REF: GITHUB_ACTION_REPOSITORY: GITHUB_ACTOR:nektos/act GITHUB_API_URL:https://api.github.com GITHUB_BASE_REF: GITHUB_ENV:/var/run/act/workflow/envs.txt GITHUB_EVENT_NAME:push GITHUB_EVENT_PATH:/var/run/act/workflow/event.json GITHUB_GRAPHQL_URL:https://api.github.com/graphql GITHUB_HEAD_REF: GITHUB_JOB:build GITHUB_PATH:/var/run/act/workflow/paths.txt GITHUB_REF:refs/heads/master GITHUB_REPOSITORY:psxcode/act-test GITHUB_REPOSITORY_OWNER:psxcode GITHUB_RETENTION_DAYS:0 GITHUB_RUN_ID:1 GITHUB_RUN_NUMBER:1 GITHUB_SERVER_URL:https://github.com GITHUB_SHA:685afc65211e203a87b1a3e59afff564bc73e235 GITHUB_TOKEN: GITHUB_WORKFLOW:Node.js Package GITHUB_WORKSPACE:/Users/psx/dev/act-test IMAGE_OS:ubuntu20 ImageOS:ubuntu20 LSB_OS_VERSION:2004 LSB_RELEASE:20.04 NODE_AUTH_TOKEN:XXXXX-XXXXX-XXXXX-XXXXX NPM_CONFIG_USERCONFIG:/tmp/.npmrc PATH:/opt/hostedtoolcache/node/12.22.5/x64/bin:/opt/hostedtoolcache/node/14.17.4/x64/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin RUNNER_PERFLOG:/dev/null RUNNER_TRACKING_ID: RUNNER_USER:root RUN_TOOL_CACHE:/opt/hostedtoolcache USER:root]
[Node.js Package/build] ⭐  Run echo ${NODE_AUTH_TOKEN}
npm who
[Node.js Package/build] Extracting content to '/Users/psx/dev/act-test'
[Node.js Package/build]   🐳  docker exec cmd=[bash --noprofile --norc -e -o pipefail /Users/psx/dev/act-test/workflow/2] user=
[Node.js Package/build] Exec command '[bash --noprofile --norc -e -o pipefail /Users/psx/dev/act-test/workflow/2]'
[Node.js Package/build]   | XXXXX-XXXXX-XXXXX-XXXXX
[Node.js Package/build]   | npm ERR! code E401
[Node.js Package/build]   | npm ERR! 401 Unauthorized - GET https://registry.npmjs.org/-/whoami
[Node.js Package/build]   | 
[Node.js Package/build]   | npm ERR! A complete log of this run can be found in:
[Node.js Package/build]   | npm ERR!     /root/.npm/_logs/2021-08-15T19_59_52_179Z-debug.log
[Node.js Package/build]   ❌  Failure - echo ${NODE_AUTH_TOKEN}
npm who

@psxcode psxcode added the kind/bug Something isn't working label Aug 15, 2021
@catthehacker catthehacker self-assigned this Aug 16, 2021
@github-actions
Copy link
Contributor

Issue is stale and will be closed in 14 days unless there is new activity

@github-actions github-actions bot added the stale label Sep 16, 2021
@catthehacker catthehacker added stale-exempt Exempt from stale and removed stale labels Sep 16, 2021
catthehacker pushed a commit to catthehacker/act-fork that referenced this issue Sep 27, 2021
step env from workflow should be last one to be written
fixes nektos#777
@mergify mergify bot closed this as completed in #832 Sep 28, 2021
mergify bot pushed a commit that referenced this issue Sep 28, 2021
* fix: rewrite StepContext env

step env from workflow should be last one to be written
fixes #777

* test: verify env correctness

* fix: move test into existing workflow
@catthehacker catthehacker added meta/resolved Issue has been fixed or valid solution has been provided (not workaround) and removed stale-exempt Exempt from stale labels Sep 28, 2021
KnisterPeter pushed a commit to xing/act that referenced this issue Oct 14, 2021
* fix: rewrite StepContext env

step env from workflow should be last one to be written
fixes nektos#777

* test: verify env correctness

* fix: move test into existing workflow
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Something isn't working meta/resolved Issue has been fixed or valid solution has been provided (not workaround)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants