From 508c36acee63fd53fba9a2bf65b9edc994159be1 Mon Sep 17 00:00:00 2001 From: GeopJr Date: Fri, 24 Mar 2023 21:14:26 +0200 Subject: [PATCH] chore(ci): upkeeping (#1137) * feat(ci)[nightly]: update tag instead of deleting * fix(ci)[pr-comment]: work on forks --- .github/workflows/nightly.yml | 9 +++------ .github/workflows/pr-comment.yml | 23 ++++++++++++----------- 2 files changed, 15 insertions(+), 17 deletions(-) diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml index e6d671cd..f7722d2e 100644 --- a/.github/workflows/nightly.yml +++ b/.github/workflows/nightly.yml @@ -77,13 +77,10 @@ jobs: echo "build_sha=$(cat sha256.checksum)" >> $GITHUB_OUTPUT cat sha256.checksum - - name: Remove previous Nightly - uses: dev-drprasad/delete-tag-and-release@v0.2.1 + - name: Run latest-tag + uses: EndBug/latest-tag@84c87607fcb948bcef069c9a27445e653113979f with: - delete_release: true - tag_name: nightly - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + ref: nightly - name: Nightly Release uses: softprops/action-gh-release@v1 diff --git a/.github/workflows/pr-comment.yml b/.github/workflows/pr-comment.yml index ed5a7ef0..b92a1676 100644 --- a/.github/workflows/pr-comment.yml +++ b/.github/workflows/pr-comment.yml @@ -8,10 +8,20 @@ jobs: if: github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'success' runs-on: ubuntu-latest steps: + - name: Get the PR number + run: | + # Query the issue search API to get the PR associated with it + PR_RAW=$(curl 'https://api.github.com/search/issues?q=${{ github.event.workflow_run.head_commit.id }}') + # Get the event number from the search results, which will be the PR number + # Filter by PRs only in this repository, as a PR with an identical head commit may be made in another repository (e.g. a fork) + # Assume the 0th index in the array of found PRs is the correct one (it seems to usually be the latest one) + PR_NUM=$(echo $PR_RAW | jq '.items | map(select(.repository_url=="https://api.github.com/repos/${{ github.repository }}")) | .[0].number') + echo "PR_NUM=${PR_NUM}" >> $GITHUB_ENV - uses: actions/github-script@v6 with: # This snippet is public-domain, taken from # https://github.com/oprypin/nightly.link/blob/master/.github/workflows/pr-comment.yml + # and modified to allow comments on external PRs (oprypin/nightly.link/pull/38 & #issuecomment-1200506721) script: | async function upsertComment(owner, repo, issue_number, purpose, body) { const {data: comments} = await github.rest.issues.listComments( @@ -36,12 +46,7 @@ jobs: } const {owner, repo} = context.repo; - const run_id = ${{github.event.workflow_run.id}}; - - const pull_requests = ${{ toJSON(github.event.workflow_run.pull_requests) }}; - if (!pull_requests.length) { - return core.error("This workflow doesn't match any pull requests!"); - } + const run_id = '${{github.event.workflow_run.id}}'; const artifacts = await github.paginate( github.rest.actions.listWorkflowRunArtifacts, {owner, repo, run_id}); @@ -54,8 +59,4 @@ jobs: } core.info("Review thread message body:", body); - - for (const pr of pull_requests) { - await upsertComment(owner, repo, pr.number, - "nightly-link", body); - } \ No newline at end of file + await upsertComment(owner, repo, ${{ env.PR_NUM }}, "nightly-link", body);