From 57ce0e35c3e829768e5a9fb76ecf475c7c1a1897 Mon Sep 17 00:00:00 2001 From: Dhruv Bhanushali Date: Wed, 29 Mar 2023 21:03:06 +0400 Subject: [PATCH 1/7] Add a Slack notification job to the CI + CD workflow --- .github/workflows/ci_cd.yml | 94 +++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) diff --git a/.github/workflows/ci_cd.yml b/.github/workflows/ci_cd.yml index 025f329bdb..8b167da70a 100644 --- a/.github/workflows/ci_cd.yml +++ b/.github/workflows/ci_cd.yml @@ -726,3 +726,97 @@ jobs: with: tag: ${{ needs.get-image-tag.outputs.image_tag }} secrets: inherit + + ################ + # Notification # + ################ + + send_report: + name: Send Slack report + if: | + !cancelled() && + github.event_name == 'push' && + github.repository == 'WordPress/openverse' && + ( + needs.emit-docs.result == 'failure' || needs.emit-docs.result == 'skipped' || + needs.publish-images.result == 'failure' || needs.publish-images.result == 'skipped' || + needs.deploy-frontend.result == 'failure' || needs.deploy-frontend.result == 'skipped' || + needs.deploy-api.result == 'failure' || needs.deploy-api.result == 'skipped' + ) + needs: # the end products of the CI + CD workflow + - emit-docs + - publish-images + - deploy-frontend + - deploy-api + + steps: + - name: Generate report + id: report + shell: python + env: + EMIT_DOCS_RESULT: ${{ needs.emit-docs.result }} + PUBLISH_IMAGES_RESULT: ${{ needs.publish-images.result }} + DEPLOY_FRONTEND_RESULT: ${{ needs.deploy-frontend.result }} + DEPLOY_API_RESULT: ${{ needs.deploy-api.result }} + SERVER_URL: ${{ github.server_url }} + REPOSITORY: ${{ github.repository }} + RUN_ID: ${{ github.run_id }} + run: | + import json + import os + import sys + from collections import defaultdict + + server_url = os.environ.get("SERVER_URL") + repository = os.environ.get("REPOSITORY") + run_id = os.environ.get("RUN_ID") + + jobs = ["emit-docs", "publish-images", "deploy-frontend", "deploy-api"] + emojis = { + "success": ":tadaco:", + "cancelled": ":no-good:", + "failure": ":alert:", + "skipped": ":warning:", + } + + results = {} + counts = defaultdict(lambda: 0) + + for job_name in jobs: + result = os.environ.get(f"{job_name.replace('-', '_')}_result".upper()) + results[job_name] = result + counts[result] += 1 + + payload = { + "text": ", ".join(f"{count} {result}" for result, count in counts.items()), + "blocks": [ + { + "type": "section", + "text": { + "type": "mrkdwn", + "text": f"<{server_url}/{repository}/actions/runs/{run_id}|Click here to review the completed CI + CD workflow>.", + }, + }, + { + "type": "section", + "fields": [ + { + "type": "mrkdwn", + "text": f"*{job_name}:*\n{emojis[result]} {result}", + } + for job_name, result in results.items() + ], + }, + ], + } + + with open(os.environ.get("GITHUB_OUTPUT"), "a") as gh_out: + for dest in [sys.stdout, gh_out]: + print(f"payload={json.dumps(payload)}", file=dest) + + - name: Send report + uses: slackapi/slack-github-action@v1.23.0 + with: + payload: ${{ steps.report.outputs.payload }} + env: + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} From 4d4e304241e633d25673cc33636a22d1d003be18 Mon Sep 17 00:00:00 2001 From: Dhruv Bhanushali Date: Wed, 29 Mar 2023 21:21:31 +0400 Subject: [PATCH 2/7] Add `runs-on` --- .github/workflows/ci_cd.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci_cd.yml b/.github/workflows/ci_cd.yml index 8b167da70a..56535b9693 100644 --- a/.github/workflows/ci_cd.yml +++ b/.github/workflows/ci_cd.yml @@ -733,6 +733,7 @@ jobs: send_report: name: Send Slack report + runs-on: ubuntu-latest if: | !cancelled() && github.event_name == 'push' && From 537f889060003215d595ba743bb87e160fcd38c8 Mon Sep 17 00:00:00 2001 From: Dhruv Bhanushali Date: Thu, 30 Mar 2023 00:31:37 +0400 Subject: [PATCH 3/7] Fix emoji name --- .github/workflows/ci_cd.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci_cd.yml b/.github/workflows/ci_cd.yml index 56535b9693..7be0cc469b 100644 --- a/.github/workflows/ci_cd.yml +++ b/.github/workflows/ci_cd.yml @@ -775,7 +775,7 @@ jobs: jobs = ["emit-docs", "publish-images", "deploy-frontend", "deploy-api"] emojis = { "success": ":tadaco:", - "cancelled": ":no-good:", + "cancelled": ":no_good:", "failure": ":alert:", "skipped": ":warning:", } From 60e0ad747cc6294e84056a721f8ce94ba91b0e45 Mon Sep 17 00:00:00 2001 From: Dhruv Bhanushali Date: Thu, 30 Mar 2023 00:52:35 +0400 Subject: [PATCH 4/7] Use newly added custom Slack emoji --- .github/workflows/ci_cd.yml | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/.github/workflows/ci_cd.yml b/.github/workflows/ci_cd.yml index 7be0cc469b..d393708b83 100644 --- a/.github/workflows/ci_cd.yml +++ b/.github/workflows/ci_cd.yml @@ -773,12 +773,6 @@ jobs: run_id = os.environ.get("RUN_ID") jobs = ["emit-docs", "publish-images", "deploy-frontend", "deploy-api"] - emojis = { - "success": ":tadaco:", - "cancelled": ":no_good:", - "failure": ":alert:", - "skipped": ":warning:", - } results = {} counts = defaultdict(lambda: 0) @@ -803,7 +797,7 @@ jobs: "fields": [ { "type": "mrkdwn", - "text": f"*{job_name}:*\n{emojis[result]} {result}", + "text": f"*{job_name}:*\n:workflow-{result}: {result}", } for job_name, result in results.items() ], From ee723ca88ad761e86fb7cb87ecfd2dffd3f329fa Mon Sep 17 00:00:00 2001 From: Dhruv Bhanushali Date: Thu, 30 Mar 2023 02:22:50 +0400 Subject: [PATCH 5/7] Track documentation changes --- .github/actions/get-changes/action.yml | 3 +++ .github/filters.yml | 4 ++++ .github/workflows/ci_cd.yml | 1 + 3 files changed, 8 insertions(+) diff --git a/.github/actions/get-changes/action.yml b/.github/actions/get-changes/action.yml index bf5c3351c0..9cdd64c8f9 100644 --- a/.github/actions/get-changes/action.yml +++ b/.github/actions/get-changes/action.yml @@ -14,6 +14,9 @@ outputs: frontend: description: "'true' if frontend changes are present" value: ${{ steps.paths-filter.outputs.frontend }} + documentation: + description: "'true' if documentation changes are present" + value: ${{ steps.paths-filter.outputs.documentation }} lint: description: "'true' if linting setup changes are present" value: ${{ steps.paths-filter.outputs.frontend }} diff --git a/.github/filters.yml b/.github/filters.yml index 86d3255c73..f541892b89 100644 --- a/.github/filters.yml +++ b/.github/filters.yml @@ -15,6 +15,10 @@ frontend: - .pnpmfile.cjs # Change to the CI + CD workflow should trigger complete workflow. - .github/workflows/ci_cd.yml +documentation: + - documentation/** + # Change to the CI + CD workflow should trigger complete workflow. + - .github/workflows/ci_cd.yml lint: - prettier.config.js - .prettierignore diff --git a/.github/workflows/ci_cd.yml b/.github/workflows/ci_cd.yml index 5c1408212d..ef5181d834 100644 --- a/.github/workflows/ci_cd.yml +++ b/.github/workflows/ci_cd.yml @@ -33,6 +33,7 @@ jobs: api: ${{ steps.paths-filter.outputs.api }} ingestion_server: ${{ steps.paths-filter.outputs.ingestion_server }} frontend: ${{ steps.paths-filter.outputs.frontend }} + documentation: ${{ steps.paths-filter.outputs.documentation }} changes: ${{ steps.paths-filter.outputs.changes }} steps: - name: Checkout repository From 8d9d87fb9bed2376c21d7ccfa6087277440eeb3b Mon Sep 17 00:00:00 2001 From: Dhruv Bhanushali Date: Thu, 30 Mar 2023 02:23:14 +0400 Subject: [PATCH 6/7] Only build docs if docs have changed --- .github/workflows/ci_cd.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/ci_cd.yml b/.github/workflows/ci_cd.yml index ef5181d834..221ac247bc 100644 --- a/.github/workflows/ci_cd.yml +++ b/.github/workflows/ci_cd.yml @@ -596,11 +596,13 @@ jobs: github.actor != 'dependabot[bot]' ) ) && + (needs.get-changes.outputs.frontend == 'true' || needs.get-changes.outputs.documentation == 'true') && (needs.test-ing.result == 'success' || needs.test-ing.result == 'skipped') && (needs.test-api.result == 'success' || needs.test-api.result == 'skipped') && (needs.nuxt-build.result == 'success' || needs.nuxt-build.result == 'skipped') runs-on: ubuntu-latest needs: + - get-changes - test-ing - test-api - nuxt-build From 888834e794db583b9ae8bb68a8a431cde1af3c0a Mon Sep 17 00:00:00 2001 From: Dhruv Bhanushali Date: Thu, 30 Mar 2023 02:37:45 +0400 Subject: [PATCH 7/7] Run report only in case of a problem --- .github/workflows/ci_cd.yml | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci_cd.yml b/.github/workflows/ci_cd.yml index bca9e83ed6..89ee8d7f3e 100644 --- a/.github/workflows/ci_cd.yml +++ b/.github/workflows/ci_cd.yml @@ -782,12 +782,14 @@ jobs: github.event_name == 'push' && github.repository == 'WordPress/openverse' && ( - needs.emit-docs.result == 'failure' || needs.emit-docs.result == 'skipped' || - needs.publish-images.result == 'failure' || needs.publish-images.result == 'skipped' || - needs.deploy-frontend.result == 'failure' || needs.deploy-frontend.result == 'skipped' || - needs.deploy-api.result == 'failure' || needs.deploy-api.result == 'skipped' + ((needs.get-changes.outputs.frontend == 'true' || needs.get-changes.outputs.documentation == 'true') && needs.emit-docs.result != 'success') || + (needs.determine-images.outputs.do_publish == 'true' && needs.publish-images.result != 'success') || + (needs.get-changes.outputs.frontend == 'true' && needs.deploy-frontend.result != 'success') || + (needs.get-changes.outputs.api == 'true' && needs.deploy-api.result != 'success') ) needs: # the end products of the CI + CD workflow + - get-changes + - determine-images - emit-docs - publish-images - deploy-frontend