Skip to content
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
merged 1 commit into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions .github/actions/slack-check-deployment-blocked/action.yml
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤯

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the question ?

Copy link
Contributor Author

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)

Copy link
Contributor

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 :)

Copy link
Contributor

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?

Copy link
Contributor Author

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).

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

8 changes: 8 additions & 0 deletions .github/workflows/deploy-front-edge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ jobs:
runs-on: ubuntu-latest

steps:
- name: Slack Check Deployment Blocked
uses: ./.github/actions/slack-check-deployment-blocked
with:
step: "start"
component: "front"
channel: ${{ secrets.SLACK_CHANNEL_ID }}
slack_token: ${{ secrets.SLACK_BOT_TOKEN }}

- name: Checkout code
uses: actions/checkout@v3

Expand Down
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
"source.fixAll.eslint": "explicit"
},
"eslint.run": "onSave",
"typescript.preferences.importModuleSpecifier": "non-relative"
"typescript.preferences.importModuleSpecifier": "non-relative",
"github-actions.workflows.pinned.workflows": []
}