-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ci: add CF Pages -> Slack notifications (#2270)
This allows to track deployment.
- Loading branch information
Showing
3 changed files
with
77 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
name: Deployment trigger | ||
permissions: read-all | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
|
||
concurrency: | ||
# yamllint disable-line rule:line-length | ||
group: "${{ github.workflow }}-${{ github.ref }}" | ||
cancel-in-progress: true | ||
|
||
jobs: | ||
deploy: | ||
timeout-minutes: 5 | ||
runs-on: ubuntu-20.04 | ||
steps: | ||
- name: Deployment start | ||
if: always() && github.event_name == 'push' && github.ref == 'refs/heads/main' | ||
# yamllint disable-line rule:line-length | ||
# nosemgrep: yaml.github-actions.security.third-party-action-not-pinned-to-commit-sha.third-party-action-not-pinned-to-commit-sha | ||
uses: Mergifyio/gha-slack-notification@main | ||
with: | ||
type: deploy-start | ||
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_DEPLOYMENT_WEBHOOK_URL_RELEASES }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
set -o pipefail | ||
|
||
slack_message () { | ||
local message="$1" | ||
local filename="docs-build-${CF_PAGES_COMMIT_SHA}.log" | ||
|
||
local payload=$( | ||
cat <<SLACK_EOF | ||
{ | ||
"blocks": [ | ||
{ | ||
"type": "section", | ||
"text": { | ||
"type": "mrkdwn", | ||
"text": "${message}" | ||
}, | ||
"accessory": { | ||
"type": "button", | ||
"text": { | ||
"type": "plain_text", | ||
"text": "Cloudflare log", | ||
"emoji": true | ||
}, | ||
"url": "https://dash.cloudflare.com/799c85a11fd788c9c914fa97c52d971e/pages/view/docs-cf-prod" | ||
} | ||
} | ||
] | ||
} | ||
SLACK_EOF | ||
) | ||
echo -en "$payload" | curl -s -H "Content-type: application/json" -d @- "$SLACK_DEPLOYMENT_WEBHOOK_URL_RELEASES" | ||
if [ "$conclusion" == "failure" ]; then | ||
echo -en "$payload" | curl -s -H "Content-type: application/json" -d @- "$SLACK_DEPLOYMENT_WEBHOOK_URL_PROD" | ||
curl -F file=@build.log -F "initial_comment=$filename" -F channels=CJBEQQPFG -H "Authorization: Bearer $SLACK_DEPLOYMENT_BOT_TOKEN" https://slack.com/api/files.upload | ||
fi | ||
} | ||
|
||
echo "Starting build..." > build.log | ||
slack_message "*Building (${CF_PAGES_BRANCH}/${CF_PAGES_COMMIT_SHA}) of docs *" | ||
exit() { slack_message "*Deployment (${CF_PAGES_BRANCH}/${CF_PAGES_COMMIT_SHA}) of docs finished ${emoji}*\\\nConclusion: ${conclusion}"; } | ||
conclusion="failure" emoji="💥" | ||
trap exit EXIT | ||
|
||
gatsby build 2>&1 | tee -a build.log | ||
|
||
conclusion="success" emoji="🦾" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters