'How to use dawidd6/action-download-artifact with pull_request trigger

This is a question for the github workflow action dawidd6/action-download-artifact. There is no discussion board in https://github.com/dawidd6/action-download-artifact, so asking this question in this forum.

This is how I wish to use this workflow in my GitHub repo:

  1. A pull request is created.
  2. This triggers an workflow – lets call it the “build workflow” - to build the entire repo and uploads the build artifacts.
  3. Then another workflow – lets call it the “test workflow” - should start, that should download the build artifact using action-download-artifact and run some other actions.

Now if I put the trigger for the “test workflow” as pull_request, then how can I make it wait for the corresponding “build workflow” to complete? Do I specify the run_id ?

For now I am using “workflow_run” as the trigger for the run WF. But then when a PR is created, it does not show the “test workflow” as one of the checks for the PR. Can you help me figure out the correct way of using the download-artifact action that would help for my purpose?



Solution 1:[1]

You could write two workflows where the first builds when the pull request is opened or edited, and the second executes the test when the pull request is closed and merged. The HEAD commit SHA could be used to identify the artifact name between the two workflows.

I'm going to reword your requirements slightly.

  1. Build everything and upload the artifacts when a pull request is opened or edited (e.g. new commits added).
  2. Download the artifact and test it when a pull request is closed and merged.

Here are two sample workflows that would accomplish that. You will need to create a token to share the artifacts between workflows (see secrets.GITHUB_TOKEN below).

Build.yml

name: Build
  on:
    pull_request:
jobs:
  Build:
    steps:
      - name: Environment Variables
        shell: bash
        run: |
          ARTIFACTS_SHA=$(git rev-parse HEAD)
          BUILD_ARTIFACTS=BuildArtifacts_${ARTIFACTS_SHA}
          echo "ARTIFACTS_DIR=$ARTIFACTS_DIR" >> $GITHUB_ENV
      - name: Build
        run: make
      - name: Capture Artifacts
        uses: actions/upload-artifact@2
        with:
          name: Artifacts_${{ env.ARTIFACTS_SHA }}
          path: path/to/artifact/

Test.yml

name: Test
  on:
    pull_request:
      types: [closed]
jobs:
  Test:
    steps:
      - name: Environment Variables
        shell: bash
        run: |
          ARTIFACTS_SHA=$(git rev-parse HEAD)
          BUILD_ARTIFACTS=BuildArtifacts_${ARTIFACTS_SHA}
          echo "ARTIFACTS_DIR=$ARTIFACTS_DIR" >> $GITHUB_ENV
      - name: Download Artifacts
        uses: dawidd6/action-download-artifact@v2
        with:
          github_token: ${{ secrets.GITHUB_TOKEN }}
          workflow: Build.yml
          name: ${{ env.BUILD_ARTIFACTS }}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Steve H