github-actionsgithub-pagesgithub-pages-deploy-action

deploy-pages@v4 Cannot Find Uploaded Artifact (No artifacts named "github-pages" were found)


I am trying to deploy my project to GitHub Pages using GitHub Actions, but I am running into an issue where deploy-pages@v4 cannot find the uploaded artifact.

Run actions/deploy-pages@v4
Fetching artifact metadata for "github-pages" in this workflow run
Found 0 artifact(s)
Error: Fetching artifact metadata failed. Is githubstatus.com reporting issues with API requests, Pages, or Actions? Please re-run the deployment at a later time.
Error: Error: No artifacts named "github-pages" were found for this workflow run. Ensure artifacts are uploaded with actions/upload-artifact@v4 or later.
    at getArtifactMetadata (/home/runner/work/_actions/actions/deploy-pages/v4/src/internal/api-client.js:85:1)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at Deployment.create (/home/runner/work/_actions/actions/deploy-pages/v4/src/internal/deployment.js:66:1)
    at main (/home/runner/work/_actions/actions/deploy-pages/v4/src/index.js:30:1)
Error: Error: No artifacts named "github-pages" were found for this workflow run. Ensure artifacts are uploaded with actions/upload-artifact@v4 or later.

Setup I have two workflows:

CI - Build & Test (builds the project and uploads an artifact)

Deploy to GitHub Pages (runs when CI completes and deploys to GitHub Pages)

CI - Build & Test

name: CI - Build & Test

on:
  push:
    branches: ["master"]

  workflow_dispatch:

jobs:
  build:
    runs-on: windows-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v4
      - name: Cache
        id: cache-web
        uses: actions/cache@v4
        with:
          path: |
            web/node_modules
          key: ${{ runner.os }}-build-${{ hashFiles('**/web/package-lock.json') }}
          restore-keys: |
            ${{ runner.os }}-build-
            ${{ runner.os }}-

      - name: Setup Pages
        uses: actions/configure-pages@v3
   
      - name: wasm-pack
        uses: jetli/wasm-pack-action@v0.4.0
        with:
          version: 'latest'
        
      - run: wasm-pack build --target web --out-dir ../web/snake-game
        working-directory: ./game
      - run: npm install
        working-directory: ./web
      - run: npm run build
        working-directory: ./web

      - uses: dtolnay/rust-toolchain@1.84.0
      - uses: Swatinem/rust-cache@v2
        with:
          cache-targets: false
      - name: Tests
        continue-on-error: true
        run: cargo test --verbose
        working-directory: ./game

      - name: Install cargo-llvm-cov
        uses: taiki-e/install-action@cargo-llvm-cov
        
      - name: code coverage
        run: cargo llvm-cov --all-features --workspace --lcov --output-path lcov.info
        working-directory: ./game

      - name: push to codecov
        uses: codecov/codecov-action@v5
        with:
          token: ${{ secrets.CODECOV_TOKEN }}
          files: ./game/lcov.info

      - name: Upload artifact
        uses: actions/upload-pages-artifact@v3
        with:
          path: "./web/dist"

Deploy to GitHub Pages

name: Deploy to GitHub Pages

on:
  workflow_run:
    workflows: ["CI - Build & Test"]
    types:
      - completed

jobs:
  deploy:
    runs-on: ubuntu-latest
    permissions:
      pages: write
      id-token: write
    environment:
      name: github-pages
      url: ${{ steps.deployment.outputs.page_url }}

    steps:
      - name: Checkout Code
        uses: actions/checkout@v4

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

Logs of the CI workflow

Run actions/upload-pages-artifact@v3
Run echo ::group::Archive artifact
Archive artifact
Run actions/upload-artifact@v4
With the provided path, there will be 1 file uploaded
Artifact name is valid!
Root directory input is valid!
Beginning upload of artifact content to blob storage
Uploaded bytes 307106
Finished uploading artifact content to blob storage!
SHA256 hash of uploaded artifact zip is bd7bd52796095adff4267943751a0a5b34d30033352cd4becf9f277f32e4e8e7
Finalizing artifact upload
Artifact github-pages.zip successfully finalized. Artifact ID 2638231538
Artifact github-pages has been successfully uploaded! Final size is 307106 bytes. Artifact ID is 2638231538
Artifact download URL: 

Any help would be greatly appreciated!


Solution

  • The relevant bit from the download-artifact docs:

    By default, the permissions are scoped so they can only download Artifacts within the current workflow run.

    In other words, you have to make the deploy a job in the same workflow:

    name: CI - Build & Test
    
    on:
      push:
        branches: ["master"]
    
      workflow_dispatch:
    
    jobs:
      build:
        # Build job, omitted
      deploy:
        runs-on: ubuntu-latest
        needs: build
        permissions:
          pages: write
          id-token: write
        environment:
          name: github-pages
          url: ${{ steps.deployment.outputs.page_url }}
        steps:
          - name: Deploy to GitHub Pages
            id: deployment
            uses: actions/deploy-pages@v4
    

    This is pretty much the recommended usage for deploy-pages.

    Notice that the checkout step is redundant in the deploy job.