-
Notifications
You must be signed in to change notification settings - Fork 913
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
GHA: Notify Mattermost #5274
base: develop
Are you sure you want to change the base?
GHA: Notify Mattermost #5274
Changes from all commits
4f234c4
b70d630
4807878
e2e6205
d440095
240f5ca
b2c96e7
852dd13
3c21e18
2358dfa
5f9aa3b
bf390c4
9dae9a8
24a1de6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
#!/usr/bin/env -S bash -euo pipefail | ||
|
||
# | ||
# Copyright (c) 2024 DuckDuckGo | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
if [ -z "${MM_AUTH_TOKEN:-}" ]; then | ||
echo 'MM_AUTH_TOKEN is not set!' | ||
exit 1 | ||
fi | ||
|
||
if [ -z "${MM_TEAM_ID:-}" ]; then | ||
echo 'MM_TEAM_ID is not set!' | ||
exit 1 | ||
fi | ||
|
||
message="${1:-test}" | ||
channel_name="david-test-channel" | ||
username="dax" | ||
priority="empty" # empty, important, or urgent | ||
request_ack="false" | ||
# Same icon as https://dub.duckduckgo.com/orgs/duckduckgo/teams/ci/edit. Uploaded with `s3cmd put --acl-public dax-ci-avatar.png 's3://ddg-chef/dax-ci-avatar.png` | ||
icon_url='https://ddg-chef.s3.amazonaws.com/dax-ci-avatar.png' | ||
|
||
# API docs at https://api.mattermost.com/#tag/posts/operation/CreatePost | ||
MM_API='https://chat.duckduckgo.com/api/v4' | ||
MM_AUTH="Authorization: Bearer ${MM_AUTH_TOKEN}" | ||
|
||
echo "> Getting id of https://chat.duckduckgo.com/ddg/channels/${channel_name}..." | ||
channel_id=$(curl -sS -H "$MM_AUTH" "${MM_API}/teams/${MM_TEAM_ID}/channels/name/${channel_name}" | jq -r '.id') | ||
echo "> Found https://chat.duckduckgo.com/ddg/channels/${channel_id}" | ||
|
||
if [ "${GITHUB_ACTIONS:-}" ]; then | ||
now=$(date '+%H:%M %Z') | ||
single_line_message=$(echo -n "${message}" | sed -z 's_\n_%0A_g') | ||
echo "::notice title=${username} to ~${channel_name} at ${now}::${single_line_message}" | ||
fi | ||
|
||
json_message=$(echo -n "${message}" | jq -Rs .) # includes double-quotes around message | ||
echo "> Sending ${json_message} with priority '${priority}'..." | ||
res=$(curl -sS --fail -H "$MM_AUTH" -X POST "${MM_API}/posts" -d '{ | ||
"channel_id":"'"${channel_id}"'", | ||
"message":'"${json_message}"', | ||
"metadata": { | ||
"priority": { | ||
"priority": "'"${priority}"'", | ||
"requested_ack": '"${request_ack}"' | ||
} | ||
}, | ||
"props":{ | ||
"override_username": "'"${username}"'", | ||
"override_icon_url":"'"${icon_url}"'", | ||
"from_webhook": "true" | ||
} | ||
}') | ||
|
||
post_id=$(echo "$res" | jq -r '.id') | ||
echo "✔ Sent https://chat.duckduckgo.com/ddg/pl/${post_id}" |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,24 +4,50 @@ on: | |
workflow_dispatch: | ||
|
||
env: | ||
ASANA_PAT: ${{ secrets.GH_ASANA_SECRET }} | ||
|
||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.ref }} | ||
cancel-in-progress: true | ||
MM_AUTH_TOKEN: ${{ secrets.MM_AUTH_TOKEN }} | ||
MM_TEAM_ID: ${{ secrets.MM_TEAM_ID }} | ||
APP_VERSION: "5.220.0" | ||
emoji_start: ":flight_departure:" # 🛫 or ':soon:' 🔜 | ||
emoji_info: ":information_source:" # ℹ️ | ||
|
||
jobs: | ||
report-release-error: | ||
name: Create Asana Task | ||
runs-on: ubuntu-20.04 | ||
name: Notify Mattermost | ||
runs-on: ubuntu-latest | ||
defaults: | ||
run: | ||
shell: bash | ||
working-directory: ./.github/actions/scripts | ||
|
||
steps: | ||
- name: Create Asana task when workflow failed | ||
uses: honeycombio/gha-create-asana-task@main | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
with: | ||
asana-secret: ${{ secrets.GH_ASANA_SECRET }} | ||
asana-workspace-id: ${{ secrets.GH_ASANA_WORKSPACE_ID }} | ||
asana-project-id: ${{ secrets.GH_ASANA_AOR_PROJECT_ID }} | ||
asana-section-id: ${{ secrets.GH_ASANA_INCOMING_ID }} | ||
asana-task-name: GH Workflow Failure - Production Release | ||
asana-task-description: The end to end workflow has failed. See https://github.com/duckduckgo/Android/actions/runs/${{ github.run_id }} | ||
submodules: recursive | ||
token: ${{ secrets.GT_DAXMOBILE }} | ||
fetch-depth: 0 | ||
ref: feature/david/11-14-gha_notify_mattermost | ||
|
||
- name: Make sure script can be executed | ||
run: | | ||
chmod +x send_chat_message.sh | ||
|
||
- name: Send Release started message | ||
run: | | ||
./send_chat_message.sh '${{env.emoji_start}}'" Android Release ${{ env.APP_VERSION }} started by @${{ github.actor }}. https://github.com/duckduckgo/Android/actions/runs/${{ github.run_id }}" | ||
|
||
- name: Send Release task created message | ||
run: | | ||
./send_chat_message.sh '${{env.emoji_info}}'" Release task created https://github.com/duckduckgo/Android/actions/runs/${{ github.run_id }}" | ||
|
||
- name: Send Release tag created | ||
run: | | ||
./send_chat_message.sh '${{env.emoji_info}}'" Release task created https://github.com/duckduckgo/Android/actions/runs/${{ github.run_id }}" | ||
|
||
- name: Send Release task created message | ||
run: | | ||
echo -n '::notice title=Inputs::' && echo '${{ toJson(inputs) }}' | sed -z 's_\n_%0A_g'; echo | ||
message="Release ${{ env.APP_VERSION }} task created" | ||
message+="See https://github.com/duckduckgo/Android/actions/runs/${{ github.run_id }}" | ||
./send_chat_message.sh '${{env.emoji_info}}'" ${message}" | ||
./send_chat_message.sh '${{env.emoji_info}}'" Release task created https://github.com/duckduckgo/Android/actions/runs/${{ github.run_id }}" | ||
Comment on lines
+39
to
+53
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There appear to be several duplicate message sends in this workflow. Specifically:
Consider consolidating these into single message sends to avoid duplicate notifications in the chat channel. This will keep the notifications clean and meaningful for the team. Spotted by Graphite Reviewer |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
name: Report Workflow Failed | ||
|
||
on: | ||
workflow_dispatch: | ||
|
||
env: | ||
ASANA_PAT: ${{ secrets.GH_ASANA_SECRET }} | ||
|
||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.ref }} | ||
cancel-in-progress: true | ||
|
||
jobs: | ||
report-release-error: | ||
name: Create Asana Task | ||
runs-on: ubuntu-20.04 | ||
|
||
steps: | ||
- name: Create Asana task when workflow failed | ||
uses: honeycombio/gha-create-asana-task@main | ||
with: | ||
asana-secret: ${{ secrets.GH_ASANA_SECRET }} | ||
asana-workspace-id: ${{ secrets.GH_ASANA_WORKSPACE_ID }} | ||
asana-project-id: ${{ secrets.GH_ASANA_AOR_PROJECT_ID }} | ||
asana-section-id: ${{ secrets.GH_ASANA_INCOMING_ID }} | ||
asana-task-name: GH Workflow Failure - Production Release | ||
asana-task-description: The end to end workflow has failed. See https://github.com/duckduckgo/Android/actions/runs/${{ github.run_id }} |
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.
The
ref
parameter is hardcoded to a specific feature branch, which will prevent this workflow from running on other branches. Consider removing this line to allow the workflow to execute on the current branch where it's triggered.Spotted by Graphite Reviewer
Is this helpful? React 👍 or 👎 to let us know.