[GH-ISSUE #517] ACT does not pick .env file #349

Closed
opened 2026-03-01 21:42:35 +03:00 by kerem · 5 comments
Owner

Originally created by @nenadfilipovic on GitHub (Feb 3, 2021).
Original GitHub issue: https://github.com/nektos/act/issues/517

As the title say, act just wont use my .env file, when I create .secrets file it works well.
This is how I run it: act pull_request -P ubuntu-latest=lucasalt/act_base:latest, env is just basic valid env file.
Maybe it is problem with my workflow file, this is how I get env vars for CI:

DATABASE_PORT: ${{ secrets.DATABASE_PORT }}
DATABASE_USER: ${{ secrets.DATABASE_USER }}
DATABASE_HOST: ${{ secrets.DATABASE_HOST }}
DATABASE_NAME: ${{ secrets.DATABASE_NAME }}
DATABASE_PASSWORD: ${{ secrets.DATABASE_PASSWORD }}

This is valid for github actions I dont know maybe ACT is picking my env file but I dont use vars correctly?
This is how I use env vars for docker-compose:

environment:
      POSTGRES_USER: ${DATABASE_USER}
      POSTGRES_PASSWORD: ${DATABASE_PASSWORD}
      POSTGRES_DB: ${DATABASE_NAME}
Originally created by @nenadfilipovic on GitHub (Feb 3, 2021). Original GitHub issue: https://github.com/nektos/act/issues/517 As the title say, act just wont use my .env file, when I create .secrets file it works well. This is how I run it: `act pull_request -P ubuntu-latest=lucasalt/act_base:latest`, env is just basic valid env file. Maybe it is problem with my workflow file, this is how I get env vars for CI: ``` DATABASE_PORT: ${{ secrets.DATABASE_PORT }} DATABASE_USER: ${{ secrets.DATABASE_USER }} DATABASE_HOST: ${{ secrets.DATABASE_HOST }} DATABASE_NAME: ${{ secrets.DATABASE_NAME }} DATABASE_PASSWORD: ${{ secrets.DATABASE_PASSWORD }} ``` This is valid for github actions I dont know maybe ACT is picking my env file but I dont use vars correctly? This is how I use env vars for docker-compose: ``` environment: POSTGRES_USER: ${DATABASE_USER} POSTGRES_PASSWORD: ${DATABASE_PASSWORD} POSTGRES_DB: ${DATABASE_NAME} ```
kerem closed this issue 2026-03-01 21:42:35 +03:00
Author
Owner

@catthehacker commented on GitHub (Feb 3, 2021):

Please provide workflow and .env file. .env file structure is described in https://github.com/nektos/act#configuration and has to be used via ${{ env.VAR }} context.

<!-- gh-comment-id:772756001 --> @catthehacker commented on GitHub (Feb 3, 2021): Please provide workflow and `.env` file. `.env` file structure is described in https://github.com/nektos/act#configuration and has to be used via `${{ env.VAR }}` context.
Author
Owner

@nenadfilipovic commented on GitHub (Feb 3, 2021):

DATABASE_PORT=5432
DATABASE_USER="admin"
DATABASE_HOST="postgres"
DATABASE_NAME="db"
DATABASE_PASSWORD="password"
# Create continuous integration environment.

name:  CI / CD

on:
  pull_request:
    branches:
      - main
    paths-ignore:
      - '**/*.md'
      - 'LICENSE'

jobs:
  job-1:
    name: Unit / Integration tests
    runs-on: ubuntu-latest

    # Load secrets from repository into continuous integration environment.
    env:
      DATABASE_PORT: ${{ secrets.DATABASE_PORT }}
      DATABASE_USER: ${{ secrets.DATABASE_USER }}
      DATABASE_HOST: ${{ secrets.DATABASE_HOST }}
      DATABASE_NAME: ${{ secrets.DATABASE_NAME }}
      DATABASE_PASSWORD: ${{ secrets.DATABASE_PASSWORD }}

    steps:
      - name: Checkout GitHub repository
        uses: actions/checkout@v2

      - name: Build continuous integration environment
        run: docker-compose -f docker-compose.yml -f docker-compose.ci.yml up -d
    
      - name: List running containers
        run: docker ps -a

      - name: List build logs
        run: docker-compose logs

      - name: Run migrations and prepare application for testing
        run: docker exec application npm run setup

      - name: Perform unit and integration tests
        run: docker exec application npm test

If I change in workflow from secrets.VAR to env.VAR it still doesn't work.

<!-- gh-comment-id:772807387 --> @nenadfilipovic commented on GitHub (Feb 3, 2021): ``` DATABASE_PORT=5432 DATABASE_USER="admin" DATABASE_HOST="postgres" DATABASE_NAME="db" DATABASE_PASSWORD="password" ``` ``` # Create continuous integration environment. name: CI / CD on: pull_request: branches: - main paths-ignore: - '**/*.md' - 'LICENSE' jobs: job-1: name: Unit / Integration tests runs-on: ubuntu-latest # Load secrets from repository into continuous integration environment. env: DATABASE_PORT: ${{ secrets.DATABASE_PORT }} DATABASE_USER: ${{ secrets.DATABASE_USER }} DATABASE_HOST: ${{ secrets.DATABASE_HOST }} DATABASE_NAME: ${{ secrets.DATABASE_NAME }} DATABASE_PASSWORD: ${{ secrets.DATABASE_PASSWORD }} steps: - name: Checkout GitHub repository uses: actions/checkout@v2 - name: Build continuous integration environment run: docker-compose -f docker-compose.yml -f docker-compose.ci.yml up -d - name: List running containers run: docker ps -a - name: List build logs run: docker-compose logs - name: Run migrations and prepare application for testing run: docker exec application npm run setup - name: Perform unit and integration tests run: docker exec application npm test ``` If I change in workflow from secrets.VAR to env.VAR it still doesn't work.
Author
Owner

@nenadfilipovic commented on GitHub (Feb 4, 2021):

@catthehacker

Ok I did some thinkering and this is result:

If I comment out this part:

env:
      DATABASE_PORT: ${{ secrets.DATABASE_PORT }}
      DATABASE_USER: ${{ secrets.DATABASE_USER }}
      DATABASE_HOST: ${{ secrets.DATABASE_HOST }}
      DATABASE_NAME: ${{ secrets.DATABASE_NAME }}
      DATABASE_PASSWORD: ${{ secrets.DATABASE_PASSWORD }}

Everything is working ok and I can echo env vars from steps. Problem is without that commented part how am I going to get CI vars for workflow, my .env is ignored in git... Maybe only solution is to use .secrets file.

<!-- gh-comment-id:773136190 --> @nenadfilipovic commented on GitHub (Feb 4, 2021): @catthehacker Ok I did some thinkering and this is result: If I comment out this part: ``` env: DATABASE_PORT: ${{ secrets.DATABASE_PORT }} DATABASE_USER: ${{ secrets.DATABASE_USER }} DATABASE_HOST: ${{ secrets.DATABASE_HOST }} DATABASE_NAME: ${{ secrets.DATABASE_NAME }} DATABASE_PASSWORD: ${{ secrets.DATABASE_PASSWORD }} ``` Everything is working ok and I can echo env vars from steps. Problem is without that commented part how am I going to get CI vars for workflow, my .env is ignored in git... Maybe only solution is to use .secrets file.
Author
Owner

@nenadfilipovic commented on GitHub (Feb 5, 2021):

Fixed with --secret-file .env in .actrc file. This way I can use .env in local and I can use secrets when running on real github runner.

<!-- gh-comment-id:774030552 --> @nenadfilipovic commented on GitHub (Feb 5, 2021): Fixed with `--secret-file .env` in .actrc file. This way I can use .env in local and I can use secrets when running on real github runner.
Author
Owner

@catthehacker commented on GitHub (Feb 5, 2021):

Well, the main issue is that currently env: keys are not interpolated in jobs: and steps: which I'm working on fixing that, only env: before jobs: will work

<!-- gh-comment-id:774069222 --> @catthehacker commented on GitHub (Feb 5, 2021): Well, the main issue is that currently `env:` keys are not interpolated in `jobs:` and `steps:` which I'm working on fixing that, only `env:` before `jobs:` will work
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/act#349
No description provided.