-
Notifications
You must be signed in to change notification settings - Fork 117
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add: github action to prevent deployment based on channel topic #8948
Merged
Fraggle
merged 1 commit into
main
from
1680-block-deployments-when-slack-channel-says-so
Nov 27, 2024
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
name: 'Slack Check Deployment Blocked' | ||
description: 'Check the Slack #deployments channel title if deployment should be blocked' | ||
|
||
inputs: | ||
component: | ||
description: 'Component being deployed' | ||
required: true | ||
channel: | ||
description: 'Slack channel' | ||
required: true | ||
slack_token: | ||
description: 'Slack bot token' | ||
required: true | ||
|
||
runs: | ||
using: "composite" | ||
steps: | ||
- name: Get channel info | ||
id: slack_channel_info | ||
uses: slackapi/slack-github-action@v2.0.0 | ||
with: | ||
method: conversations.info | ||
token: ${{ inputs.slack_token }} | ||
payload: | | ||
channel: ${{ inputs.channel }} | ||
|
||
- name: Get channel topic | ||
if: steps.slack_channel_info.outputs.ok == 'true' | ||
id: slack_channel_topic | ||
shell: bash | ||
run: | | ||
RESPONSE='${{ steps.slack_channel_info.outputs.response }}' | ||
if ! TOPIC=$(echo "$RESPONSE" | jq -r '.channel.topic.value'); then | ||
echo "Failed to extract Slack channel topic" >&2 | ||
exit 0 | ||
fi | ||
echo "topic=$TOPIC" >> $GITHUB_OUTPUT | ||
|
||
- name: Parse channel topic for blocked deployments | ||
if: steps.slack_channel_topic.outputs.topic != '' | ||
id: parse_channel_topic | ||
shell: bash | ||
run: | | ||
is_blocked() { | ||
local raw_component="$1" | ||
local component=$(printf '%s' "$raw_component" | sed 's/[][\.*^$/]/\\&/g') | ||
|
||
local status_string="$2" | ||
|
||
if echo "$status_string" | grep -q ":x:[ ]*${component}[ ]" || echo "$status_string" | grep -q ":x:[ ]*${component}|\$" ; then | ||
return 1 | ||
else | ||
return 0 | ||
fi | ||
} | ||
is_blocked "${{ inputs.component }}" "${{ steps.slack_channel_topic.outputs.topic }}" && echo "${{ inputs.component}} is blocked based on channel topic" && exit 1 | ||
|
This file contains 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
This file contains 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤯
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the question ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(grep is limited afaik, | didn't work)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No question! Just a lot of magic :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assumes the human do the right thing as well. Only worry is this interfering with incidents. Is there an easy way to override it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We look for a statement of blocking, otherwise we let it go.
If the slack api fails, we should let it go too (updating the final PR for that).