2

I'm trying to run a Github Action locally with nektos/act. I have Docker setup and everything works fine until I reference a Github variable (not a secret). Then I get the following error:

 Unable to interpolate expression 'format('{0}', vars.APP_ID)': Unavailable context: vars

How do I setup the vars context using a .env file?

on:
  pull_request:
  push:
jobs:
  build-test:
    name: Build & Test
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3

      - name: Install Dependencies   
        run: npm ci
        working-directory: test/unit

      - name: Run Unit Tests
        run: npm run test:ci
        working-directory: test/unit

      - name: Install Integration Test Dependencies
        run: npm ci
        working-directory: test/integration

      - name: Run Integration Tests
        env:
          APP_ID: ${{ vars.APP_ID }}

      #...omitted
user2966445
  • 1,267
  • 16
  • 39
  • could be related? https://github.com/nektos/act/issues/1558 – Matteo Mar 06 '23 at 07:57
  • Wouldn't it be an option to use an `env file` instead of `vars`? As specified [here](https://github.com/nektos/act#configuration)? And then just call it by using `${{ env.APP_ID }}` ? – GuiFalourd Mar 06 '23 at 11:48
  • @Matteo Yes, definitely related. – user2966445 Mar 06 '23 at 15:24
  • @GuiFalourd It might be an option, but how would I use both an env file and secrets together? – user2966445 Mar 06 '23 at 15:25
  • 1
    You can configure the secret file separately as well as stated in the [act readme file](https://github.com/nektos/act#secrets). – GuiFalourd Mar 06 '23 at 17:55
  • 1
    @Matteo @GuiFalourd I have this working now based on your comments. So #1, it appears `vars` context isn't supported with act, and #2 the secrets file can be used locally. So one of you can answer and I will accept. – user2966445 Mar 08 '23 at 00:17

1 Answers1

0

It's currently not an option. The listed issue on github addresses it - i don't see how act is ready for prime-time without this!

The workaround is to change your workflow file to use env. instead of vars., and change it back when you are ready to push it up to github. This is not a good workaround! But it's the best anyone seems to be able to offer.

Max Cascone
  • 648
  • 9
  • 25
  • Or just not use the vars context at all, which is what I ended up doing. – user2966445 May 11 '23 at 02:36
  • I get it, but I only have Secrets and Variables available in my repo; Environment isn't an option AFAIK unless I'm not understanding something (which is always highly likely). – Max Cascone May 11 '23 at 02:40
  • You just have to write directly to ‘$GITHUB_ENV’ as described here: https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#setting-an-environment-variable – user2966445 May 11 '23 at 06:06