diff --git a/.github/actions/scripts/send_chat_message.sh b/.github/actions/scripts/send_chat_message.sh new file mode 100644 index 000000000000..78ebba5f20af --- /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:-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}" \ No newline at end of file diff --git a/.github/workflows/release_report_error.yml b/.github/workflows/release_report_error.yml index 75dde4ba14d3..c7947dbc2591 100644 --- a/.github/workflows/release_report_error.yml +++ b/.github/workflows/release_report_error.yml @@ -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 }} \ No newline at end of file + 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 }}" \ 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