From de9ed172df1291b7f474de503afebcdfc39ba9e2 Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Thu, 23 Mar 2023 18:43:51 +0100 Subject: [PATCH 1/2] tools: fix Slack notification action --- .github/workflows/notify-on-push.yml | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/.github/workflows/notify-on-push.yml b/.github/workflows/notify-on-push.yml index dd415a4a380dae..0c937b63cc2ac5 100644 --- a/.github/workflows/notify-on-push.yml +++ b/.github/workflows/notify-on-push.yml @@ -32,16 +32,19 @@ jobs: if: github.repository == 'nodejs/node' runs-on: ubuntu-latest steps: + - uses: actions/checkout@v3 + with: + persist-credentials: false - name: Check commit message - run: npx -q core-validate-commit ${{ github.event.commits[0].id }} || echo "INVALID_COMMIT_MESSAGE=1" >> $GITHUB_ENV + run: npx -q core-validate-commit ${{ github.event.after }} || echo "INVALID_COMMIT_MESSAGE=1" >> $GITHUB_ENV - name: Retrieve PR number if possible if: ${{ env.INVALID_COMMIT_MESSAGE }} run: | - node <<<'EOF' + node <<'EOF' >> $GITHUB_ENV || true const invalidCommitMessageMatch = /\s\(\#\d+\)$/.exec(process.env.COMMIT_MESSAGE); - if (match == null) process.exit(1) - console.log(`PR_ID=${match[0]}`) - EOF >> $GITHUB_ENV || true + if (invalidCommitMessageMatch == null) process.exit(1) + console.log(`PR_ID=${invalidCommitMessageMatch[0]}`) + EOF env: COMMIT_MESSAGE: ${{ github.event.commits[0].message }} - name: Comment on the Pull Request From 2470ece4cb89adca8efa3d0f4c0942044937a374 Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Thu, 23 Mar 2023 19:15:45 +0100 Subject: [PATCH 2/2] fixup! tools: fix Slack notification action --- .github/workflows/notify-on-push.yml | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/.github/workflows/notify-on-push.yml b/.github/workflows/notify-on-push.yml index 0c937b63cc2ac5..36e62ee53c7334 100644 --- a/.github/workflows/notify-on-push.yml +++ b/.github/workflows/notify-on-push.yml @@ -31,6 +31,8 @@ jobs: name: Notify on Push on `main` that lacks metadata if: github.repository == 'nodejs/node' runs-on: ubuntu-latest + permissions: + pull-requests: write steps: - uses: actions/checkout@v3 with: @@ -38,21 +40,20 @@ jobs: - name: Check commit message run: npx -q core-validate-commit ${{ github.event.after }} || echo "INVALID_COMMIT_MESSAGE=1" >> $GITHUB_ENV - name: Retrieve PR number if possible - if: ${{ env.INVALID_COMMIT_MESSAGE }} + if: env.INVALID_COMMIT_MESSAGE run: | - node <<'EOF' >> $GITHUB_ENV || true - const invalidCommitMessageMatch = /\s\(\#\d+\)$/.exec(process.env.COMMIT_MESSAGE); + COMMIT_TITLE=$(git --no-pager log --oneline -1 --no-color) node <<'EOF' >> $GITHUB_ENV || true + const invalidCommitMessageMatch = /\s\(\#(\d+)\)$/.exec(process.env.COMMIT_TITLE); if (invalidCommitMessageMatch == null) process.exit(1) - console.log(`PR_ID=${invalidCommitMessageMatch[0]}`) + console.log(`PR_ID=${invalidCommitMessageMatch[1]}`) EOF - env: - COMMIT_MESSAGE: ${{ github.event.commits[0].message }} - name: Comment on the Pull Request if: ${{ env.PR_ID }} - run: gh pr comment ${{ env.PR_ID }} --repo "${{ github.repository }}" --body "$BODY" + run: | + gh pr comment ${{ env.PR_ID }} --repo "${{ github.repository }}" \ + --body "A commit referencing this Pull Request was pushed to `main` by @${{ github.actor }} without the expected commit metadata added to its message." env: - BODY: | - A commit referencing this Pull Request was pushed to `main` by @${{ github.actor }} without the expected commit metadata added to its message. + GH_TOKEN: ${{ github.token }} - name: Slack Notification if: ${{ env.INVALID_COMMIT_MESSAGE }} uses: rtCamp/action-slack-notify@12e36fc18b0689399306c2e0b3e0f2978b7f1ee7