-
-
Notifications
You must be signed in to change notification settings - Fork 10
344 lines (302 loc) · 12.5 KB
/
Copy pathbuild_project.yml
File metadata and controls
344 lines (302 loc) · 12.5 KB
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
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
name: build-project
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
on:
push:
branches: [main]
pull_request:
branches: main
release:
types: [published]
env:
REGISTRY_GITHUB: ghcr.io
jobs:
variables:
outputs:
ref_name: ${{ steps.var.outputs.ref_name}}
image_name: ${{ steps.var.outputs.image_name }}
ghcr_image: ${{ steps.var.outputs.ghcr_image }}
version: ${{ steps.var.outputs.version }}
runs-on: "ubuntu-latest"
permissions:
contents: read
steps:
- name: Setting global variables
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3
id: var
with:
script: |
const refName = '${{ github.ref_name || github.event.release.tag_name }}';
core.setOutput('ref_name', refName.toLowerCase().replaceAll(/[/.]/g, '-').trim('-'));
core.setOutput('image_name', '${{ github.repository }}'.toLowerCase());
core.setOutput('ghcr_image', '${{ env.REGISTRY_GITHUB }}/${{ github.repository }}'.toLowerCase());
const version = refName.replace(/^v/, '');
core.setOutput('version', version);
build-check:
runs-on: ubuntu-latest
needs: [variables]
env:
REF_NAME: ${{ needs.variables.outputs.ref_name }}
permissions:
id-token: write
contents: write
steps:
- name: Checkout
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0
with:
fetch-depth: 0
- name: Set up Python 3.13
uses: actions/setup-python@ece7cb06caefa5fff74198d8649806c4678c61a1
with:
python-version: "3.13"
- name: Cache Python packages
uses: actions/cache@2c8a9bd7457de244a408f35966fab2fb45fda9c8
with:
path: |
~/.cache/pip
!~/.cache/pip/log
key: ${{ runner.os }}-python-3.13-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-python-3.13-pip-
${{ runner.os }}-python-3.13-
${{ runner.os }}-python-
${{ runner.os }}-pip-
- name: Install build package
run: |
python -m pip install --upgrade pip
pip install build
- name: Install package with dev dependencies
run: pip install -e ".[dev,forecast]"
- name: Get changed Python files
id: changed-py-files
run: |
if [ "${{ github.event_name }}" = "pull_request" ]; then
FILES=$(git diff --name-only --diff-filter=ACMRT "origin/${{ github.base_ref }}...HEAD" -- '*.py' | tr '\n' ' ')
elif [ "${{ github.event_name }}" = "push" ] && \
[ "${{ github.event.before }}" != "0000000000000000000000000000000000000000" ]; then
FILES=$(git diff --name-only --diff-filter=ACMRT "${{ github.event.before }}" "${{ github.sha }}" -- '*.py' | tr '\n' ' ')
fi
echo "files=$(echo "$FILES" | xargs)" >> $GITHUB_OUTPUT
- name: Lint with ruff
run: |
FILES="${{ steps.changed-py-files.outputs.files }}"
ruff check ${FILES:-.}
- name: Type check with pyright
run: |
FILES="${{ steps.changed-py-files.outputs.files }}"
if [ -z "$FILES" ]; then
pyright
else
pyright $FILES
fi
- name: Run tests with coverage
run: python -m pytest --cov=solaredge2mqtt --cov-report=xml:coverage.xml --tb=short
- name: Build package
run: python -m build
- name: Save python artifacts
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a
with:
name: python-artifacts-3.13-${{ env.REF_NAME }}
path: |
dist
- name: Publish package to pypi
if: ${{ github.event_name == 'release' }}
uses: pypa/gh-action-pypi-publish@cef221092ed1bacb1cc03d23a2d87d1d172e277b
with:
packages-dir: dist/
- name: Publish assets to github
if: ${{ github.event_name == 'release' }}
uses: svenstaro/upload-release-action@29e53e917877a24fad85510ded594ab3c9ca12de
with:
repo_token: ${{ github.token }}
file: dist/*
tag: ${{ github.event.release.tag_name }}
overwrite: true
file_glob: true
build-compat:
runs-on: ubuntu-latest
needs: [variables, build-check]
env:
REF_NAME: ${{ needs.variables.outputs.ref_name }}
permissions:
contents: read
strategy:
matrix:
python-version:
- "3.11"
- "3.12"
steps:
- name: Checkout
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0
with:
fetch-depth: 0
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@ece7cb06caefa5fff74198d8649806c4678c61a1
with:
python-version: ${{ matrix.python-version }}
- name: Cache Python packages
uses: actions/cache@2c8a9bd7457de244a408f35966fab2fb45fda9c8
with:
path: |
~/.cache/pip
!~/.cache/pip/log
key: ${{ runner.os }}-python-${{ matrix.python-version }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-python-${{ matrix.python-version }}-pip-
${{ runner.os }}-python-${{ matrix.python-version }}-
${{ runner.os }}-python-
${{ runner.os }}-pip-
- name: Install package with dev dependencies
run: |
python -m pip install --upgrade pip
pip install -e ".[dev,forecast]"
- name: Run tests
run: python -m pytest --tb=short
build-docker:
runs-on: ubuntu-latest
needs: [variables, build-check]
env:
REF_NAME: ${{ needs.variables.outputs.ref_name }}
IMAGE_NAME: ${{ needs.variables.outputs.image_name }}
GHCR_IMAGE: ${{ needs.variables.outputs.ghcr_image }}
VERSION: ${{ needs.variables.outputs.version }}
permissions:
contents: read
packages: write
strategy:
matrix:
arch: [amd64, arm64, arm/v7]
steps:
- name: Checkout
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0
with:
fetch-depth: 0
- name: Install setuptools-scm and tomli
run: pip install setuptools-scm[toml]>=8 tomli
- name: Generate static version.json
run: python freeze_version.py
- name: Generate requirements hashFiles
run: python generate_requirements.py
- name: Set up QEMU
uses: docker/setup-qemu-action@ce360397dd3f832beb865e1373c09c0e9f86d70a
with:
platforms: linux/amd64,linux/arm64,linux/arm/v7
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@d7f5e7f509e45cec5c76c4d5afdd7de93d0b3df5
- name: Log in to the Docker github container registry
if: ${{github.event_name == 'release' || (github.event_name == 'push' && contains(fromJSON(vars.PACKAGE_BRANCHES), github.ref_name))}}
uses: docker/login-action@650006c6eb7dba73a995cc03b0b2d7f5ca915bee
with:
registry: ${{ env.REGISTRY_GITHUB }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Log in to the Docker container registry
if: ${{github.event_name == 'release'}}
uses: docker/login-action@650006c6eb7dba73a995cc03b0b2d7f5ca915bee
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Map platform to tag suffix
id: archmap
run: |
case "${{ matrix.arch }}" in
amd64) echo "ARCH_TAG=amd64" >> $GITHUB_ENV ;;
arm64) echo "ARCH_TAG=arm64" >> $GITHUB_ENV ;;
arm/v7) echo "ARCH_TAG=armv7" >> $GITHUB_ENV ;;
esac
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@80c7e94dd9b9319bd5eb7a0e0fe9291e23a2a2e9
with:
images: |
${{ env.GHCR_IMAGE }}
${{ github.event_name == 'release' && env.IMAGE_NAME || '' }}
tags: |
type=raw,value=latest-${{ env.ARCH_TAG }},enable=${{ github.event_name == 'release' }}
type=raw,value=${{ env.VERSION }}-${{ env.ARCH_TAG }},enable=${{ github.event_name == 'release' }}
type=raw,value=${{ env.REF_NAME }}-${{ env.ARCH_TAG }},enable=${{ github.event_name != 'release' }}
- name: Build and push Docker image
uses: docker/build-push-action@f9f3042f7e2789586610d6e8b85c8f03e5195baf
with:
builder: ${{ steps.buildx.outputs.name }}
context: .
platforms: linux/${{ matrix.arch }}
push: ${{github.event_name == 'release' || (github.event_name == 'push' && contains(fromJSON(vars.PACKAGE_BRANCHES), github.ref_name))}}
tags: ${{ steps.meta.outputs.tags }}
annotations: ${{ steps.meta.outputs.annotations }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha,scope=${{ github.repository }}-${{ env.REF_NAME }}-${{ matrix.arch }}
cache-to: type=gha,mode=max,scope=${{ github.repository }}-${{ env.REF_NAME }}-${{ matrix.arch }}
merge-manifest:
runs-on: ubuntu-latest
needs: [variables, build-docker]
env:
REF_NAME: ${{ needs.variables.outputs.ref_name }}
IMAGE_NAME: ${{ needs.variables.outputs.image_name }}
GHCR_IMAGE: ${{ needs.variables.outputs.ghcr_image }}
VERSION: ${{ needs.variables.outputs.version }}
if: ${{github.event_name == 'release' || (github.event_name == 'push' && contains(fromJSON(vars.PACKAGE_BRANCHES), github.ref_name))}}
permissions:
contents: read
packages: write
steps:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@d7f5e7f509e45cec5c76c4d5afdd7de93d0b3df5
- name: Log in to the Docker github container registry
uses: docker/login-action@650006c6eb7dba73a995cc03b0b2d7f5ca915bee
with:
registry: ${{ env.REGISTRY_GITHUB }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Log in to the Docker container registry
if: ${{github.event_name == 'release'}}
uses: docker/login-action@650006c6eb7dba73a995cc03b0b2d7f5ca915bee
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@80c7e94dd9b9319bd5eb7a0e0fe9291e23a2a2e9
with:
images: |
${{ env.GHCR_IMAGE }}
${{ github.event_name == 'release' && env.IMAGE_NAME || '' }}
tags: |
type=raw,value=latest,enable=${{ github.event_name == 'release' }}
type=raw,value=${{ env.VERSION }},enable=${{ github.event_name == 'release' }}
type=raw,value=${{ env.REF_NAME }},enable=${{ github.event_name != 'release' }}
- name: Create and push multi-arch manifest
run: |
set -eux
if [ "${{ github.event_name }}" == "release" ]; then
# Create latest tag
docker buildx imagetools create \
-t ${{ env.GHCR_IMAGE }}:latest \
${{ env.GHCR_IMAGE }}:latest-amd64 \
${{ env.GHCR_IMAGE }}:latest-arm64 \
${{ env.GHCR_IMAGE }}:latest-armv7
docker buildx imagetools create \
-t ${{ env.IMAGE_NAME }}:latest \
${{ env.IMAGE_NAME }}:latest-amd64 \
${{ env.IMAGE_NAME }}:latest-arm64 \
${{ env.IMAGE_NAME }}:latest-armv7
# Create version tag
docker buildx imagetools create \
-t ${{ env.GHCR_IMAGE }}:${{ env.VERSION }} \
${{ env.GHCR_IMAGE }}:${{ env.VERSION }}-amd64 \
${{ env.GHCR_IMAGE }}:${{ env.VERSION }}-arm64 \
${{ env.GHCR_IMAGE }}:${{ env.VERSION }}-armv7
docker buildx imagetools create \
-t ${{ env.IMAGE_NAME }}:${{ env.VERSION }} \
${{ env.IMAGE_NAME }}:${{ env.VERSION }}-amd64 \
${{ env.IMAGE_NAME }}:${{ env.VERSION }}-arm64 \
${{ env.IMAGE_NAME }}:${{ env.VERSION }}-armv7
else
docker buildx imagetools create \
-t ${{ env.GHCR_IMAGE }}:${{ env.REF_NAME }} \
${{ env.GHCR_IMAGE }}:${{ env.REF_NAME }}-amd64 \
${{ env.GHCR_IMAGE }}:${{ env.REF_NAME }}-arm64 \
${{ env.GHCR_IMAGE }}:${{ env.REF_NAME }}-armv7
fi