From 4f234c492af1d7ef4deb46b206ee90ff95acebe3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Gonz=C3=A1lez?= Date: Thu, 14 Nov 2024 17:12:47 +0100 Subject: [PATCH 01/14] GHA: Notify Mattermost --- .github/actions/scripts/send_chat_message.sh | 70 ++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 .github/actions/scripts/send_chat_message.sh diff --git a/.github/actions/scripts/send_chat_message.sh b/.github/actions/scripts/send_chat_message.sh new file mode 100644 index 000000000000..b992a57190db --- /dev/null +++ b/.github/actions/scripts/send_chat_message.sh @@ -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" +channel_name="${2:-jenkins}" +username="${3:-dax}" +priority="${4:-empty}" # empty, important, or urgent +request_ack="${5:-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}" \ No newline at end of file From b70d6304fd64c1688f4583a81e3d02cd36c50029 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Gonz=C3=A1lez?= Date: Thu, 14 Nov 2024 17:23:40 +0100 Subject: [PATCH 02/14] added a test script --- .github/actions/scripts/send_chat_message.sh | 2 +- .github/workflows/release_report_error.yml | 33 ++++++++++--------- .../workflows/release_report_error_old.yml | 27 +++++++++++++++ 3 files changed, 46 insertions(+), 16 deletions(-) create mode 100644 .github/workflows/release_report_error_old.yml diff --git a/.github/actions/scripts/send_chat_message.sh b/.github/actions/scripts/send_chat_message.sh index b992a57190db..e0c3f0e4c9d1 100644 --- a/.github/actions/scripts/send_chat_message.sh +++ b/.github/actions/scripts/send_chat_message.sh @@ -27,7 +27,7 @@ if [ -z "${MM_TEAM_ID:-}" ]; then fi message="$1" -channel_name="${2:-jenkins}" +channel_name="${2:-thermostat}" username="${3:-dax}" priority="${4:-empty}" # empty, important, or urgent request_ack="${5:-false}" diff --git a/.github/workflows/release_report_error.yml b/.github/workflows/release_report_error.yml index 75dde4ba14d3..3a2de03b78a1 100644 --- a/.github/workflows/release_report_error.yml +++ b/.github/workflows/release_report_error.yml @@ -4,24 +4,27 @@ 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 }} 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/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 }} \ No newline at end of file + submodules: recursive + token: ${{ secrets.GT_DAXMOBILE }} + fetch-depth: 0 + + - name: Run a script + run: | + chmod +x send_chat_message.sh + ./send_chat_message.sh "This is a test" \ No newline at end of file diff --git a/.github/workflows/release_report_error_old.yml b/.github/workflows/release_report_error_old.yml new file mode 100644 index 000000000000..75dde4ba14d3 --- /dev/null +++ b/.github/workflows/release_report_error_old.yml @@ -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 }} \ No newline at end of file From 480787837ba4d4cdd914c7de0dc914fbd543f0dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Gonz=C3=A1lez?= Date: Thu, 14 Nov 2024 17:28:45 +0100 Subject: [PATCH 03/14] ensure proper branch is checked --- .github/workflows/release_report_error.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/release_report_error.yml b/.github/workflows/release_report_error.yml index 3a2de03b78a1..f4285cc5c55d 100644 --- a/.github/workflows/release_report_error.yml +++ b/.github/workflows/release_report_error.yml @@ -23,6 +23,7 @@ jobs: submodules: recursive token: ${{ secrets.GT_DAXMOBILE }} fetch-depth: 0 + ref: feature/david/11-14-gha_notify_mattermost - name: Run a script run: | From e2e6205475732e30b8e79b6bffe24a12c00d57e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Gonz=C3=A1lez?= Date: Thu, 14 Nov 2024 17:34:31 +0100 Subject: [PATCH 04/14] proper scrip location --- .github/workflows/release_report_error.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release_report_error.yml b/.github/workflows/release_report_error.yml index f4285cc5c55d..a43ab1d70453 100644 --- a/.github/workflows/release_report_error.yml +++ b/.github/workflows/release_report_error.yml @@ -14,7 +14,7 @@ jobs: defaults: run: shell: bash - working-directory: ./github/scripts + working-directory: ./github/actions/scripts steps: - name: Checkout repository From d4400953fdf69995a04c456078a1d15587fbb8c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Gonz=C3=A1lez?= Date: Thu, 14 Nov 2024 17:36:57 +0100 Subject: [PATCH 05/14] move to defualt directyory --- .github/workflows/release_report_error.yml | 4 ---- .github/{actions/scripts => workflows}/send_chat_message.sh | 0 2 files changed, 4 deletions(-) rename .github/{actions/scripts => workflows}/send_chat_message.sh (100%) diff --git a/.github/workflows/release_report_error.yml b/.github/workflows/release_report_error.yml index a43ab1d70453..61f0faa7cce3 100644 --- a/.github/workflows/release_report_error.yml +++ b/.github/workflows/release_report_error.yml @@ -11,10 +11,6 @@ jobs: report-release-error: name: Notify Mattermost runs-on: ubuntu-latest - defaults: - run: - shell: bash - working-directory: ./github/actions/scripts steps: - name: Checkout repository diff --git a/.github/actions/scripts/send_chat_message.sh b/.github/workflows/send_chat_message.sh similarity index 100% rename from .github/actions/scripts/send_chat_message.sh rename to .github/workflows/send_chat_message.sh From 240f5caacd216ea2c1af9e87415ef09137045a40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Gonz=C3=A1lez?= Date: Thu, 14 Nov 2024 17:40:08 +0100 Subject: [PATCH 06/14] back to main folder --- .github/{workflows => actions/scripts}/send_chat_message.sh | 2 +- .github/workflows/release_report_error.yml | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) rename .github/{workflows => actions/scripts}/send_chat_message.sh (99%) diff --git a/.github/workflows/send_chat_message.sh b/.github/actions/scripts/send_chat_message.sh similarity index 99% rename from .github/workflows/send_chat_message.sh rename to .github/actions/scripts/send_chat_message.sh index e0c3f0e4c9d1..f5b17138c3dd 100644 --- a/.github/workflows/send_chat_message.sh +++ b/.github/actions/scripts/send_chat_message.sh @@ -26,7 +26,7 @@ if [ -z "${MM_TEAM_ID:-}" ]; then exit 1 fi -message="$1" +message="${1:-test}" channel_name="${2:-thermostat}" username="${3:-dax}" priority="${4:-empty}" # empty, important, or urgent diff --git a/.github/workflows/release_report_error.yml b/.github/workflows/release_report_error.yml index 61f0faa7cce3..f66c1ea039bf 100644 --- a/.github/workflows/release_report_error.yml +++ b/.github/workflows/release_report_error.yml @@ -11,6 +11,10 @@ jobs: report-release-error: name: Notify Mattermost runs-on: ubuntu-latest + defaults: + run: + shell: bash + working-directory: ./.github/actions/scripts steps: - name: Checkout repository From b2c96e72a8d13154bbe3bea59b9a6164057306b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Gonz=C3=A1lez?= Date: Thu, 14 Nov 2024 17:56:28 +0100 Subject: [PATCH 07/14] testing mentions in MM --- .github/workflows/release_report_error.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release_report_error.yml b/.github/workflows/release_report_error.yml index f66c1ea039bf..435a2571e3f3 100644 --- a/.github/workflows/release_report_error.yml +++ b/.github/workflows/release_report_error.yml @@ -28,4 +28,4 @@ jobs: - name: Run a script run: | chmod +x send_chat_message.sh - ./send_chat_message.sh "This is a test" \ No newline at end of file + ./send_chat_message.sh "@acaptina please finish the graphs" \ No newline at end of file From 852dd13bb37efc6fbf0137eea4d74c83fd022d46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Gonz=C3=A1lez?= Date: Thu, 14 Nov 2024 18:03:20 +0100 Subject: [PATCH 08/14] typo --- .github/workflows/release_report_error.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release_report_error.yml b/.github/workflows/release_report_error.yml index 435a2571e3f3..c3b2acc7564e 100644 --- a/.github/workflows/release_report_error.yml +++ b/.github/workflows/release_report_error.yml @@ -28,4 +28,4 @@ jobs: - name: Run a script run: | chmod +x send_chat_message.sh - ./send_chat_message.sh "@acaptina please finish the graphs" \ No newline at end of file + ./send_chat_message.sh "@acapa"'tina please finish the graphs" \ No newline at end of file From 3c21e18a64a594f7dcccf3e7971129144d84e8c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Gonz=C3=A1lez?= Date: Thu, 14 Nov 2024 18:05:26 +0100 Subject: [PATCH 09/14] proper name --- .github/workflows/release_report_error.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release_report_error.yml b/.github/workflows/release_report_error.yml index c3b2acc7564e..8dfebd134c6c 100644 --- a/.github/workflows/release_report_error.yml +++ b/.github/workflows/release_report_error.yml @@ -28,4 +28,4 @@ jobs: - name: Run a script run: | chmod +x send_chat_message.sh - ./send_chat_message.sh "@acapa"'tina please finish the graphs" \ No newline at end of file + ./send_chat_message.sh "@acapatina please finish the graphs" \ No newline at end of file From 2358dfaa61f5978ed56b00ac77677f307eae55d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Gonz=C3=A1lez?= Date: Thu, 14 Nov 2024 21:23:03 +0100 Subject: [PATCH 10/14] added release start message --- .github/actions/scripts/send_chat_message.sh | 2 +- .github/workflows/release_report_error.yml | 12 +++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/.github/actions/scripts/send_chat_message.sh b/.github/actions/scripts/send_chat_message.sh index f5b17138c3dd..289738b7f729 100644 --- a/.github/actions/scripts/send_chat_message.sh +++ b/.github/actions/scripts/send_chat_message.sh @@ -27,7 +27,7 @@ if [ -z "${MM_TEAM_ID:-}" ]; then fi message="${1:-test}" -channel_name="${2:-thermostat}" +channel_name="${2:-david-test-channel}" username="${3:-dax}" priority="${4:-empty}" # empty, important, or urgent request_ack="${5:-false}" diff --git a/.github/workflows/release_report_error.yml b/.github/workflows/release_report_error.yml index 8dfebd134c6c..664ff6b1baa4 100644 --- a/.github/workflows/release_report_error.yml +++ b/.github/workflows/release_report_error.yml @@ -6,6 +6,7 @@ on: env: MM_AUTH_TOKEN: ${{ secrets.MM_AUTH_TOKEN }} MM_TEAM_ID: ${{ secrets.MM_TEAM_ID }} + APP_VERSION: "5.220.0" jobs: report-release-error: @@ -25,7 +26,12 @@ jobs: fetch-depth: 0 ref: feature/david/11-14-gha_notify_mattermost - - name: Run a script + - name: Make sure script can be executed run: | - chmod +x send_chat_message.sh - ./send_chat_message.sh "@acapatina please finish the graphs" \ No newline at end of file + chmod +x send_chat_message.sh + + - name: Send Release start message + run: | + message="Release ${{ env.APP_VERSION }} by @${{ github.actor }} has started." + message+="See https://github.com/duckduckgo/Android/actions/runs/${{ github.run_id }}" + ./send_chat_message.sh ${message} \ No newline at end of file From 5f9aa3b21c40a7065aa114e9809a4d82cc51aab5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Gonz=C3=A1lez?= Date: Thu, 14 Nov 2024 21:35:58 +0100 Subject: [PATCH 11/14] sending message as parameter --- .github/actions/scripts/send_chat_message.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/actions/scripts/send_chat_message.sh b/.github/actions/scripts/send_chat_message.sh index 289738b7f729..78ebba5f20af 100644 --- a/.github/actions/scripts/send_chat_message.sh +++ b/.github/actions/scripts/send_chat_message.sh @@ -27,10 +27,10 @@ if [ -z "${MM_TEAM_ID:-}" ]; then fi message="${1:-test}" -channel_name="${2:-david-test-channel}" -username="${3:-dax}" -priority="${4:-empty}" # empty, important, or urgent -request_ack="${5:-false}" +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' From bf390c43314d441a799e1a154f9dc4cb13276fed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Gonz=C3=A1lez?= Date: Thu, 14 Nov 2024 21:40:24 +0100 Subject: [PATCH 12/14] message formatting --- .github/workflows/release_report_error.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/release_report_error.yml b/.github/workflows/release_report_error.yml index 664ff6b1baa4..ec0ce1951a6d 100644 --- a/.github/workflows/release_report_error.yml +++ b/.github/workflows/release_report_error.yml @@ -7,6 +7,7 @@ env: MM_AUTH_TOKEN: ${{ secrets.MM_AUTH_TOKEN }} MM_TEAM_ID: ${{ secrets.MM_TEAM_ID }} APP_VERSION: "5.220.0" + emoji_info: ":information_source:" # ℹī¸ jobs: report-release-error: @@ -32,6 +33,7 @@ jobs: - name: Send Release start message run: | + echo -n '::notice title=Inputs::' && echo '${{ toJson(inputs) }}' | sed -z 's_\n_%0A_g'; echo message="Release ${{ env.APP_VERSION }} by @${{ github.actor }} has started." message+="See https://github.com/duckduckgo/Android/actions/runs/${{ github.run_id }}" - ./send_chat_message.sh ${message} \ No newline at end of file + ./send_chat_message.sh '${{env.emoji_info}}'" ${message} \ No newline at end of file From 9dae9a80d486142bf8f3e96e4b00ae2e58d4ad4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Gonz=C3=A1lez?= Date: Thu, 14 Nov 2024 21:50:06 +0100 Subject: [PATCH 13/14] missing char --- .github/workflows/release_report_error.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release_report_error.yml b/.github/workflows/release_report_error.yml index ec0ce1951a6d..5fe41fbd76b8 100644 --- a/.github/workflows/release_report_error.yml +++ b/.github/workflows/release_report_error.yml @@ -36,4 +36,4 @@ jobs: echo -n '::notice title=Inputs::' && echo '${{ toJson(inputs) }}' | sed -z 's_\n_%0A_g'; echo message="Release ${{ env.APP_VERSION }} by @${{ github.actor }} has started." message+="See https://github.com/duckduckgo/Android/actions/runs/${{ github.run_id }}" - ./send_chat_message.sh '${{env.emoji_info}}'" ${message} \ No newline at end of file + ./send_chat_message.sh '${{env.emoji_info}}'" ${message}" \ No newline at end of file From 24a1de69d7ad8620358eff27c236f9962fb80a55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Gonz=C3=A1lez?= Date: Thu, 14 Nov 2024 22:24:12 +0100 Subject: [PATCH 14/14] skeleton two more steps --- .github/workflows/release_report_error.yml | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/.github/workflows/release_report_error.yml b/.github/workflows/release_report_error.yml index 5fe41fbd76b8..c7947dbc2591 100644 --- a/.github/workflows/release_report_error.yml +++ b/.github/workflows/release_report_error.yml @@ -7,6 +7,7 @@ env: 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: @@ -31,9 +32,22 @@ jobs: run: | chmod +x send_chat_message.sh - - name: Send Release start message + - 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 }} by @${{ github.actor }} has started." - message+="See https://github.com/duckduckgo/Android/actions/runs/${{ github.run_id }}" - ./send_chat_message.sh '${{env.emoji_info}}'" ${message}" \ No newline at end of file + 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 }}" \ No newline at end of file