Running Github Action locally with vars context using nektos/act

1.7k views Asked by At

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
2

There are 2 answers

3
Max Cascone On

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.

0
xab On

It is now possible to use the var file by providing the --var-file argument see docs.
For example act -j build-test .github/workflows/workflow.yml --var-file .vars

# .vars
APP_ID=123456