@@ -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
2118outputs :
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 }}
0 commit comments