Skip to content

Commit 334f7cd

Browse files
committed
Report workflow failures to VK Teams
When a workflow fails, a message will be sent to VK Teams, @tt_docs_cicd_reports. This will only work with PRs from original repository, but not from forks. Also, extract webhooks into separate scripts to make separate steps for them. This way, we'll know which step failed: uploading to S3 or running a webhook. Rename BRANCH_NAME to DEPLOYMENT_NAME in scripts and workflows, becase it makes more sense in workflows deploy-custom and destroy-deployment-manually. Update bobheadxi/deployments to version 1, which supports deleting deployments entirely. Resolves #3085
1 parent 450f342 commit 334f7cd

10 files changed

+183
-50
lines changed

Diff for: .github/workflows/deploy-branch.yml

+32-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Deploy-branch
1+
name: Deploy to dev server
22

33
on:
44
pull_request:
@@ -14,38 +14,63 @@ jobs:
1414
S3_UPLOAD_PATH: ${{secrets.S3_UPLOAD_PATH}}
1515
TARANTOOL_UPDATE_KEY: ${{secrets.TARANTOOL_UPDATE_KEY}}
1616
TARANTOOL_UPDATE_URL: ${{secrets.TARANTOOL_DEVELOP_UPDATE_URL}}
17+
VKTEAMS_BOT_TOKEN: ${{secrets.VKTEAMS_TARANTOOLBOT_TOKEN}}
1718
steps:
1819
- uses: actions/checkout@v2
20+
id: checkout
1921
with:
2022
submodules: recursive
2123

2224
- name: Fetch submodules
25+
id: fetch-submodules
2326
run: git fetch --recurse-submodules
2427

25-
- name: Set branch name from source branch
26-
run: echo "BRANCH_NAME=${GITHUB_HEAD_REF##*/}" >> $GITHUB_ENV
28+
- name: Set deployment name from source branch
29+
id: set-deployment-name
30+
run: echo "DEPLOYMENT_NAME=${GITHUB_HEAD_REF##*/}" >> $GITHUB_ENV
2731

2832
- name: Start dev server deployment
29-
uses: bobheadxi/deployments@v0.5.2
33+
uses: bobheadxi/deployments@v1
3034
id: deployment
3135
with:
3236
step: start
3337
token: ${{secrets.GITHUB_TOKEN}}
34-
env: "branch-${{env.BRANCH_NAME}}"
38+
env: "branch-${{env.DEPLOYMENT_NAME}}"
3539
ref: ${{github.head_ref}}
3640

3741
- run: cmake .
42+
id: cmake
3843
- run: make pull-modules
44+
id: make-pull-modules
3945
- run: make build-modules
46+
id: make-build-modules
4047
- run: make json
48+
id: make-json
4149
- run: make json-ru
50+
id: make-json-ru
51+
4252
- run: bash upload_output.sh
53+
id: upload-output
54+
- run: bash webhooks/update_deployment.sh
55+
id: update-deployment-webhook
4356

4457
- name: update deployment status
45-
uses: bobheadxi/[email protected]
58+
id: finalize-deployment
59+
uses: bobheadxi/deployments@v1
4660
with:
4761
step: finish
4862
token: ${{secrets.GITHUB_TOKEN}}
63+
env: "branch-${{env.DEPLOYMENT_NAME}}"
4964
status: ${{job.status}}
5065
deployment_id: ${{steps.deployment.outputs.deployment_id}}
51-
env_url: ${{secrets.TARANTOOL_HOST}}/doc/${{env.BRANCH_NAME}}/
66+
env_url: ${{secrets.TARANTOOL_HOST}}/doc/${{env.DEPLOYMENT_NAME}}/
67+
68+
- name: Send VK Teams message on failures
69+
# bot token won't be accessible in the forks
70+
if: ${{ failure() && env.VKTEAMS_BOT_TOKEN != '' }}
71+
uses: tarantool/actions/report-job-status@master
72+
with:
73+
api-url: "https://api.internal.myteam.mail.ru/bot/v1/"
74+
bot-token: ${{ env.VKTEAMS_BOT_TOKEN }}
75+
chat-id: tt_docs_cicd_reports
76+
job-steps: ${{ ToJson(steps) }}

