-
Notifications
You must be signed in to change notification settings - Fork 4
239 lines (201 loc) · 7.83 KB
/
build_publish_api.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
name: Publish API Docker images and create a release
on:
workflow_dispatch:
inputs:
bump:
description: "Bump the version of the API"
type: choice
required: true
default: "patch"
options:
- "patch"
- "minor"
- "major"
- "prepatch"
- "preminor"
- "premajor"
env:
DRAFT: ${{ contains(inputs.bump, 'pre') }}
jobs:
python_project:
name: Build ecoindex API python project
runs-on: ubuntu-latest
outputs:
wheel: ${{ steps.wheel.outputs.wheel }}
api_version: ${{ steps.version.outputs.api_version }}
steps:
- name: Check out the repo
uses: actions/checkout@v4
- name: Set up Python 3.10
uses: actions/setup-python@v5
with:
python-version: "3.10"
- name: Install Task
uses: arduino/setup-task@v2
with:
version: 3.x
- name: Install poetry
uses: abatilo/actions-poetry@v2
- name: Install poetry build project
run: pip install poetry-multiproject-plugin
- name: Bump version
run: task api:bump -- ${{ github.event.inputs.bump }}
- name: Build
run: task api:poetry:build
- name: Upload version to artifacts
uses: actions/upload-artifact@v4
with:
name: version
path: bases/ecoindex/backend/VERSION
- name: Upload pyproject.toml to artifacts
uses: actions/upload-artifact@v4
with:
name: pyproject
path: projects/ecoindex_api/pyproject.toml
- name: Upload dist folder
uses: actions/upload-artifact@v4
with:
name: dist
path: projects/ecoindex_api/dist
- name: Output version
id: version
run: echo "api_version=$(task api:poetry:version-short)" >> $GITHUB_OUTPUT
- name: Output wheel
id: wheel
run: echo "wheel=ecoindex_api-${{ steps.version.outputs.api_version }}-py3-none-any.whl" >> $GITHUB_OUTPUT
- name: Output summary
run: |
echo "API version ${{ steps.version.outputs.api_version }}" >> $GITHUB_STEP_SUMMARY
echo "Wheel ${{ steps.wheel.outputs.wheel }}" >> $GITHUB_STEP_SUMMARY
backend_image:
name: Build and push backend image to docker hub
runs-on: ubuntu-latest
needs: python_project
steps:
- name: Check out the repo
uses: actions/checkout@v4
- name: Download dist from artifacts
uses: actions/download-artifact@v4
with:
name: dist
path: projects/ecoindex_api/dist
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- 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: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v4
with:
images: vvatelot/ecoindex-api-backend
- name: Build and push
uses: docker/build-push-action@v4
with:
context: projects/ecoindex_api
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }},vvatelot/ecoindex-api-backend:${{ needs.python_project.outputs.api_version }},${{ !env.DRAFT && 'vvatelot/ecoindex-api-backend:latest' || '' }}
labels: ${{ steps.meta.outputs.labels }}
file: projects/ecoindex_api/docker/backend/dockerfile
build-args: wheel=${{ needs.python_project.outputs.wheel }}
worker_image:
name: Build and push worker image to docker hub
runs-on: ubuntu-latest
needs: python_project
steps:
- name: Check out the repo
uses: actions/checkout@v4
- name: Download dist from artifacts
uses: actions/download-artifact@v4
with:
name: dist
path: projects/ecoindex_api/dist
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- 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: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v4
with:
images: vvatelot/ecoindex-api-worker
- name: Build and push
uses: docker/build-push-action@v4
with:
context: projects/ecoindex_api
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }},vvatelot/ecoindex-api-worker:${{ needs.python_project.outputs.api_version }},${{ !env.DRAFT && 'vvatelot/ecoindex-api-worrker:latest' || '' }}
labels: ${{ steps.meta.outputs.labels }}
file: projects/ecoindex_api/docker/worker/dockerfile
build-args: wheel=${{ needs.python_project.outputs.wheel }}
release:
name: Create a release
runs-on: ubuntu-latest
needs: [python_project, backend_image, worker_image]
steps:
- name: Check out the repo
uses: actions/checkout@v4
- name: Git pull
run: git pull
- name: Download pyproject.toml to a temporary file
uses: actions/download-artifact@v4
with:
name: pyproject
path: /tmp
- name: Download VERSION to a temporary file
uses: actions/download-artifact@v4
with:
name: version
path: /tmp
- name: Copy and overwrite existing files to the repo
run: |
cp /tmp/pyproject.toml projects/ecoindex_api/pyproject.toml
cp /tmp/VERSION bases/ecoindex/backend/VERSION
- name: Get last tag (that is not a `pre` tag) for api
id: last_tag
run: echo "last_tag=$(git tag --list | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+@api$' | sort -r | head -n 1)" >> $GITHUB_OUTPUT
- name: Commit files
uses: EndBug/add-and-commit@v9
with:
message: "chore(api): Bump API version to ${{ needs.python_project.outputs.api_version }}"
tag: v${{ needs.python_project.outputs.api_version }}@api
tag_push: "--force"
push: true
- name: Update CHANGELOG
id: changelog
uses: requarks/changelog-action@v1
with:
token: ${{ github.token }}
fromTag: v${{ needs.python_project.outputs.api_version }}@api
toTag: ${{ steps.last_tag.outputs.last_tag }}
excludeScopes: cli
changelogFilePath: /tmp/changelog.md
- name: Update changelog content with dockerhub links
run: |
echo "" >> /tmp/changelog.md
echo "### Docker images" >> /tmp/changelog.md
echo "" >> /tmp/changelog.md
echo "Docker images have been built and pushed to Docker Hub. You can find them here:" >> /tmp/changelog.md
echo "- **Backend**: [vvatelot/ecoindex-api-backend:${{ needs.python_project.outputs.api_version }}](https://hub.docker.com/r/vvatelot/ecoindex-api-backend/tags?page=1&name=${{ needs.python_project.outputs.api_version }})" >> /tmp/changelog.md
echo "- **Worker**: [vvatelot/ecoindex-api-worker:${{ needs.python_project.outputs.api_version }}](https://hub.docker.com/r/vvatelot/ecoindex-api-worker/tags?page=1&name=${{ needs.python_project.outputs.api_version }})" >> /tmp/changelog.md
- name: Create Release
uses: ncipollo/release-action@v1
with:
allowUpdates: true
draft: ${{ env.DRAFT }}
makeLatest: true
name: "API: v${{ needs.python_project.outputs.api_version }}"
tag: v${{ needs.python_project.outputs.api_version }}@api
token: ${{ github.token }}
bodyFile: /tmp/changelog.md