代码之家  ›  专栏  ›  技术社区  ›  Józef Podlecki

deploy-pages@v4找不到上传的工件(找不到名为“github页面”的工件)

  •  0
  • Józef Podlecki  · 技术社区  · 2 月前

    我正试图使用GitHub Actions将我的项目部署到GitHub Pages,但我遇到了一个问题deploy-pages@v4找不到上传的工件。

    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.
    

    安装程序 我有两个工作流程:

    CI-构建和;测试(构建项目并上传工件)

    部署到GitHub Pages(在CI完成并部署到GitHub Page时运行)

    CI-构建和;测试

    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/[email protected]
            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/[email protected]
          - 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"
    

    部署到GitHub页面

    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
    
    

    CI工作流日志

    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: 
    

    任何帮助都将不胜感激!

    1 回复  |  直到 2 月前
        1
  •  1
  •   Benjamin W.    2 月前

    相关部分来自 download-artifact docs :

    默认情况下,权限是有范围的,因此他们只能下载当前工作流运行中的工件。

    换句话说,您必须在同一工作流中使部署成为一个作业:

    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
    

    这几乎就是 recommended usage 用于部署页面。

    请注意,签出步骤在部署作业中是多余的。