|
| 1 | +on: |
| 2 | + push: |
| 3 | + branches: |
| 4 | + - main |
| 5 | + |
| 6 | +name: Notify on Push |
| 7 | +permissions: |
| 8 | + contents: read |
| 9 | + |
| 10 | +jobs: |
| 11 | + notifyOnForcePush: |
| 12 | + name: Notify on Force Push on `main` |
| 13 | + if: github.repository == 'nodejs/node' && github.event.forced |
| 14 | + runs-on: ubuntu-latest |
| 15 | + steps: |
| 16 | + - name: Slack Notification |
| 17 | + uses: rtCamp/action-slack-notify@12e36fc18b0689399306c2e0b3e0f2978b7f1ee7 |
| 18 | + env: |
| 19 | + SLACK_COLOR: '#DE512A' |
| 20 | + SLACK_ICON: https://github.com/nodejs.png?size=48 |
| 21 | + SLACK_TITLE: ${{ github.actor }} force-pushed to ${{ github.ref }} |
| 22 | + SLACK_MESSAGE: | |
| 23 | + A commit was force-pushed to <https://github.com/${{ github.repository }}/tree/${{ github.repository.default_branch }}|${{ github.repository }}@${{ github.repository.default_branch }}> by <https://github.com/${{ github.actor }}|${{ github.actor }}> |
| 24 | +
|
| 25 | + Before: <https://github.com/${{ github.repository }}/commit/${{ github.event.before }}|${{ github.event.before }}> |
| 26 | + After: <https://github.com/${{ github.repository }}/commit/${{ github.event.after }}|${{ github.event.after }}> |
| 27 | + SLACK_USERNAME: nodejs-bot |
| 28 | + SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }} |
| 29 | + |
| 30 | + notifyOnMissingMetadata: |
| 31 | + name: Notify on Push on `main` that lacks metadata |
| 32 | + if: github.repository == 'nodejs/node' |
| 33 | + runs-on: ubuntu-latest |
| 34 | + steps: |
| 35 | + - name: Check commit message |
| 36 | + run: npx -q core-validate-commit ${{ github.event.commits[0].id }} || echo "INVALID_COMMIT_MESSAGE=1" >> $GITHUB_ENV |
| 37 | + - name: Retrieve PR number if possible |
| 38 | + if: ${{ env.INVALID_COMMIT_MESSAGE }} |
| 39 | + run: | |
| 40 | + node <<<'EOF' |
| 41 | + const invalidCommitMessageMatch = /\s\(\#\d+\)$/.exec(process.env.COMMIT_MESSAGE); |
| 42 | + if (match == null) process.exit(1) |
| 43 | + console.log(`PR_ID=${match[0]}`) |
| 44 | + EOF >> $GITHUB_ENV || true |
| 45 | + env: |
| 46 | + COMMIT_MESSAGE: ${{ github.event.commits[0].message }} |
| 47 | + - name: Comment on the Pull Request |
| 48 | + if: ${{ env.PR_ID }} |
| 49 | + run: gh pr comment ${{ env.PR_ID }} --repo "${{ github.repository }}" --body "$BODY" |
| 50 | + env: |
| 51 | + BODY: | |
| 52 | + A commit referencing this Pull Request was pushed to `main` by @${{ github.actor }} without the expected commit metadata added to its message. |
| 53 | + - name: Slack Notification |
| 54 | + if: ${{ env.INVALID_COMMIT_MESSAGE }} |
| 55 | + uses: rtCamp/action-slack-notify@12e36fc18b0689399306c2e0b3e0f2978b7f1ee7 |
| 56 | + env: |
| 57 | + SLACK_COLOR: '#DE512A' |
| 58 | + SLACK_ICON: https://github.com/nodejs.png?size=48 |
| 59 | + SLACK_TITLE: Invalid commit was pushed to ${{ github.repository.default_branch }} |
| 60 | + SLACK_MESSAGE: | |
| 61 | + A commit lacking the expected metadata was pushed to <https://github.com/${{ github.repository }}/tree/${{ github.repository.default_branch }}|${{ github.repository }}@${{ github.repository.default_branch }}> by <https://github.com/${{ github.actor }}|${{ github.actor }}>. |
| 62 | +
|
| 63 | + Before: <https://github.com/${{ github.repository }}/commit/${{ github.event.before }}|${{ github.event.before }}> |
| 64 | + After: <https://github.com/${{ github.repository }}/commit/${{ github.event.after }}|${{ github.event.after }}> |
| 65 | + SLACK_USERNAME: nodejs-bot |
| 66 | + SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }} |
0 commit comments