chore(ci): upkeeping (#1137)

* feat(ci)[nightly]: update tag instead of deleting

* fix(ci)[pr-comment]: work on forks
This commit is contained in:
GeopJr 2023-03-24 21:14:26 +02:00 committed by GitHub
parent aa4b0d7ed1
commit 508c36acee
2 changed files with 15 additions and 17 deletions

View File

@ -77,13 +77,10 @@ jobs:
echo "build_sha=$(cat sha256.checksum)" >> $GITHUB_OUTPUT echo "build_sha=$(cat sha256.checksum)" >> $GITHUB_OUTPUT
cat sha256.checksum cat sha256.checksum
- name: Remove previous Nightly - name: Run latest-tag
uses: dev-drprasad/delete-tag-and-release@v0.2.1 uses: EndBug/latest-tag@84c87607fcb948bcef069c9a27445e653113979f
with: with:
delete_release: true ref: nightly
tag_name: nightly
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Nightly Release - name: Nightly Release
uses: softprops/action-gh-release@v1 uses: softprops/action-gh-release@v1

View File

@ -8,10 +8,20 @@ jobs:
if: github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'success' if: github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'success'
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: 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 - uses: actions/github-script@v6
with: with:
# This snippet is public-domain, taken from # This snippet is public-domain, taken from
# https://github.com/oprypin/nightly.link/blob/master/.github/workflows/pr-comment.yml # 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: | script: |
async function upsertComment(owner, repo, issue_number, purpose, body) { async function upsertComment(owner, repo, issue_number, purpose, body) {
const {data: comments} = await github.rest.issues.listComments( const {data: comments} = await github.rest.issues.listComments(
@ -36,12 +46,7 @@ jobs:
} }
const {owner, repo} = context.repo; const {owner, repo} = context.repo;
const run_id = ${{github.event.workflow_run.id}}; 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 artifacts = await github.paginate( const artifacts = await github.paginate(
github.rest.actions.listWorkflowRunArtifacts, {owner, repo, run_id}); github.rest.actions.listWorkflowRunArtifacts, {owner, repo, run_id});
@ -54,8 +59,4 @@ jobs:
} }
core.info("Review thread message body:", body); core.info("Review thread message body:", body);
await upsertComment(owner, repo, ${{ env.PR_NUM }}, "nightly-link", body);
for (const pr of pull_requests) {
await upsertComment(owner, repo, pr.number,
"nightly-link", body);
}