Search code examples
github-actionsgithub-pages

Unable to get ACTIONS_ID_TOKEN_REQUEST_URL env variable


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.


Solution

  • Your need set the permisions in the action yaml file:

    # Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
    permissions:
      contents: read
      pages: write
      id-token: write