Diff for: .github/workflows/deploy-custom.yml

+34-7
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: Custom-deploy-branch
33
on:
44
workflow_dispatch:
55
inputs:
6-
env_name:
6+
deployment_name:
77
description: 'Enter unique name (version) of deployment'
88
required: True
99
cartridge:
@@ -40,20 +40,24 @@ jobs:
4040
S3_UPLOAD_PATH: ${{secrets.S3_UPLOAD_PATH}}
4141
TARANTOOL_UPDATE_KEY: ${{secrets.TARANTOOL_UPDATE_KEY}}
4242
TARANTOOL_UPDATE_URL: ${{secrets.TARANTOOL_DEVELOP_UPDATE_URL}}
43+
VKTEAMS_BOT_TOKEN: ${{secrets.VKTEAMS_TARANTOOLBOT_TOKEN}}
4344
steps:
4445
- uses: actions/checkout@v2
46+
id: checkout
4547
with:
4648
submodules: recursive
4749

4850
- name: Pull submodules
51+
id: pull-submodules
4952
run: |
5053
git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*"
5154
git fetch --recurse-submodules
5255
53-
- name: Update inputs
56+
- name: Update workflow inputs
57+
id: update-workflow-inputs
5458
run: |
55-
echo "BRANCH_NAME=${{github.event.inputs.env_name}}" >> $GITHUB_ENV
5659
echo "workaround until actions/runner#655 is fixed"
60+
echo "DEPLOYMENT_NAME=${{github.event.inputs.deployment_name}}" >> $GITHUB_ENV
5761
echo "INPUT_CARTRIDGE=${{github.event.inputs.cartridge}}" >> $GITHUB_ENV
5862
echo "INPUT_CARTRIDGE_CLI=${{github.event.inputs.cartridge_cli}}" >> $GITHUB_ENV
5963
echo "INPUT_GRAFANA=${{github.event.inputs.grafana}}" >> $GITHUB_ENV
@@ -63,27 +67,50 @@ jobs:
6367
echo "INPUT_CPP_DRIVER=${{github.event.inputs.cpp_driver}}" >> $GITHUB_ENV
6468
6569
- name: Start dev server deployment
66-
uses: bobheadxi/deployments@v0.5.2
70+
uses: bobheadxi/deployments@v1
6771
id: deployment
6872
with:
6973
step: start
7074
token: ${{secrets.GITHUB_TOKEN}}
71-
env: ${{env.BRANCH_NAME}}
75+
env: ${{env.DEPLOYMENT_NAME}}
7276
ref: ${{github.head_ref}}
7377

7478
- run: cmake .
79+
id: cmake
7580
- run: make pull-modules
81+
id: make-pull-modules
7682
- run: make build-modules
83+
id: make-build-modules
7784
- run: make json
85+
id: make-json
7886
- run: make json-ru
87+
id: make-json-ru
88+
7989
- run: curl ${{secrets.WAKEUP_URL}} --connect-timeout 300 --retry 3 --retry-delay 30 >> /dev/null
90+
id: wake-up-server
91+
8092
- run: bash upload_output.sh
93+
id: upload-output
94+
- run: bash webhooks/update_deployment.sh
95+
id: update-deployment-webhook
8196

