GitHub Actions - Unable to get ACTIONS_ID_TOKEN_REQUEST_URL env variable
Asked Answered
B

1

18

Currently, there are two workflows in my repository for 'publishing GitHub Pages'.

One is 'Build GitHub Pages' which is made by me, 'pages-build-deployment' is registered by GitHub for GitHub Page publishing.

img

I don't like this. I want these two workflow are merged as one.

There are two reasons.

First, 'pages-build-deployment' runs twice. First one gets cancelled and second one runs normally. That's because I modify files of 'gh-pages' branch for beautifying files. That triggers 'pages-build-deployment' run twice. I don't want that. This makes workflow logs have three entries for one commit. Yes, that's personal preference.

Second, I want to see full status of publishing GitHub Pages. Even if 'Build GitHub Pages' action succeeded, I have to wait 'pages-build-deployment' to finish its job to get actual page running.

So, I wrote workflow file like this.

name: Build GitHub Pages
on:
  push:
    branches:
      - main
jobs:
  build:
    name: Build GitHub Pages
    runs-on: ubuntu-latest
    steps:
      - name: Checkout latest commit
        uses: actions/checkout@v3
      - name: Prepare Python
        uses: actions/setup-python@v3
        with:
          python-version: 3.x
      - name: Install requirements (mkdocs-material)
        run: |
          echo "Installing mkdocs-material"
          pip install mkdocs-material
          echo "Installing js-beautify"
          npm install -g --location=global js-beautify --no-fund
      - name: Build website
        run: mkdocs gh-deploy --force
  modify:
    name: Modify Generated Files
    runs-on: ubuntu-latest
    needs: build
    steps:
      - name: Checkout latest commit of gh-pages
        uses: actions/checkout@v3
        with:
          ref: gh-pages
      - name: Prepare Node.js
        uses: actions/setup-node@v3
        with:
          node-version: 16
      - name: Install requirements (js-beautify)
        run: |
          echo "Installing js-beautify"
          npm install -g --location=global js-beautify --no-fund
      - name: Beautify files
        run: | 
          echo "Beautify files"
          git checkout gh-pages
          find . -type f -name '*.js' ! -name '*.min.js' -exec js-beautify -r '{}' --config jsbeautify.json --preserve-newlines false \;
          find . -type f -name '*.css' ! -name '*.min.css' -exec css-beautify -r '{}' --config jsbeautify.json --preserve-newlines false \;
          find . -type f -name '*.html' -exec html-beautify -r '{}' --config jsbeautify.json --preserve-newlines false \;
      - name: Manually set CNAME
        run: |
          echo "mydomain.com" > CNAME
          git add CNAME
      - name: Save changes to gh-pages branch
        uses: stefanzweifel/git-auto-commit-action@v4
        with:
          commit_message: Apply beautified files
          branch: gh-pages
  publish:
    name: Publish GitHub Pages
    runs-on: ubuntu-latest
    needs: modify
    steps:
      - name: Checkout latest commit of gh-pages
        uses: actions/checkout@v3
        with:
          ref: gh-pages
          submodules: recursive
      - name: Upload page artifact
        uses: actions/upload-pages-artifact@v0
        with:
          path: .
      - name: Upload artifact
        uses: actions/upload-artifact@main
        with:
          name: github-pages
          path: /home/runner/work/_temp/artifact.tar
          retention-days: 1
  report:
    name: Report telemetry
    runs-on: ubuntu-latest
    needs: publish
    steps:
      - name: Report build status
        uses: actions/deploy-pages@v1
        with:
          emit_telemetry: true
  deploy:
    name: Deploy GitHub Pages
    runs-on: ubuntu-latest
    needs: publish
    steps:
      - name: Deploy GitHub Pages
        uses: actions/deploy-pages@v1
        with:
          emit_telemetry: false

(Ignore some duplicates)

I tried to mimic 'pages-build-deployment' as much as I could, but deploy part fails. I see this error message from action log but couldn't find out how to solve this error.

Error: Error: Error message: Unable to get ACTIONS_ID_TOKEN_REQUEST_URL env variable

I couldn't find that ACTIONS_ID_TOKEN_REQUEST_URL was defined in 'pages-build-deployment' so I don't get what is wrong with my settings.


TL;DR

How to solve this error message in GitHub workflow?

Error: Error: Error message: Unable to get ACTIONS_ID_TOKEN_REQUEST_URL env variable

I don't see any usage in ACTIONS_ID_TOKEN_REQUEST_URL in 'original' workflow.

Budwig answered 5/6, 2022 at 5:26 Comment(4)
See github.com/glassechidna/ghaoidc/issues/1, I had the same issue and this helped me make some progressAsyndeton
@Asyndeton the action still fails with this 403 error: {"message":"Resource not accessible by integration","documentation_url":"https://docs.github.com/rest/reference/repos#create-a-github-pages-deployment"} but it is still some improvement. But I don't understand why it fails. these actions are made by github itself and API endpoint is causing this error?Budwig
Let's take a look at my own workflow...Seems I'm using github.com/JamesIves/github-pages-deploy-action/tree/v4.3.3 to push the actual website to the gh-pages branch, and then I'm using the built-in settings for GitHub Pages to deploy that branch to my domain.Asyndeton
I still get pages-build-deployment action running even if I disable that action. This is very annoying problem... It seems that action is triggered when new commit on gh-pages but I can't override or remove it because there isn't any workflow file exists...Budwig
W
28

Your need set the permisions

# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
  contents: read
  pages: write
  id-token: write
Wristwatch answered 22/10, 2022 at 21:35 Comment(1)
I just want to note that this is still required even if you have your token's default permissions set to "permissive" (i.e. Repo->Actions->Workflow permissions->Read and write permissions), as the 'id-token' scope specifically is still set to "none" in that case: docs.github.com/en/actions/security-guides/…Bedroom

© 2022 - 2024 — McMap. All rights reserved.