Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to download artifact/release-asset in another workflow

Is it possible for Github actions to upload a build artifact for commits on a release branch, and then for another workflow to download & use that artifact?

name: Deploy release to UAT & archive artifact
on:
  release:
    types: [published]
jobs:
  package:
    name: package and archive
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: actions/setup-node@v1
        with:
          node-version: '12'
      - name: serverless package
        uses: serverless/github-action@master
        with:
          args: package --stage=prod
      - name: Upload Release Asset
        uses: actions/upload-release-asset@v1
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        with:
          upload_url: ${{ github.event.release.upload_url }}
          asset_path: .serverless
          asset_name: release-asset-${{ github.event.release.name }}.zip
          asset_content_type: application/zip
      - name: Upload Artifact
        uses: actions/upload-artifact@v2
        with:
          name: release-artifact-${{ github.event.release.name }}
          path: .serverless

...but how do you download the asset/artifact? I think up/download-artifact is intended only to be used only from the same workflow, and there doesn't seem to be an action for downloading a release asset.

name: Deploy to production
on:
  workflow_dispatch:
    inputs:
      release:
        description: Name of release to deploy
        required: true
        default: v1.0.0

jobs:
  deploy:
    name: deploy
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
    - uses: actions/setup-node@v1
      with:
        node-version: '12'
    - run: npm ci --only=prod
    - name: Download the release artifact
      uses: actions/download-artifact@v2
      with:
        name: release-${{ github.event.inputs.release }}
        path: .serverless
    - name: serverless deploy
      uses: serverless/github-action@master
      with:
        args: deploy --stage=prod --package=.serverless
      env:
        AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
        AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
like image 646
Nicholas Albion Avatar asked Jan 25 '23 15:01

Nicholas Albion


2 Answers

You can use download-workflow-artifact action.

like image 55
Marcin Kłopotek Avatar answered Mar 05 '23 16:03

Marcin Kłopotek


One of my team mates got this working:

      - id: download-release-asset
        name: Download release asset
        uses: dsaltares/fetch-gh-release-asset@master
        with:
          version: tags/${{ env.RELEASE }}
          file: myproject-${{ env.RELEASE }}.tar.gz
          target: release.tar.gz
          token: ${{ secrets.DEPLOY_TOKEN }}
like image 38
Nicholas Albion Avatar answered Mar 05 '23 15:03

Nicholas Albion