-
-
Notifications
You must be signed in to change notification settings - Fork 97
204 lines (172 loc) · 6.18 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
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.9
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
check-docker-image:
name: Check Docker image
runs-on: ubuntu-latest
if: ${{ github.ref != 'refs/heads/master' }}
steps:
- name: Checkout 🛎️
uses: actions/checkout@v3
- name: Build Docker image 🏗
run: |-
docker build .
build-deploy:
name: Build and deploy
runs-on: ubuntu-latest
needs: [test, lint]
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.12.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.5
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 }}"
}
}
]'