forked from zeshuaro/telegram-pdf-bot
-
Notifications
You must be signed in to change notification settings - Fork 1
260 lines (219 loc) · 8.03 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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
name: GitHub Actions
on:
push:
branches:
- master
pull_request:
jobs:
test:
name: Test
runs-on: ubuntu-latest
steps:
- name: Checkout 🛎️
uses: actions/checkout@v3
- name: Setup Python 🐍
id: setup-python
uses: actions/setup-python@v4
with:
python-version-file: ".python-version"
- name: Install Poetry 📦
uses: snok/install-poetry@v1.3.3
with:
virtualenvs-create: true
virtualenvs-in-project: true
- name: Cache virtual environment 💾
uses: actions/cache@v3
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: Run SonarCloud scan ☁️
uses: sonarsource/sonarcloud-github-action@v1.8
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- name: Checkout 🛎️
uses: actions/checkout@v3
- name: Setup Python 🐍
id: setup-python
uses: actions/setup-python@v4
with:
python-version-file: ".python-version"
- name: Install Poetry 📦
uses: snok/install-poetry@v1.3.3
with:
virtualenvs-create: true
virtualenvs-in-project: true
- name: Cache virtual environment 💾
uses: actions/cache@v3
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
snyk-scan:
name: Snyk scan
runs-on: ubuntu-latest
steps:
- name: Checkout 🛎️
uses: actions/checkout@v3
- name: Setup Snyk 🐕
uses: snyk/actions/setup@master
- name: Setup Python 🐍
id: setup-python
uses: actions/setup-python@v4
with:
python-version-file: ".python-version"
- name: Install Poetry 📦
uses: snok/install-poetry@v1.3.3
with:
virtualenvs-create: true
virtualenvs-in-project: true
- name: Cache virtual environment 💾
uses: actions/cache@v3
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-root --no-interaction
- name: Run Snyk scan 🛡️
continue-on-error: true # To make sure that SARIF upload gets called
env:
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
run: snyk test --sarif-file-output=snyk.sarif
- name: Upload Snyk results 📡
uses: github/codeql-action/upload-sarif@v2
with:
sarif_file: snyk.sarif
- name: Run Snyk monitor 🖥️
if: ${{ github.ref == 'refs/heads/master' }}
env:
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
run: snyk monitor
git-guardian-scan:
name: GitGuardian scan
runs-on: ubuntu-latest
steps:
- name: Checkout 🛎️
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Run GitGuardian scan 🤐
uses: GitGuardian/ggshield-action@master
env:
GITHUB_PUSH_BEFORE_SHA: ${{ github.event.before }}
GITHUB_PUSH_BASE_SHA: ${{ github.event.base }}
GITHUB_PULL_BASE_SHA: ${{ github.event.pull_request.base.sha }}
GITHUB_DEFAULT_BRANCH: ${{ github.event.repository.default_branch }}
GITGUARDIAN_API_KEY: ${{ secrets.GITGUARDIAN_API_KEY }}
build-deploy:
name: Build and deploy
runs-on: ubuntu-latest
needs: [test, lint, snyk-scan, git-guardian-scan]
if: ${{ github.ref == 'refs/heads/master' }}
concurrency: production
environment:
name: Production
env:
DOCKER_IMAGE: registry.digitalocean.com/${{ secrets.DIGITALOCEAN_REGISTRY }}/${{ secrets.DIGITALOCEAN_APP_NAME }}:${{ github.sha }}
steps:
- name: Checkout 🛎️
uses: actions/checkout@v3
with:
fetch-depth: 0
ref: master
token: ${{ secrets.PAT }}
- name: Setup Python 🐍
id: setup-python
uses: actions/setup-python@v4
with:
python-version-file: ".python-version"
- name: Install Poetry 📦
uses: snok/install-poetry@v1.3.3
with:
virtualenvs-create: true
virtualenvs-in-project: true
- name: Cache virtual environment 💾
uses: actions/cache@v3
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 📄
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_ENV
- name: Commit changes 🆕
if: env.NUM_DIFFS > 1
uses: stefanzweifel/git-auto-commit-action@v4.16.0
with:
commit_message: "ci: update localization source file [skip ci]"
file_pattern: locale/en_GB/LC_MESSAGES/pdf_bot.po
push_options: --force
- name: Upload sources and download translations 🌐
if: env.NUM_DIFFS > 1
uses: crowdin/github-action@v1.6.0
with:
upload_sources: true
upload_translations: false
download_translations: true
commit_message: "feat: 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: ${{ secrets.PAT }}
CROWDIN_PROJECT_ID: ${{ secrets.CROWDIN_PROJECT_ID }}
CROWDIN_PERSONAL_TOKEN: ${{ secrets.CROWDIN_PERSONAL_TOKEN }}
- name: Install doctl 🌊
uses: digitalocean/action-doctl@v2.3.0
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@v1.1.4
with:
app_name: ${{ secrets.DIGITALOCEAN_APP_NAME }}
token: ${{ secrets.DIGITALOCEAN_TOKEN }}
images: '[
{
"name": "${{ secrets.DIGITALOCEAN_APP_NAME }}",
"image": {
"registry_type": "DOCR",
"repository": "${{ secrets.DIGITALOCEAN_APP_NAME }}",
"tag": "${{ github.sha }}"
}
}
]'