-
Notifications
You must be signed in to change notification settings - Fork 0
297 lines (249 loc) · 10.2 KB
/
compile.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
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
name: Python CI
on:
push:
branches:
- "*"
paths:
- "src/**/*.py"
- "requirements.txt"
- "Dockerfile"
- ".github/workflows/compile.yml"
pull_request:
branches:
- "*"
paths:
- "src/**/*.py"
- "requirements.txt"
- "Dockerfile"
- ".github/workflows/compile.yml"
env:
SRC: "./src/pyramid"
TEST: "./src/pyramid-test"
TEST_FILES: "*_test.py"
jobs:
compile:
name: "Compile Python 3.11"
runs-on: ubuntu-latest
outputs:
json: ${{ steps.version.outputs.json }}
version: ${{ steps.version.outputs.version }}
commit_id: ${{ steps.version.outputs.commit_id }}
last_author: ${{ steps.version.outputs.last_author }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Python 3.11
uses: actions/setup-python@v4
with:
python-version: "3.11"
- name: Cache dependencies
uses: actions/cache@v3
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip
- name: Install dependencies
run: |
python -m pip install --upgrade pip
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Test compilation
run: |
python -m compileall ${{ env.SRC }}
- name: Save version
run: |
FULL_JSON=$(python ${{ env.SRC }} --version)
echo "json=$(echo $FULL_JSON | jq -c)" >> $GITHUB_OUTPUT
echo "version=$(echo $FULL_JSON | jq -r '.version')" >> $GITHUB_OUTPUT
echo "commit_id=$(echo $FULL_JSON | jq -r '.git_info.commit_id')" >> $GITHUB_OUTPUT
echo "last_author=$(echo $FULL_JSON | jq -r '.git_info.last_author')" >> $GITHUB_OUTPUT
id: version
unit_test:
name: "Unit tests Python"
needs: compile
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
clean: false
- name: Set up Python 3.11
uses: actions/setup-python@v4
with:
python-version: "3.11"
- name: Cache dependencies
uses: actions/cache@v3
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip
- name: Install dependencies
run: |
python -m pip install --upgrade pip
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Units tests
run: |
python -m unittest discover -v -s ${{ env.TEST }} -p ${{ env.TEST_FILES }}
version_compatibility:
name: "Compile Python"
needs: compile
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.12"]
continue-on-error: true
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: "${{ matrix.python-version }}"
- name: Cache dependencies
uses: actions/cache@v3
with:
path: ~/.cache/pip
key: ${{ runner.os }}-python_${{ matrix.python-version }}-pip-${{ hashFiles('**/requirements.txt') }}-${{ matrix.python-version }}
restore-keys: |
${{ runner.os }}-python_${{ matrix.python-version }}-pip
- name: Install dependencies
run: |
python -m pip install --upgrade pip
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Test compilation
run: |
python -m compileall ${{ env.SRC }}
publish_release:
name: "Publish release"
needs: ["compile", "unit_test"]
runs-on: ubuntu-latest
outputs:
docker_tag: ${{ steps.docker_tag.outputs.tag }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 100
- name: Set Docker Image Tag
id: docker_tag
run: |
if [ ${{ github.ref }} = 'refs/heads/main' ]; then
echo "tag=latest" >> $GITHUB_OUTPUT
elif [ ${{ github.ref }} = 'refs/heads/pre-prod' ]; then
echo "tag=pre-prod" >> $GITHUB_OUTPUT
echo "tag_github=unstable" >> $GITHUB_OUTPUT
else
echo "tag=dev" >> $GITHUB_OUTPUT
fi
- name: Get commit messages
id: get_commit_messages
run: |
COMMIT_MESSAGES=$(git log --pretty=format:"* %s" ${{ github.event.before }}..${{ github.sha }})
echo "commit_messages=$COMMIT_MESSAGES" >> $GITHUB_OUTPUT
- name: Get last release tag
if: steps.docker_tag.outputs.tag == 'latest'
id: get_last_release
run: |
RESPONSE=$(curl -s "https://api.github.com/repos/${{ github.repository }}/releases/latest")
if [[ $(echo "$RESPONSE" | jq -r .message) == "Not Found" ]]; then
LAST_RELEASE_TAG=$(git rev-list --max-parents=0 HEAD)
else
LAST_RELEASE_TAG=$(echo "$RESPONSE" | jq -r .tag_name)
fi
echo "last_release_tag=${LAST_RELEASE_TAG}" >> $GITHUB_OUTPUT
- name: Create stable Release
if: steps.docker_tag.outputs.tag == 'latest'
uses: actions/create-release@latest
env:
GITHUB_TOKEN: ${{ secrets.TOKEN_RELEASE }}
with:
tag_name: ${{ needs.compile.outputs.version }}-${{ needs.compile.outputs.commit_id }}
release_name: Stable Auto-Release v${{ needs.compile.outputs.version }}
body: |
This has been deployed on the Discord bot `PyRamid#6882`.
To use the latest version the bot, please refer to the instructions outlined at https://github.com/tristiisch/PyRamid/#usage.
## Changes
${{ steps.get_commit_messages.outputs.commit_messages }}
## Docker
This version is now accessible through various Docker images. Each image creation corresponds to a unique snapshot of this version, while updating the image corresponds to using an updated Docker image tag.
### Images creation
* ${{ secrets.DOCKERHUB_USERNAME }}/pyramid:${{ needs.compile.outputs.version }}-${{ needs.compile.outputs.commit_id }}
### Images update
* ${{ secrets.DOCKERHUB_USERNAME }}/pyramid:${{ steps.docker_tag.outputs.tag }}
* ${{ secrets.DOCKERHUB_USERNAME }}/pyramid:${{ needs.compile.outputs.version }}
draft: true
prerelease: false
- name: Get last pre-release tag
if: steps.docker_tag.outputs.tag != 'latest'
id: get_last_unstable_release
run: |
RESPONSE=$(curl -s "https://api.github.com/repos/${{ github.repository }}/releases")
if [[ $(echo "$RESPONSE" | jq -r .message) == "Not Found" ]]; then
LAST_RELEASE_TAG=${{ github.event.before }}
else
LAST_RELEASE_TAG=$(echo "$RESPONSE" | jq -r '.[0].tag_name')
fi
echo "last_release_tag=${LAST_RELEASE_TAG}" >> $GITHUB_OUTPUT
- name: Create unstable Release
if: steps.docker_tag.outputs.tag != 'latest'
uses: actions/create-release@latest
env:
GITHUB_TOKEN: ${{ secrets.TOKEN_RELEASE }}
with:
tag_name: ${{ steps.docker_tag.outputs.tag_github }}-${{ needs.compile.outputs.version }}-${{ needs.compile.outputs.commit_id }}
release_name: Unstable Auto-Release v${{ needs.compile.outputs.version }}-${{ needs.compile.outputs.commit_id }}
body: |
This has been deployed on the Discord bot `PyRamid PRÉ-PROD#6277`.
Feel free to put it to the test by joining the development server at https://discord.gg/pNrZp7U34d.
## Changes
${{ steps.get_commit_messages.outputs.commit_messages }}
## Docker
This version is now accessible through various Docker images. Each image creation corresponds to a unique snapshot of this version, while updating the image corresponds to using an updated Docker image tag.
### Images creation
* ${{ secrets.DOCKERHUB_USERNAME }}/pyramid:${{ needs.compile.outputs.version }}-${{ needs.compile.outputs.commit_id }}
### Images update
* ${{ secrets.DOCKERHUB_USERNAME }}/pyramid:${{ steps.docker_tag.outputs.tag }}
draft: false
prerelease: true
docker_push:
name: "Docker Push"
needs: ["compile", "publish_release"]
runs-on: ubuntu-latest
if: github.event_name == 'push'
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set git info
run: |
echo '${{ needs.compile.outputs.json }}' | jq -r '.git_info' > git_info.json
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push PROD
if: needs.publish_release.outputs.docker_tag == 'latest'
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: |
${{ secrets.DOCKERHUB_USERNAME }}/pyramid:${{ needs.publish_release.outputs.docker_tag }},
${{ secrets.DOCKERHUB_USERNAME }}/pyramid:${{ needs.compile.outputs.version }},
${{ secrets.DOCKERHUB_USERNAME }}/pyramid:${{ needs.compile.outputs.version }}-${{ needs.compile.outputs.commit_id }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Build and push DEV
if: needs.publish_release.outputs.docker_tag != 'latest'
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: |
${{ secrets.DOCKERHUB_USERNAME }}/pyramid:${{ needs.publish_release.outputs.docker_tag }},
${{ secrets.DOCKERHUB_USERNAME }}/pyramid:${{ needs.compile.outputs.version }}-${{ needs.compile.outputs.commit_id }}
cache-from: type=gha
cache-to: type=gha,mode=max