Skip to content

Commit f0cf1e1

Browse files
GHA-219 Replace Docker-based Slack notifier with Python script (#125)
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent b1b6baa commit f0cf1e1

File tree

11 files changed

+371
-361
lines changed

11 files changed

+371
-361
lines changed

.github/workflows/test-all.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ jobs:
4545
test-update-rule-metadata:
4646
uses: ./.github/workflows/test-update-rule-metadata.yml
4747

48+
test-notify-slack:
49+
uses: ./.github/workflows/test-notify-slack.yml
50+
4851
test-lock-branch:
4952
uses: ./.github/workflows/test-lock-branch.yml
5053

.github/workflows/test-lock-branch.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,4 @@ jobs:
3939
- name: Run unit tests
4040
run: |
4141
cd lock-branch
42-
python -m pytest test_utils.py test_lock_branch.py test_notify_slack.py -v --cov=utils --cov=lock_branch --cov=notify_slack --cov-report=term-missing
42+
python -m pytest test_utils.py test_lock_branch.py -v --cov=utils --cov=lock_branch --cov-report=term-missing
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
name: Test Notify Slack Action
2+
3+
on:
4+
workflow_call:
5+
pull_request:
6+
paths:
7+
- 'notify-slack/**'
8+
- '.github/workflows/test-notify-slack.yml'
9+
push:
10+
branches:
11+
- branch-*
12+
paths:
13+
- 'notify-slack/**'
14+
- '.github/workflows/test-notify-slack.yml'
15+
workflow_dispatch:
16+
17+
jobs:
18+
integration-test:
19+
name: Send Test Notification
20+
runs-on: ubuntu-latest
21+
continue-on-error: true
22+
permissions:
23+
id-token: write
24+
steps:
25+
- name: Checkout code
26+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
27+
- name: Send test Slack notification
28+
uses: ./notify-slack
29+
with:
30+
project-name: release-github-actions
31+
slack-channel: alerts-release-github-actions
32+
icon: ':test_tube:'
33+
color: good
34+
message: 'Test notification from `notify-slack` action on branch `${{ github.ref_name }}`'
35+
36+
unit-tests:
37+
name: Run Unit Tests
38+
runs-on: ubuntu-latest
39+
40+
steps:
41+
- name: Checkout code
42+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
43+
44+
- name: Set up Python
45+
uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0
46+
with:
47+
python-version: '3.10'
48+
cache: 'pip'
49+
cache-dependency-path: notify-slack/requirements.txt
50+
51+
- name: Install dependencies
52+
run: |
53+
cd notify-slack
54+
pip install -r requirements.txt
55+
pip install pytest pytest-cov
56+
57+
- name: Run unit tests
58+
run: |
59+
cd notify-slack
60+
python -m pytest test_notify_slack.py -v --cov=notify_slack --cov-report=term-missing

lock-branch/action.yml

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@ inputs:
1414
github-token:
1515
description: 'GitHub token with admin permissions (defaults to Vault)'
1616
required: false
17-
slack-token:
18-
description: 'Slack token for notifications (defaults to Vault)'
19-
required: false
2017

2118
outputs:
2219
branch:
@@ -34,12 +31,11 @@ runs:
3431
steps:
3532
- name: Get Secrets from Vault
3633
id: secrets
37-
if: ${{ !inputs.github-token || (!inputs.slack-token && inputs.slack-channel) }}
34+
if: ${{ !inputs.github-token }}
3835
uses: SonarSource/vault-action-wrapper@v3
3936
with:
4037
secrets: |
4138
development/github/token/{REPO_OWNER_NAME_DASH}-lock token | GITHUB_LOCK_TOKEN;
42-
development/kv/data/slack token | SLACK_TOKEN;
4339
4440
- name: Set up Python
4541
uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0
@@ -64,18 +60,41 @@ runs:
6460
--repository "${{ github.repository }}" \
6561
>> $GITHUB_OUTPUT
6662
67-
- name: Send Slack Notification
63+
- name: Build Slack Message
64+
id: slack-message
6865
if: ${{ inputs.slack-channel != '' }}
6966
shell: bash
7067
env:
71-
SLACK_TOKEN: ${{ inputs.slack-token || fromJSON(steps.secrets.outputs.vault).SLACK_TOKEN }}
72-
INPUT_CHANNEL: ${{ inputs.slack-channel }}
7368
INPUT_BRANCH: ${{ inputs.branch }}
7469
INPUT_FREEZE: ${{ inputs.freeze }}
70+
RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
7571
run: |
76-
python ${{ github.action_path }}/notify_slack.py \
77-
--channel "$INPUT_CHANNEL" \
78-
--branch "$INPUT_BRANCH" \
79-
--repository "${{ github.repository }}" \
80-
--freeze "$INPUT_FREEZE" \
81-
--run-url "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
72+
if [[ "$INPUT_FREEZE" == "true" ]]; then
73+
ICON=":ice_cube:"
74+
ACTION="frozen"
75+
COLOR="warning"
76+
else
77+
ICON=":sun_with_face:"
78+
ACTION="unfrozen"
79+
COLOR="good"
80+
fi
81+
echo "icon=$ICON" >> $GITHUB_OUTPUT
82+
echo "color=$COLOR" >> $GITHUB_OUTPUT
83+
DELIMITER="$(openssl rand -hex 8)"
84+
{
85+
echo "message<<${DELIMITER}"
86+
printf '%s Branch `%s` has been %s in `${{ github.repository }}`\n*Run:* <%s|View workflow run>' \
87+
"$ICON" "$INPUT_BRANCH" "$ACTION" "$RUN_URL"
88+
echo
89+
echo "${DELIMITER}"
90+
} >> $GITHUB_OUTPUT
91+
92+
- name: Send Slack Notification
93+
if: ${{ inputs.slack-channel != '' }}
94+
uses: SonarSource/release-github-actions/notify-slack@v1
95+
with:
96+
project-name: ${{ github.repository }}
97+
slack-channel: ${{ inputs.slack-channel }}
98+
icon: ${{ steps.slack-message.outputs.icon }}
99+
color: ${{ steps.slack-message.outputs.color }}
100+
message: ${{ steps.slack-message.outputs.message }}

lock-branch/notify_slack.py

Lines changed: 0 additions & 126 deletions
This file was deleted.

0 commit comments

Comments
 (0)