-
Notifications
You must be signed in to change notification settings - Fork 2
187 lines (167 loc) · 7.75 KB
/
publish_dev.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
name: Docker testing
on:
push:
# Publish `dev` as Docker `testing` image.
branches:
- dev
env:
IMAGE_NAME: sysblokbot
jobs:
# Run tests.
# See also https://docs.docker.com/docker-hub/builds/automated-testing/
test:
runs-on: ubuntu-latest
steps:
- name: Cancel Previous Runs
uses: styfle/cancel-workflow-action@0.9.1
with:
access_token: ${{ github.token }}
- uses: actions/checkout@v2
with:
ref: dev
- name: Python Style Checker
working-directory: ${{ github.workspace }}
run: |
pip3 install --upgrade pip
export PATH="$HOME/.local/bin:$PATH"
pip3 install pycodestyle
pycodestyle . --max-line-length 100
- name: Notify us about failure
if: ${{ failure() }}
env:
TELEGRAM_TEST_TOKEN: ${{ secrets.TELEGRAM_TEST_TOKEN }}
TELEGRAM_ERROR_CHAT_ID: ${{ secrets.TELEGRAM_ERROR_CHAT_ID }}
run: |
curl -X POST \
-H 'Content-Type: application/json' \
-d '{"parse_mode": "markdown", "chat_id": "${{ env.TELEGRAM_ERROR_CHAT_ID }}", "text": "[github CI] pycodestyle [failed](https://github.com/sysblok/sysblokbot/actions/runs/${{github.run_id}})" \
}' \
https://api.telegram.org/bot${{env.TELEGRAM_TEST_TOKEN}}/sendMessage
# - name: Python Pytest Github Action
# uses: fylein/python-pytest-github-action@v2
# with:
# args: apt-get update && apt-get install -y git && pip3 install -e . && pip3 install -r requirements.txt && pytest tests/unit
- name: Notify us about failure
if: ${{ failure() }}
env:
TELEGRAM_TEST_TOKEN: ${{ secrets.TELEGRAM_TEST_TOKEN }}
TELEGRAM_ERROR_CHAT_ID: ${{ secrets.TELEGRAM_ERROR_CHAT_ID }}
run: |
curl -X POST \
-H 'Content-Type: application/json' \
-d '{"parse_mode": "markdown", "chat_id": "${{ env.TELEGRAM_ERROR_CHAT_ID }}", "text": "[github CI] unit tests [failed](https://github.com/sysblok/sysblokbot/actions/runs/${{github.run_id}})" \
}' \
https://api.telegram.org/bot${{env.TELEGRAM_TEST_TOKEN}}/sendMessage
# Push image to GitHub Packages.
# See also https://docs.docker.com/docker-hub/builds/
push:
# Ensure test job passes before pushing image.
needs: test
environment: testing
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
ref: dev
- name: Generate build args
id: args
run: |
echo "::set-output name=commit_hash::$(git rev-parse HEAD)"
echo "::set-output name=commit_hash_short::$(git rev-parse --short HEAD)"
- name: Publish to Github Packages Registry with cache
uses: whoan/docker-build-with-cache-action@v5
env:
IMAGE_NAME: ${{ env.IMAGE_NAME }}
COMMIT_HASH: "${{ steps.args.outputs.commit_hash }}"
COMMIT_HASH_SHORT: "${{ steps.args.outputs.commit_hash_short }}"
with:
image_name: ${{ github.repository }}/${{ env.IMAGE_NAME }}
registry: docker.pkg.github.com
username: sysblok
password: ${{ secrets.GITHUB_TOKEN }}
dockerfile: Dockerfile
image_tag: testing
build_extra_args: "--build-arg=COMMIT_HASH --build-arg=COMMIT_HASH_SHORT"
- name: Notify us about failure
if: ${{ failure() }}
env:
TELEGRAM_TEST_TOKEN: ${{ secrets.TELEGRAM_TEST_TOKEN }}
TELEGRAM_ERROR_CHAT_ID: ${{ secrets.TELEGRAM_ERROR_CHAT_ID }}
run: |
curl -X POST \
-H 'Content-Type: application/json' \
-d '{"parse_mode": "markdown", "chat_id": "${{ env.TELEGRAM_ERROR_CHAT_ID }}", "text": "[github CI] build [failed](https://github.com/sysblok/sysblokbot/actions/runs/${{github.run_id}})" \
}' \
https://api.telegram.org/bot${{env.TELEGRAM_TEST_TOKEN}}/sendMessage
- name: Deploy package to digitalocean
uses: appleboy/ssh-action@master
env:
GITHUB_USERNAME: sysblok
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
IMAGE_NAME: ${{ env.IMAGE_NAME }}
ROOT_DIR: /home/${{ secrets.MASTER_DO_USER }}/testing
TELEGRAM_TEST_TOKEN: ${{ secrets.TELEGRAM_TEST_TOKEN }}
TELEGRAM_ERROR_CHAT_ID: ${{ secrets.TELEGRAM_ERROR_CHAT_ID }}
UPTRACE_DSN: ${{ secrets.UPTRACE_DSN }}
CONFIG: ${{ secrets.CONFIG }}
CONFIG_GS: ${{ secrets.CONFIG_GS }}
with:
host: ${{ secrets.MASTER_HOST }}
username: ${{ secrets.MASTER_DO_USER }}
passphrase: ${{ secrets.MASTER_DO_SSH_KEY_PASSWORD }}
key: ${{ secrets.MASTER_DO_SSH_KEY }}
port: ${{ secrets.MASTER_PORT }}
envs: GITHUB_USERNAME, GITHUB_TOKEN, IMAGE_NAME, ROOT_DIR, TELEGRAM_TEST_TOKEN, TELEGRAM_ERROR_CHAT_ID, UPTRACE_DSN, CONFIG, CONFIG_GS
script: |
export CONTAINER_ID=$(docker ps -aq --filter name=testing)
export IMAGE_ID=$(docker images -aq --filter reference='docker.pkg.github.com/sysblok/sysblokbot/sysblokbot:testing')
docker stop --time=30 $CONTAINER_ID
docker rm $CONTAINER_ID
docker rmi $IMAGE_ID
docker login docker.pkg.github.com -u $GITHUB_USERNAME -p $GITHUB_TOKEN
touch ${{ env.ROOT_DIR }}/sysblokbot.sqlite
touch ${{ env.ROOT_DIR }}/strings.sqlite
touch ${{ env.ROOT_DIR }}/board_credentials.json
touch ${{ env.ROOT_DIR }}/config_override.json
touch ${{ env.ROOT_DIR }}/config_gs.json
echo '${{ env.CONFIG }}' > ${{ env.ROOT_DIR }}/config_override.json
echo '${{ env.CONFIG_GS }}' > ${{ env.ROOT_DIR }}/config_gs.json
docker run -dit --name sysblokbot-testing \
--env APP_SOURCE="testing" --restart unless-stopped \
--env TELEGRAM_ERROR_CHAT_ID="${{ env.TELEGRAM_ERROR_CHAT_ID }}" \
--env UPTRACE_DSN="${{ env.UPTRACE_DSN }}" \
--env TELEGRAM_TOKEN="${{ env.TELEGRAM_TEST_TOKEN }}" \
-v ${{ env.ROOT_DIR }}/config_override.json:/app/config_override.json \
-v ${{ env.ROOT_DIR }}/config_gs.json:/app/config_gs.json \
-v ${{ env.ROOT_DIR }}/sysblokbot.sqlite:/app/sysblokbot.sqlite \
-v ${{ env.ROOT_DIR }}/strings.sqlite:/app/strings.sqlite \
-v ${{ env.ROOT_DIR }}/persistent_storage.pickle:/app/persistent_storage.pickle \
-v ${{ env.ROOT_DIR }}/board_credentials.json:/app/board_credentials.json \
docker.pkg.github.com/sysblok/sysblokbot/${{ env.IMAGE_NAME }}:testing
- name: Notify us about failure
if: ${{ failure() }}
env:
TELEGRAM_TEST_TOKEN: ${{ secrets.TELEGRAM_TEST_TOKEN }}
TELEGRAM_ERROR_CHAT_ID: ${{ secrets.TELEGRAM_ERROR_CHAT_ID }}
run: |
curl -X POST \
-H 'Content-Type: application/json' \
-d '{"parse_mode": "markdown", "chat_id": "${{ env.TELEGRAM_ERROR_CHAT_ID }}", "text": "[github CI] deploy [failed](https://github.com/sysblok/sysblokbot/actions/runs/${{github.run_id}})" \
}' \
https://api.telegram.org/bot${{env.TELEGRAM_TEST_TOKEN}}/sendMessage
# integration_tests:
# needs: push
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v2
# with:
# ref: dev
# - name: Integration tests
# uses: fylein/python-pytest-github-action@v2
# env:
# CONFIG_OVERRIDE: ${{ secrets.CONFIG_OVERRIDE_TESTING }}
# with:
# args: |
# apt-get update && apt-get install -y git && \
# pip3 install -e . && pip3 install -r requirements.txt && \
# pytest tests/integration -vs