From 336d1291144c29b9d3229bf4665e17044ae2af59 Mon Sep 17 00:00:00 2001 From: Garrett Cox Date: Mon, 14 Nov 2022 08:50:26 -0600 Subject: [PATCH] Add workflow to add artifact links to PR descriptions (#1961) --- .github/workflows/pr-artifacts.yml | 37 ++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 .github/workflows/pr-artifacts.yml diff --git a/.github/workflows/pr-artifacts.yml b/.github/workflows/pr-artifacts.yml new file mode 100644 index 000000000..599aa1bbb --- /dev/null +++ b/.github/workflows/pr-artifacts.yml @@ -0,0 +1,37 @@ +name: pr-artifacts + +on: + workflow_run: + workflows: [generate-builds] + types: + - completed + +jobs: + pr-artifacts: + runs-on: ubuntu-latest + if: ${{ github.event.workflow_run.event == 'pull_request' }} + steps: + - id: 'get-info' + uses: actions/github-script@v6 + with: + result-encoding: string + script: | + let allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({ + owner: context.repo.owner, + repo: context.repo.repo, + run_id: context.payload.workflow_run.id, + }); + + return allArtifacts.data.artifacts.reduce((acc, item) => { + if (item.name === "assets") return acc; + acc += ` + - [${item.name}](${context.payload.repository.html_url}/suites/${context.payload.workflow_run.check_suite_id}/artifacts/${item.id})`; + return acc; + }, '### Build Artifacts'); + - id: 'add-to-pr' + uses: garrettjoecox/pr-section@3.1.0 + with: + repo-token: '${{ secrets.GITHUB_TOKEN }}' + pr-number: ${{ github.event.workflow_run.pull_requests[0].number }} + section-name: 'artifacts' + section-value: '${{ steps.get-info.outputs.result }}'