github-actions

What asset_path to upload to release after build?


I've an action script that runs when I create a new release on github

Here is a snippet of the build steps:

jobs:
  linux:
    runs-on: ${{ matrix.platform.runner }}
    strategy:
      matrix:
        platform:
          - runner: ubuntu-22.04
            target: x86_64
          - runner: ubuntu-22.04
            target: aarch64
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-python@v5
        with:
          python-version: "3.10"
      - name: Build wheels
        uses: PyO3/maturin-action@v1
        with:
          target: ${{ matrix.platform.target }}
          args: --release --out dist
          sccache: ${{ !startsWith(github.ref, 'refs/tags/') }}
          manylinux: auto
      - name: Upload wheels
        uses: actions/upload-artifact@v4
        with:
          name: wheels-linux-${{ matrix.platform.target }}
          path: dist

After which I want to attach the wheel to the release. Here is what I have using linux as an example:

  release:
    name: Release
    runs-on: ubuntu-latest
    if: ${{ startsWith(github.ref, 'refs/tags/') || github.event_name == 'workflow_dispatch' }}
    needs: [linux, windows, macos]
      - name: upload linux artifact aarcg64
        uses: actions/upload-release-asset@v1
        env:
          GITHUB_TOKEN: ${{ github.token }}
        with:
          upload_url: ${{ github.event.release.upload_url }}
          asset_path: wheels-linux-aarch64.zip # FAILS HERE
          asset_name: wheels-linux-aarch64.zip
          asset_content_type: application/zip

I've tried dist/wheels-linux-aarch64.zip as well as bin/wheels-linux-aarch64.zip but get 'not found' for all.


Solution

  • Artifacts uploaded in one job (like linux) aren't automatically available in another (like release).

    To use them, you must download them with actions/download-artifact, zip them if needed, and then upload using actions/upload-release-asset with the correct file path.


    Without this download and zip step, the file you're trying to upload simply doesn't exist in the job's workspace, which is why you're getting a "not found" error.

    To fix your workflow, modify your release job so that it explicitly downloads the artifacts before uploading them, steps 1 and 2:

    release:
      name: Release
      runs-on: ubuntu-latest
      if: ${{ startsWith(github.ref, 'refs/tags/') || github.event_name == 'workflow_dispatch' }}
      needs: [linux, windows, macos]
      steps:
        - name: Download Linux aarch64 artifact
          uses: actions/download-artifact@v4
          with:
            name: wheels-linux-aarch64
            path: artifacts/linux/aarch64
    
        - name: Zip artifact
          run: |
            cd artifacts/linux/aarch64
            zip -r wheels-linux-aarch64.zip .
    
        - name: Upload Linux aarch64 artifact to GitHub Release
          uses: actions/upload-release-asset@v1
          env:
            GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          with:
            upload_url: ${{ github.event.release.upload_url }}
            asset_path: artifacts/linux/aarch64/wheels-linux-aarch64.zip
            asset_name: wheels-linux-aarch64.zip
            asset_content_type: application/zip