8297
- name: update deployment status
83-
uses: bobheadxi/[email protected]
98+
id: finalize-deployment
99+
uses: bobheadxi/deployments@v1
84100
with:
85101
step: finish
86102
token: ${{secrets.GITHUB_TOKEN}}
103+
env: ${{env.DEPLOYMENT_NAME}}
87104
status: ${{job.status}}
88105
deployment_id: ${{steps.deployment.outputs.deployment_id}}
89-
env_url: ${{secrets.TARANTOOL_HOST}}/doc/${{env.BRANCH_NAME}}
106+
env_url: ${{secrets.TARANTOOL_HOST}}/doc/${{env.DEPLOYMENT_NAME}}
107+
108+
- name: Send VK Teams message on failures
109+
# bot token won't be accessible in the forks
110+
if: ${{ failure() && env.VKTEAMS_BOT_TOKEN != '' }}
111+
uses: tarantool/actions/report-job-status@master
112+
with:
113+
api-url: "https://api.internal.myteam.mail.ru/bot/v1/"
114+
bot-token: ${{ env.VKTEAMS_BOT_TOKEN }}
115+
chat-id: tt_docs_cicd_reports
116+
job-steps: ${{ ToJson(steps) }}

Diff for: .github/workflows/destroy-deployment-manually.yml

+25-3
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,40 @@ on:
99
jobs:
1010
destroy-deployment-manually:
1111
runs-on: ubuntu-latest
12+
env:
13+
# we only remove deployments from the test site, never from prod
14+
TARANTOOL_UPDATE_URL: ${{secrets.TARANTOOL_DEVELOP_UPDATE_URL}}
15+
TARANTOOL_UPDATE_KEY: ${{secrets.TARANTOOL_UPDATE_KEY}}
16+
VKTEAMS_BOT_TOKEN: ${{secrets.VKTEAMS_TARANTOOLBOT_TOKEN}}
1217
steps:
18+
- uses: actions/checkout@v2
19+
id: checkout
20+
with:
21+
token: "${{ secrets.GITHUB_TOKEN }}"
22+
1323
- name: Update inputs
24+
id: update-inputs
1425
run: |
1526
echo "DEPLOYMENT_NAME=${{github.event.inputs.deployment_name}}" >> $GITHUB_ENV
1627
echo "workaround until actions/runner#655 is fixed"
1728
1829
- name: Remove dev server deployment at ${{env.DEPLOYMENT_NAME}}
30+
id: delete-deployment-webhook
31+
run: bash webhooks/delete_deployment.sh
32+
33+
- name: Remove GitHub deployment at ${{env.DEPLOYMENT_NAME}}
1934
uses: strumwolf/delete-deployment-environment@v2
35+
id: remove-github-deployment
2036
with:
2137
token: "${{ secrets.TARANTOOLBOT_TOKEN }}"
2238
environment: ${{ env.DEPLOYMENT_NAME }}
23-
# onlyRemoveDeployments: true
2439

25-
- run: |
26-
curl -X DELETE -d '{"update_key":"${{secrets.TARANTOOL_UPDATE_KEY}}"}' -H "Content-Type: application/json" ${{secrets.TARANTOOL_DEVELOP_UPDATE_URL}}${{env.DEPLOYMENT_NAME}}/
40+
- name: Send VK Teams message on failures
41+
# bot token won't be accessible in the forks
42+
if: ${{ failure() && env.VKTEAMS_BOT_TOKEN != '' }}
43+
uses: tarantool/actions/report-job-status@master
44+
with:
45+
api-url: "https://api.internal.myteam.mail.ru/bot/v1/"
46+
bot-token: ${{ env.VKTEAMS_BOT_TOKEN }}
47+
chat-id: tt_docs_cicd_reports
48+
job-steps: ${{ ToJson(steps) }}

Diff for: .github/workflows/destroy-deployment.yml

+30-15
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,50 @@
11
name: Destroy-deployments
22

