Merge pull request #816 from wwuoneway/form-redesign-backend-technology #57
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Guardrail Push Alerts | |
| on: | |
| push: | |
| branches: [main] | |
| jobs: | |
| slack-alert: | |
| runs-on: ubuntu-latest | |
| permissions: {} # Explicitly drops all token permissions | |
| if: github.actor != 'dependabot[bot]' | |
| steps: | |
| - name: Process and Format Slack Alert | |
| env: | |
| SLACK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} | |
| # Safely map variables as structured environment inputs | |
| COMMIT_MSG: ${{ github.event.head_commit.message }} | |
| COMMITTER: ${{ github.event.head_commit.committer.name }} | |
| REPO_NAME: ${{ github.repository }} | |
| ACTOR: ${{ github.actor }} | |
| run: | | |
| # If the committer isn't 'GitHub', an admin pushed directly via local CLI. | |
| if [ "$COMMITTER" != "GitHub" ]; then | |
| # Use jq to format a completely safe, escaped JSON object for Slack | |
| PAYLOAD=$(jq -n \ | |
| --arg msg "$COMMIT_MSG" \ | |
| --arg repo "$REPO_NAME" \ | |
| --arg actor "$ACTOR" \ | |
| '{"text": "⚠️ *Direct Push to Main Detected!*\n*Repo:* `\($repo)`\n*Actor:* `@\($actor)`\n*Commit:* `\($msg)`"}') | |
| curl -X POST -H 'Content-type: application/json' --data "$PAYLOAD" "$SLACK_URL" | |
| fi |