-
-
Notifications
You must be signed in to change notification settings - Fork 97
222 lines (185 loc) · 6.78 KB
/
github-actions.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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
name: GitHub Actions
on:
push:
branches:
- master
pull_request:
concurrency:
group: ${{ github.workflow }}-${{ github.event.number || github.ref }}
cancel-in-progress: true
jobs:
test:
name: Test
runs-on: ubuntu-latest
steps:
- name: Checkout 🛎️
uses: actions/checkout@v4
- name: Setup Python 🐍
id: setup-python
uses: actions/setup-python@v5
with:
python-version-file: ".python-version"
- name: Install Poetry 📦
uses: snok/install-poetry@v1.4.1
with:
virtualenvs-create: true
virtualenvs-in-project: true
- name: Cache virtual environment 💾
uses: actions/cache@v4
with:
path: .venv
key: ${{ runner.os }}-venv-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}
restore-keys: |
${{ runner.os }}-venv-${{ steps.setup-python.outputs.python-version }}-
- name: Install dependencies ⚙️
run: poetry install --no-interaction
- name: Run Tests 🧪
run: |
source .venv/bin/activate
pybabel compile -D pdf_bot -d locale
pytest --cov --cov-report=xml
- name: Upload coverage report 📡
uses: codecov/codecov-action@v5.0.2
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- name: Checkout 🛎️
uses: actions/checkout@v4
- name: Setup Python 🐍
id: setup-python
uses: actions/setup-python@v5
with:
python-version-file: ".python-version"
- name: Install Poetry 📦
uses: snok/install-poetry@v1.4.1
with:
virtualenvs-create: true
virtualenvs-in-project: true
- name: Cache virtual environment 💾
uses: actions/cache@v4
with:
path: .venv
key: ${{ runner.os }}-venv-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}
restore-keys: |
${{ runner.os }}-venv-${{ steps.setup-python.outputs.python-version }}-
- name: Install dependencies ⚙️
run: poetry install --no-interaction --no-root
- name: Run linting 🧪
run: |
source .venv/bin/activate
pre-commit run --all-files
check-docker-image:
name: Check Docker image
runs-on: ubuntu-latest
if: ${{ github.ref != 'refs/heads/master' }}
steps:
- name: Checkout 🛎️
uses: actions/checkout@v4
- name: Build Docker image 🏗
run: |-
docker build .
check-pyenv:
name: Check pyenv
runs-on: ubuntu-latest
if: ${{ github.ref != 'refs/heads/master' }}
steps:
- name: Checkout 🛎️
uses: actions/checkout@v4
- name: Check Python version in pyenv 🐍
run: |
curl https://pyenv.run | bash
export PYENV_ROOT="$HOME/.pyenv"
command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"
pyenv install
build-deploy:
name: Build and deploy
runs-on: ubuntu-latest
needs: [test, lint]
if: ${{ github.ref == 'refs/heads/master' }}
environment:
name: Production
env:
DOCKER_IMAGE: registry.digitalocean.com/${{ secrets.DIGITALOCEAN_REGISTRY }}/${{ secrets.DIGITALOCEAN_APP_NAME }}:${{ github.sha }}
steps:
- name: Create GitHub App token 🔑
id: app-token
uses: actions/create-github-app-token@v1
with:
app-id: ${{ secrets.GH_APP_ID }}
private-key: ${{ secrets.GH_APP_PRIVATE_KEY }}
- name: Checkout 🛎️
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: master
token: ${{ steps.app-token.outputs.token }}
- name: Setup Python 🐍
id: setup-python
uses: actions/setup-python@v5
with:
python-version-file: ".python-version"
- name: Install Poetry 📦
uses: snok/install-poetry@v1.4.1
with:
virtualenvs-create: true
virtualenvs-in-project: true
- name: Cache virtual environment 💾
uses: actions/cache@v4
with:
path: .venv
key: ${{ runner.os }}-venv-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}
restore-keys: |
${{ runner.os }}-venv-${{ steps.setup-python.outputs.python-version }}-
- name: Install dependencies ⚙️
run: poetry install --no-interaction --no-root
- name: Update localization source file 📄
id: update-i18n-source
run: |
source .venv/bin/activate
pybabel extract pdf_bot/ -o locale/pdf_bot.pot
pybabel update -l locale -i locale/pdf_bot.pot -o locale/en_GB/LC_MESSAGES/pdf_bot.po
echo "NUM_DIFFS=$(git diff --shortstat | egrep -o '[0-9]+ i' | egrep -o '[0-9]+')" >> "$GITHUB_OUTPUT"
- name: Commit changes 🆕
if: ${{ steps.update-i18n-source.outputs.NUM_DIFFS > 1 }}
uses: stefanzweifel/git-auto-commit-action@v5.0.1
with:
commit_message: "ci: update localization source file [skip ci]"
file_pattern: locale/en_GB/LC_MESSAGES/pdf_bot.po
- name: Upload sources and download translations 🌐
if: ${{ steps.update-i18n-source.outputs.NUM_DIFFS > 1 }}
uses: crowdin/github-action@v2.3.0
with:
upload_sources: true
upload_translations: false
download_translations: true
commit_message: "fix: update translations with latest changes [skip ci]"
create_pull_request: false
localization_branch_name: master
config: ./crowdin.yml
source: locale/en_GB/LC_MESSAGES/pdf_bot.po
translation: /locale/%locale_with_underscore%/LC_MESSAGES/pdf_bot.po
env:
GITHUB_TOKEN: ${{ steps.app-token.outputs.token }}
CROWDIN_PROJECT_ID: ${{ secrets.CROWDIN_PROJECT_ID }}
CROWDIN_PERSONAL_TOKEN: ${{ secrets.CROWDIN_PERSONAL_TOKEN }}
- name: Install doctl 🌊
uses: digitalocean/action-doctl@v2.5.1
with:
token: ${{ secrets.DIGITALOCEAN_TOKEN }}
- name: Authenticate to DigitalOcean 🔐
run: doctl registry login --expiry-seconds 600
- name: Build and push image 🏗
run: |-
docker build -t ${{ env.DOCKER_IMAGE }} --build-arg COMMIT_HASH=${{ github.sha }} .
docker push ${{ env.DOCKER_IMAGE }}
- name: Deploy 🚀
uses: digitalocean/app_action/deploy@v2.0.6
env:
IMAGE_TAG_TELEGRAM_PDF_BOT: ${{ github.sha }}
with:
token: ${{ secrets.DIGITALOCEAN_TOKEN }}
app_name: ${{ secrets.DIGITALOCEAN_APP_NAME }}