3+
# When a pull request is merged or just closed, remove deployed docs from the dev server
4+
# and remove the GitHub deployment with the same name.
5+
36
on:
47
pull_request:
58
types:
69
- closed
710
jobs:
811
destroy-deployment:
912
runs-on: ubuntu-latest
13+
env:
14+
# we only remove deployments from the test site, never from prod
15+
TARANTOOL_UPDATE_URL: ${{secrets.TARANTOOL_DEVELOP_UPDATE_URL}}
16+
TARANTOOL_UPDATE_KEY: ${{secrets.TARANTOOL_UPDATE_KEY}}
17+
VKTEAMS_BOT_TOKEN: ${{secrets.VKTEAMS_TARANTOOLBOT_TOKEN}}
1018
steps:
1119
- uses: actions/checkout@v2
20+
id: checkout
1221
with:
1322
token: "${{ secrets.GITHUB_TOKEN }}"
1423

15-
- name: Set branch name from source branch
16-
run: echo "BRANCH_NAME=${GITHUB_HEAD_REF##*/}" >> $GITHUB_ENV
24+
- name: Set deployment name from source branch
25+
id: set-deployment-name
26+
run: echo "DEPLOYMENT_NAME=${GITHUB_HEAD_REF##*/}" >> $GITHUB_ENV
1727

18-
- run: |
19-
curl -X DELETE -d '{"update_key":"${{secrets.TARANTOOL_UPDATE_KEY}}"}' -H "Content-Type: application/json" ${{secrets.TARANTOOL_DEVELOP_UPDATE_URL}}${{env.BRANCH_NAME}}/
28+
- name: Remove dev server deployment at branch-${{env.DEPLOYMENT_NAME}}
29+
id: delete-deployment-webhook
30+
run: bash webhooks/delete_deployment.sh
2031

21-
- name: Remove dev server deployment at branch-${{env.BRANCH_NAME}}
22-
uses: bobheadxi/[email protected]
23-
id: deployment
32+
- name: Remove GitHub deployment at branch-${{env.DEPLOYMENT_NAME}}
33+
uses: bobheadxi/deployments@v1
34+
# remove GH deployment even if webhook failed
35+
if: always()
36+
id: remove-github-deployment
2437
with:
25-
step: deactivate-env
38+
step: delete-env
2639
token: ${{secrets.GITHUB_TOKEN}}
27-
env: "branch-${{env.BRANCH_NAME}}"
40+
env: "branch-${{env.DEPLOYMENT_NAME}}"
2841

29-
- name: Remove translation deployment at translate-${{env.BRANCH_NAME}}
30-
uses: bobheadxi/[email protected]
31-
id: translation
42+
- name: Send VK Teams message on failures
43+
# bot token won't be accessible in the forks
44+
if: ${{ failure() && env.VKTEAMS_BOT_TOKEN != '' }}
45+
uses: tarantool/actions/report-job-status@master
3246
with:
33-
step: deactivate-env
34-
token: ${{secrets.GITHUB_TOKEN}}
35-
env: "translation-${{env.BRANCH_NAME}}"
47+
api-url: "https://api.internal.myteam.mail.ru/bot/v1/"
48+
bot-token: ${{ env.VKTEAMS_BOT_TOKEN }}
49+
chat-id: tt_docs_cicd_reports
50+
job-steps: ${{ ToJson(steps) }}

Diff for: .github/workflows/main.yml

+26-12
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Deploy
1+
name: Deploy to prod
22

33
on:
44
workflow_dispatch:
@@ -19,29 +19,43 @@ jobs:
1919
S3_UPLOAD_PATH: ${{secrets.S3_UPLOAD_PATH}}
2020
TARANTOOL_UPDATE_KEY: ${{secrets.TARANTOOL_UPDATE_KEY}}
2121
TARANTOOL_UPDATE_URL: ${{secrets.TARANTOOL_UPDATE_URL}}
22+
DEPLOYMENT_NAME: latest
2223
steps:
2324
- uses: actions/checkout@v2
25+
id: checkout
2426
with:
2527
submodules: recursive
2628

2729
- name: Fetch submodules
30+
id: fetch-submodules
2831
run: git fetch --recurse-submodules
2932

