github-actionsdevopscicdcontinuous-deployment

::error::Unable to get the ACTIONS_RUNTIME_TOKEN env variable


I am trying to upload my frontend to be hosted and served on GitHub with GitHub actions. I am using the following workflow:

name: Deploy Frontend

on:
  push:
    branches: [main, staging, frontend]
    paths:
      - 'frontend/**'
      - '.github/workflows/deploy_frontend.yml'
  workflow_dispatch:

jobs:
  build-and-deploy:
    runs-on: ubuntu-latest
    permissions:
      contents: write
      pages: write       # Added for GitHub Pages deployment
      id-token: write    # Necessary for actions/deploy-pages
    environment:
      name: github-pages
      url: ${{ steps.deployment.outputs.page_url }}
    steps:
    - uses: actions/checkout@v4

    - name: Debug REACT_APP_API_URL
      shell: bash
      run: |
        echo -e "\e[32m@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\e[0m"
        echo -e "\e[32mREACT_APP_API_URL=${REACT_APP_API_URL}\e[0m"
        env
        echo $(env | grep ACTIONS_RUNTIME_TOKEN)
        # exit 1  # Commented out to allow the workflow to continue

    - name: Set up Node.js
      uses: actions/setup-node@v4
      with:
        node-version: '20'

    - name: Print Environment Variables and Secrets
      shell: bash
      env:
        REACT_APP_ENVIRONMENT: ${{ env.REACT_APP_ENVIRONMENT }}
      run: |
        echo -e "\e[32mREACT_APP_API_URL=${REACT_APP_API_URL}\e[0m"
        echo -e "\e[32mREACT_APP_ENVIRONMENT=${REACT_APP_ENVIRONMENT}\e[0m"
        env
        echo ACTIONS_RUNTIME_TOKEN=$(env | grep ACTIONS_RUNTIME_TOKEN)

    - name: Install dependencies
      shell: bash
      run: |
        cd frontend
        npm ci 2>&1 || (echo -e "\e[31mInstall dependencies step failed.\e[0m" && exit 1)

    - name: Build
      shell: bash
      run: |
        cd frontend
        mkdir -p build_logs
        TIMESTAMP=$(date +"%Y%m%d_%H%M%S")
        export REACT_APP_BUILD_TIME=$(TZ=America/Argentina/Buenos_Aires date +"%Y-%m-%d %H:%M:%S")
        echo -e "\e[32mBuilding with environment variables:\e[0m"
        env
        echo -e "\e[32m$(pwd)\e[0m"
        npm run build || (echo -e "\e[31mBuild step failed.\e[0m" && exit 1)

    - name: Setup Pages
      uses: actions/configure-pages@v4

    - name: Upload artifact
      uses: actions/upload-pages-artifact@v3
      with:
        path: './frontend/build'

    - name: Deploy to GitHub Pages
      id: deployment
      uses: actions/deploy-pages@v4

    - name: Build Succeeded
      if: success()
      run: echo -e "\e[32mBuild succeeded.\e[0m"

    - name: Build Failed
      if: failure()
      shell: bash
      run: |
        echo -e "\e[31mBuild failed.\e[0m"
        exit 1

Locally, with npm start or npm run build; npx serve -s build, this serves fine, so I am not showing the code itself.

I want to test locally and then use github actions. Running the workflow like so:

~/src/personal_website$ act -j build-and-deploy -W .github/workflows/deploy_frontend.yml --secret-file /home/noams/src/personal_website/frontend/.secrets_frontend --env-file /home/noams/src/personal_website/frontend/.env

The secrets are

REACT_APP_API_URL=ZZZ
#REACT_APP_API_URL=http://localhost:8080
GITHUB_TOKEN=YYY
#ACTIONS_RUNTIME_TOKEN=YYY
ACTIONS_RUNTIME_TOKEN=dummy [but also fails with the same token as GITHUB]
GITHUB_REPOSITORY=XXX

the .env file is as follows:

# frontend
# leave this here for the npm start to work
REACT_APP_API_URL=XXX
ENVIRONMENT="local"
REACT_APP_ENVIRONMENT="local"
# some backend variables below

Notice a duplicate REACT_APP_API_URL exists in .secrets, because npm start only knows how to read an .env and not .secrets and i figured it won't matter much. (Can be nice to clean it up too).

Github configuration is irrelevant AFAIK, because this is running locally with act.

The error:

The step

    - name: Upload artifact
      uses: actions/upload-pages-artifact@v3
      with:
        path: './frontend/build'

fails with

[Deploy Frontend/build-and-deploy]   💬  ::debug::File:/tmp/artifact.tar was found using the provided searchPath
| With the provided path, there will be 1 file uploaded
[Deploy Frontend/build-and-deploy]   💬  ::debug::Root artifact directory is /tmp
| Artifact name is valid!
| Root directory input is valid!
[Deploy Frontend/build-and-deploy]   ❗  ::error::Unable to get the ACTIONS_RUNTIME_TOKEN env variable
[Deploy Frontend/build-and-deploy]   ❌  Failure - Main Upload artifact
[Deploy Frontend/build-and-deploy] exitcode '1': failure
[Deploy Frontend/build-and-deploy]   ⚙  ::set-output:: artifact_id=
[Deploy Frontend/build-and-deploy]   ❌  Failure - Main Upload artifact
[Deploy Frontend/build-and-deploy] exitcode '1': failure
[Deploy Frontend/build-and-deploy] ⭐ Run Post Upload artifact
[Deploy Frontend/build-and-deploy]   🐳  docker cp src=/home/noams/.cache/act/actions-upload-pages-artifact@v3/ dst=/var/run/act/actions/actions-upload-pages-artifact@v3/
[Deploy Frontend/build-and-deploy]   ✅  Success - Post Upload artifact
[Deploy Frontend/build-and-deploy] 🏁  Job failed
Error: Job 'build-and-deploy' failed

So there are two errors here I can't pinpoint:

  1. ::error::Unable to get the ACTIONS_RUNTIME_TOKEN env variable, even though I tried feeding it in and not feeding it in
  2. ::debug::Root artifact directory is /tmp | Artifact name is valid! | Root directory input is valid!, I have no idea what they are talking about

Solution

  • As per the threads @Azeem linked:

    I have to run with the extra --artifact-server-path /tmp/artifacts and it solves it. Why? who knows. Maybe the github thread.

    Complete run command:

    act -j build-and-deploy \
    -W .github/workflows/deploy_frontend.yml \
    --secret-file /home/noams/src/personal_website/frontend/.secrets_frontend \
    --env-file /home/noams/src/personal_website/frontend/.env \
    --artifact-server-path /tmp/artifacts