-
Notifications
You must be signed in to change notification settings - Fork 5
185 lines (161 loc) · 6.18 KB
/
build.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
# GitHub Action to build a self-contained binary of the Denon AVR Python driver
---
name: "Build & Release"
on:
push:
# branches: [ main ]
# tags:
# - v[0-9]+.[0-9]+.[0-9]+*
pull_request:
types: [ opened, synchronize, reopened ]
env:
INTG_NAME: denonavr
HASH_FILENAME: uc-intg-denonavr.hash
# Python version to use in the builder image. See https://hub.docker.com/r/arm64v8/python for possible versions.
PYTHON_VER: 3.11.6-0.2.0
BUILD_CHANGELOG: build-changelog.md
jobs:
build:
runs-on: ubuntu-24.04
steps:
- name: Checkout
uses: actions/checkout@v4
with:
# History of 200 should be more than enough to calculate commit count since last release tag.
fetch-depth: 200
- name: Fetch all tags to determine version
run: |
git fetch origin +refs/tags/*:refs/tags/*
echo "VERSION=$(git describe --match "v[0-9]*" --tags HEAD --always)" >> $GITHUB_ENV
- name: Verify driver.json version for release build
if: contains(github.ref, 'tags/v')
run: |
DRIVER_VERSION="v$(jq .version -r driver.json)"
if [ "${{ env.VERSION }}" != "$DRIVER_VERSION" ]; then
echo "Version in driver.json ($DRIVER_VERSION) doesn't match git version tag (${{ env.VERSION }})!"
exit 1
fi
- name: Prepare
run: |
sudo apt-get update && sudo apt-get install -y qemu binfmt-support qemu-user-static
docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
echo "Running pyinstaller"
docker run --rm --name builder \
--platform=aarch64 \
--user=$(id -u):$(id -g) \
-v ${GITHUB_WORKSPACE}:/workspace \
docker.io/unfoldedcircle/r2-pyinstaller:${PYTHON_VER} \
bash -c \
"cd /workspace && \
python -m pip install -r requirements.txt && \
pyinstaller --clean --onedir --name intg-denonavr intg-denonavr/driver.py"
- name: Add version
run: |
mkdir -p artifacts
cd artifacts
echo ${{ env.VERSION }} > version.txt
- name: Prepare artifacts
shell: bash
run: |
mv dist/intg-denonavr artifacts/
mv artifacts/intg-denonavr artifacts/bin
mv artifacts/bin/intg-denonavr artifacts/bin/driver
cp driver.json artifacts/
echo "ARTIFACT_NAME=uc-intg-${{ env.INTG_NAME }}-${{ env.VERSION }}-aarch64" >> $GITHUB_ENV
- name: Create upload artifact
shell: bash
run: |
tar czvf ${{ env.ARTIFACT_NAME }}.tar.gz -C ${GITHUB_WORKSPACE}/artifacts .
ls -lah
- uses: actions/upload-artifact@v4
id: upload_artifact
with:
name: ${{ env.ARTIFACT_NAME }}
path: ${{ env.ARTIFACT_NAME }}.tar.gz
if-no-files-found: error
retention-days: 3
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "lts/*"
- name: "Create Changelog"
run: |
npm install -g conventional-changelog-cli
conventional-changelog -p conventionalcommits -u -o ${{ env.BUILD_CHANGELOG }}
cat ${{ env.BUILD_CHANGELOG }}
- name: Upload changelog
uses: actions/upload-artifact@v4
with:
name: changelog
path: ${{ env.BUILD_CHANGELOG }}
if-no-files-found: error
retention-days: 3
release:
name: Create Release
# TODO just for testing PR
# if: github.ref == 'refs/heads/main' || contains(github.ref, 'tags/v')
runs-on: ubuntu-24.04
needs: [ build ]
steps:
- name: Download build artifacts
uses: actions/download-artifact@v4
- name: Extract build archives from downloaded files
run: |
ls -R
# extract tar.gz build archives from downloaded artifacts
# (wrapped in tar from actions/upload-artifact, then extracted into a directory by actions/download-artifact)
for D in *
do if [ -d "${D}" ]; then
mv $D/* ./
fi
done;
# Use a common timestamp for all matrix build artifacts
- name: Get timestamp
run: |
echo "TIMESTAMP=$(date +"%Y%m%d_%H%M%S")" >> $GITHUB_ENV
# Checkout is required for the next `gh release delete` step
- name: Checkout
uses: actions/checkout@v4
with:
path: main
# We have to delete the "latest" release, otherwise `softprops/action-gh-release` will only append the new artifact.
# This simulates the old marvinpinto/action-automatic-releases action.
- name: Remove previous pre-release
run: |
cd main
gh release delete latest --cleanup-tag -y || true
env:
GH_TOKEN: ${{ github.token }}
# Add timestamp to development builds
- name: Create GitHub development build archives
if: "!contains(github.ref, 'tags/v')"
run: |
# append timestamp
for filename in *.tar.gz; do mv $filename "$(basename $filename .tar.gz)-${{ env.TIMESTAMP }}.tar.gz"; done;
for filename in *.tar.gz; do echo "sha256 `sha256sum $filename`" >> ${{ env.HASH_FILENAME }}; done;
# Use conventional commit changelog, and append the GitHub generated changelog
- name: Create Pre-Release
uses: softprops/action-gh-release@v2
if: "!contains(github.ref, 'tags/v')"
with:
prerelease: true
tag_name: latest
body_path: ${{ env.BUILD_CHANGELOG }}
generate_release_notes: true
name: "Development Build"
files: |
*.tar.gz
${{ env.HASH_FILENAME }}
- name: Create GitHub release archives
if: "contains(github.ref, 'tags/v')"
run: |
for filename in *.tar.gz; do echo "sha256 `sha256sum $filename`" >> ${{ env.HASH_FILENAME }}; done;
- name: Create Release
uses: softprops/action-gh-release@v2
if: "contains(github.ref, 'tags/v')"
with:
prerelease: false
generate_release_notes: true
files: |
*.tar.gz
${{ env.HASH_FILENAME }}