From 6598da434ea97d930482032ff4ab8732c79d6891 Mon Sep 17 00:00:00 2001 From: David Chavez Date: Thu, 1 Aug 2024 13:02:35 +0200 Subject: [PATCH] chore(ci): link and update build artifacts for PRs (#453) --- .github/workflows/update-pr-artifacts.yml | 57 +++++++++++++++++++ ...ate_external.yml => validate-external.yml} | 0 ...ate_internal.yml => validate-internal.yml} | 0 3 files changed, 57 insertions(+) create mode 100644 .github/workflows/update-pr-artifacts.yml rename .github/workflows/{validate_external.yml => validate-external.yml} (100%) rename .github/workflows/{validate_internal.yml => validate-internal.yml} (100%) diff --git a/.github/workflows/update-pr-artifacts.yml b/.github/workflows/update-pr-artifacts.yml new file mode 100644 index 0000000..2a51c36 --- /dev/null +++ b/.github/workflows/update-pr-artifacts.yml @@ -0,0 +1,57 @@ +name: update-pr-artifacts +on: + workflow_run: + workflows: [validate] + types: + - completed +jobs: + update-pr-artifacts: + runs-on: ubuntu-latest + if: github.event.workflow_run.event == 'pull_request' + name: Update PR Artifacts + steps: + - name: Get PR Number + id: pr-number + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + # Get list of PR's associated to the commit that triggered the workflow run + prs=$(gh api \ + -H "Accept: application/vnd.github+json" \ + /repos/${{ github.event.pull_request.head.repo.full_name }}/commits/${{ github.event.workflow_run.head_sha }}/pulls) + + # Find the PR against the current repo + pr_number=$(echo "$prs" | jq -r '.[] | select(.base.repo.full_name == "${{ github.repository }}") | .number' | head -n1) + + if [ -z "$pr_number" ]; then + echo "No pull request found for this workflow run" + exit 1 + else + echo "pr_number=$pr_number" >> $GITHUB_OUTPUT + echo "PR number: $pr_number" + fi + - name: Create Artifacts Content + id: artifacts-content + uses: actions/github-script@v7 + with: + result-encoding: string + script: | + const artifacts = await github.rest.actions.listWorkflowRunArtifacts({ + owner: context.repo.owner, + repo: context.repo.repo, + run_id: context.payload.workflow_run.id, + }); + + const nightlyLinks = artifacts.data.artifacts.reduce((acc, item) => { + acc += `- [${item.name}.zip](https://nightly.link/${context.repo.owner}/${context.repo.repo}/actions/artifacts/${item.id}.zip)\n`; + return acc; + }, '### Build Artifacts\n'); + + return nightlyLinks; + - name: Update PR Description + uses: garrettjoecox/pr-section@3.1.0 + with: + section-name: 'artifacts' + repo-token: '${{ secrets.GITHUB_TOKEN }}' + pr-number: ${{ steps.pr-number.outputs.pr_number }} + section-value: '${{ steps.artifacts-content.outputs.result }}' diff --git a/.github/workflows/validate_external.yml b/.github/workflows/validate-external.yml similarity index 100% rename from .github/workflows/validate_external.yml rename to .github/workflows/validate-external.yml diff --git a/.github/workflows/validate_internal.yml b/.github/workflows/validate-internal.yml similarity index 100% rename from .github/workflows/validate_internal.yml rename to .github/workflows/validate-internal.yml