From 8e48028be38d1effc9dd7370420cc7370e249148 Mon Sep 17 00:00:00 2001 From: Vladimir Jimenez Date: Sun, 17 Aug 2025 20:59:51 -0700 Subject: [PATCH 1/2] fix(slack): don't send Slack msgs multiple times One workflow gets triggered per label that was added. For example, in "content" and "resources". Our if statement checked with `contains` against the `issue.labels.*.name` array, which included both labels already since these labels were created alongside the issue; opposed to being added individually. Instead, check that the label triggered this workflow is what we're looking for. --- .github/workflows/resource-slack.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/resource-slack.yml b/.github/workflows/resource-slack.yml index 99555c15..dcacdae8 100644 --- a/.github/workflows/resource-slack.yml +++ b/.github/workflows/resource-slack.yml @@ -7,7 +7,7 @@ on: jobs: notify-slack: runs-on: ubuntu-latest - if: contains(github.event.issue.labels.*.name, 'press') || contains(github.event.issue.labels.*.name, 'resources') + if: github.event.label.name == 'press' || github.event.label.name == 'resources' steps: - name: Slack notification uses: rtCamp/action-slack-notify@v2 From 7c1ff97c8257950c76080a6a863b18142e3f3b6b Mon Sep 17 00:00:00 2001 From: Vladimir Jimenez Date: Mon, 18 Aug 2025 05:33:27 +0000 Subject: [PATCH 2/2] feat(slack): notify on preview failures --- .github/workflows/notify-failed-previews.yml | 39 ++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 .github/workflows/notify-failed-previews.yml diff --git a/.github/workflows/notify-failed-previews.yml b/.github/workflows/notify-failed-previews.yml new file mode 100644 index 00000000..ade764a3 --- /dev/null +++ b/.github/workflows/notify-failed-previews.yml @@ -0,0 +1,39 @@ +name: On Netlify Check Failure (PR only) + +on: + status: + +jobs: + notify-slack-on-failure: + if: (github.event.state == 'failure' || github.event.state == 'error') && endsWith(github.event.context, '/deploy-preview') + runs-on: ubuntu-latest + steps: + - name: Install GitHub CLI + uses: cli/cli@v2 + + - name: Check if commit is part of a PR + id: prcheck + env: + GH_TOKEN: ${{ github.token }} + run: | + prs=$(gh api \ + -H "Accept: application/vnd.github+json" \ + repos/${{ github.repository }}/commits/${{ github.event.sha }}/pulls) + + if [ "$(echo "$prs" | jq 'length')" -gt 0 ]; then + echo "isPR=true" >> $GITHUB_OUTPUT + else + echo "isPR=false" >> $GITHUB_OUTPUT + fi + + - name: Slack notification + uses: rtCamp/action-slack-notify@v2 + if: steps.prcheck.outputs.isPR == 'true' + env: + SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }} + SLACK_USERNAME: cal-itp-bot + SLACK_MSG_AUTHOR: cal-itp-bot + SLACK_ICON: https://github.com/cal-itp-bot.png?size=48 + SLACK_MESSAGE: "" + SLACK_FOOTER: "" + MSG_MINIMAL: true