3033
- run: cmake .
34+
id: cmake
3135
- run: make pull-modules
36+
id: make-pull-modules
3237
- run: make build-modules
38+
id: make-build-modules
3339
- run: make json
40+
id: make-json
3441
- run: make json-ru
42+
id: make-json-ru
3543
- run: make pdf
44+
id: make-pdf
3645
- run: make pdf-ru
37-
- uses: nelonoel/[email protected]
38-
- if:
39-
contains('
40-
refs/heads/latest
41-
refs/heads/2.5
42-
refs/heads/2.4
43-
refs/heads/2.3
44-
refs/heads/2.2
45-
refs/heads/1.10
46-
', github.ref)
47-
run: bash upload_output.sh
46+
id: make-pdf-ru
47+
48+
- run: bash upload_output.sh
49+
id: upload-output
50+
- run: bash webhooks/update_deployment.sh
51+
id: update-deployment-webhook
52+
53+
- name: Send VK Teams message on failures
54+
# bot token won't be accessible in the forks
55+
if: ${{ failure() && env.VKTEAMS_BOT_TOKEN != '' }}
56+
uses: tarantool/actions/report-job-status@master
57+
with:
58+
api-url: "https://api.internal.myteam.mail.ru/bot/v1/"
59+
bot-token: ${{ env.VKTEAMS_BOT_TOKEN }}
60+
chat-id: tt_docs_cicd_reports
61+
job-steps: ${{ ToJson(steps) }}

Diff for: .gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ rocks
1919
# Crowdin API key
2020
apikey.txt
2121

22+
# secrets for running webhooks locally
23+
webhooks/.env
24+
2225
# README copied to contributor docs
2326
/doc/contributing/docs/_includes/README.rst
2427

Diff for: upload_output.sh

+3-6
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22

33
set -xe -o pipefail -o nounset
44

5-
BRANCH=$BRANCH_NAME
5+
BRANCH=$DEPLOYMENT_NAME
66
ENDPOINT_URL=$S3_ENDPOINT_URL
77
S3_PATH=$S3_UPLOAD_PATH
88

9+
echo "Upload produced documentation outputs to the S3 storage, tarantool/${BRANCH}"
10+
911
# don't upload the '*.pickle' files
1012
find output -name '*.pickle' -delete
1113

@@ -33,8 +35,3 @@ aws s3 sync --acl public-read output/html/ru/_static $S3_PATH/$BRANCH/ru/_static
3335
aws s3 sync --acl public-read output/html/ru/_images $S3_PATH/$BRANCH/ru/_images --endpoint-url=$ENDPOINT_URL --delete --size-only
3436
aws s3 cp --acl public-read output/html/ru/singlehtml.html $S3_PATH/$BRANCH/ru/singlehtml.html --endpoint-url=$ENDPOINT_URL
3537
fi
36-
37-
curl --fail --show-error \
38-
--data '{"update_key":"'"$TARANTOOL_UPDATE_KEY"'"}' \
39-
--header "Content-Type: application/json" \
40-
--request POST "$TARANTOOL_UPDATE_URL""$BRANCH"/

Diff for: webhooks/.env-example

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
TARANTOOL_UPDATE_URL=
2+
TARANTOOL_UPDATE_KEY=
3+
DEPLOYMENT_NAME=

Diff for: webhooks/delete_deployment.sh

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/bin/env bash
2+
3+
set -xe -o pipefail -o nounset
4+
5+
echo "Remove doc deployment ${DEPLOYMENT_NAME} from the server"
6+
7+
# testing this locally:
8+
# source .env && export $(cut -d= -f1 .env) && ./delete_deployment.sh
9+
10+
curl --fail --show-error -v \
11+
--data '{"update_key":"'"${TARANTOOL_UPDATE_KEY}"'"}' \
12+
--header "Content-Type: application/json" \
13+
--request DELETE "${TARANTOOL_UPDATE_URL}""${DEPLOYMENT_NAME}"/
14+

0 commit comments

Comments
 (0)