Skip to content

Commit

Permalink
Fail-fast workflows and reports to VK Teams
Browse files Browse the repository at this point in the history
Use strict settings for fast-failing on errors in
bash scripts.

Report failed workflows to VK Teams.

Rename a few variables for consistency with other doc projects.
  • Loading branch information
NickVolynkin committed Aug 18, 2022
1 parent db07f42 commit ca3f133
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 20 deletions.
30 changes: 24 additions & 6 deletions .github/workflows/deploy-branch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,47 @@ jobs:
S3_ENDPOINT_URL: ${{secrets.S3_ENDPOINT_URL}}
S3_UPLOAD_PATH: ${{secrets.S3_UPLOAD_PATH}}
S3_BUCKET: ${{secrets.S3_BUCKET}}
INTERNALS_UPDATE_URL: ${{secrets.INTERNALS_DEVELOP_UPDATE_URL}}
INTERNALS_UPDATE_KEY: ${{secrets.INTERNALS_UPDATE_KEY}}
BRANCH_NAME: test
DEPLOYMENT_NAME: test
VKTEAMS_BOT_TOKEN: ${{secrets.VKTEAMS_TARANTOOLBOT_TOKEN}}
TARANTOOL_UPDATE_URL: ${{secrets.INTERNALS_DEVELOP_UPDATE_URL}}
TARANTOOL_UPDATE_KEY: ${{secrets.INTERNALS_UPDATE_KEY}}
steps:
- uses: actions/checkout@v2
id: checkout

- name: Start dev server deployment
uses: bobheadxi/deployments@v0.5.2
uses: bobheadxi/deployments@v1
id: deployment
with:
step: start
token: ${{secrets.GITHUB_TOKEN}}
env: ${{env.BRANCH_NAME}}
env: ${{env.DEPLOYMENT_NAME}}
ref: ${{github.head_ref}}

- run: make -f ci.mk json
id: make-json
- run: bash upload_output.sh
id: upload-output

- run: bash webhooks/update_deployment.sh
id: update-deployment-webhook

- name: update deployment status
uses: bobheadxi/deployments@v0.5.2
uses: bobheadxi/deployments@v1
with:
step: finish
token: ${{secrets.GITHUB_TOKEN}}
env: ${{env.DEPLOYMENT_NAME}}
status: ${{job.status}}
deployment_id: ${{steps.deployment.outputs.deployment_id}}
env_url: ${{secrets.TARANTOOL_HOST}}

- name: Send VK Teams message on failures
# bot token won't be accessible in the forks
if: ${{ failure() && env.VKTEAMS_BOT_TOKEN != '' }}
uses: tarantool/actions/report-job-status@master
with:
api-url: "https://api.internal.myteam.mail.ru/bot/v1/"
bot-token: ${{ env.VKTEAMS_BOT_TOKEN }}
chat-id: tt_docs_cicd_reports
job-steps: ${{ ToJson(steps) }}
23 changes: 20 additions & 3 deletions .github/workflows/deploy-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,28 @@ jobs:
S3_ENDPOINT_URL: ${{secrets.S3_ENDPOINT_URL}}
S3_UPLOAD_PATH: ${{secrets.S3_UPLOAD_PATH}}
S3_BUCKET: ${{secrets.S3_BUCKET}}
INTERNALS_UPDATE_URL: ${{secrets.INTERNALS_UPDATE_URL}}
INTERNALS_UPDATE_KEY: ${{secrets.INTERNALS_UPDATE_KEY}}
BRANCH_NAME: latest
TARANTOOL_UPDATE_URL: ${{secrets.INTERNALS_UPDATE_URL}}
TARANTOOL_UPDATE_KEY: ${{secrets.INTERNALS_UPDATE_KEY}}
DEPLOYMENT_NAME: latest
VKTEAMS_BOT_TOKEN: ${{secrets.VKTEAMS_TARANTOOLBOT_TOKEN}}
steps:
- uses: actions/checkout@v2
id: checkout

- run: make -f ci.mk json
id: make-json
- run: bash upload_output.sh
id: upload-output

- run: bash webhooks/update_deployment.sh
id: update-deployment-webhook

- name: Send VK Teams message on failures
# bot token won't be accessible in the forks
if: ${{ failure() && env.VKTEAMS_BOT_TOKEN != '' }}
uses: tarantool/actions/report-job-status@master
with:
api-url: "https://api.internal.myteam.mail.ru/bot/v1/"
bot-token: ${{ env.VKTEAMS_BOT_TOKEN }}
chat-id: tt_docs_cicd_reports
job-steps: ${{ ToJson(steps) }}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@
patches/

build/

# secrets for running webhooks locally
webhooks/.env
20 changes: 9 additions & 11 deletions upload_output.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
#!/usr/bin/env bash

set -xe
DOC_DEST="$S3_UPLOAD_PATH/internals/${BRANCH_NAME}"
# version in doc project and scripts
set -xe -o pipefail -o nounset

DOC_DEST="$S3_UPLOAD_PATH/internals/${DEPLOYMENT_NAME}"
# version in doc project and scripts is always 'latest'
# for both prod and test server, because internals
# is a single-version project.
DOC_VERSION=latest
CHECK_KEY="doc-builds/internals/${BRANCH_NAME}/json/_build_en/json/toctree.fjson"
UPDATE_KEY=$INTERNALS_UPDATE_KEY
UPDATE_URL=$INTERNALS_UPDATE_URL
# directory in the S3 bucket: latest or test.
CHECK_KEY="doc-builds/internals/${DEPLOYMENT_NAME}/json/_build_en/json/toctree.fjson"

not_exist=false
aws s3api head-object --bucket ${S3_BUCKET} --key ${CHECK_KEY} --endpoint-url="${S3_ENDPOINT_URL}" || not_exist=true
if [ $not_exist ]; then
echo "toctree.json does not exist"
Expand All @@ -17,8 +20,3 @@ else
fi

aws s3 cp build/json "${DOC_DEST}"/json/_build_en/json --endpoint-url="${S3_ENDPOINT_URL}" --recursive --include "*" --exclude "*.jpg" --exclude "*.png" --exclude "*.svg"

curl --fail --show-error \
--data '{"update_key":"'"${UPDATE_KEY}"'"}' \
--header "Content-Type: application/json" \
--request POST "${UPDATE_URL}""${DOC_VERSION}"/
3 changes: 3 additions & 0 deletions webhooks/.env-example
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
TARANTOOL_UPDATE_URL=
TARANTOOL_UPDATE_KEY=
DEPLOYMENT_NAME=
13 changes: 13 additions & 0 deletions webhooks/update_deployment.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env bash

set -xe -o pipefail -o nounset

echo "Deploy version ${DEPLOYMENT_NAME} on the server"

# testing this locally:
# source .env && export $(cut -d= -f1 .env) && ./update_deployment.sh

curl --fail --show-error -v \
--data '{"update_key":"'"${TARANTOOL_UPDATE_KEY}"'"}' \
--header "Content-Type: application/json" \
--request POST "${TARANTOOL_UPDATE_URL}""${DEPLOYMENT_NAME}"/

0 comments on commit ca3f133

Please sign in to comment.