-
Notifications
You must be signed in to change notification settings - Fork 0
308 lines (245 loc) · 8.89 KB
/
build.yaml
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
name: "Build binary & package"
on:
workflow_dispatch:
inputs:
build_branch:
description: "camera-streamer branch to build"
required: false
default: 'master'
octopi_version:
description: "OctoPi version to build against (leave empty to use latest stable release)"
required: false
default: ''
debian_revision:
description: "Debian revision to use"
required: false
default: '1'
jobs:
build:
name: "Build"
runs-on: ubuntu-latest
outputs:
camera-streamer-version: ${{ steps.extract.outputs.camera-streamer-version }}
dependencies: ${{ steps.extract.outputs.dependencies }}
steps:
- name: "⬇ Checkout"
uses: actions/checkout@v3
- name: "🔎 Determine OctoPi version"
uses: actions/github-script@v6
with:
script: |
let release = null;
let version = context.payload.inputs.octopi_version;
if (version) {
console.log(`Fetching release of ${version}`);
const query = `query {
repository(owner: "guysoft", name: "Octopi") {
release(tagName:"${version}") {
tagName
releaseAssets(first:5) {
nodes {
name
downloadUrl
}
}
}
}
}`;
const result = await github.graphql(query);
console.log({result});
release = result.repository.release;
} else {
console.log("Fetching latest release");
const query = `query {
repository(owner:"guysoft", name:"OctoPi") {
latestRelease {
tagName
releaseAssets(first:5) {
nodes {
name
downloadUrl
}
}
}
}
}`;
const result = await github.graphql(query);
console.log({result});
release = result.repository.latestRelease;
}
if (!release || !release.tagName || !release.releaseAssets || !release.releaseAssets.nodes) core.setFailed("Could not find OctoPi release");
const octopiVersion = release.tagName;
let octopiUrl = null;
for (const asset of release.releaseAssets.nodes) {
if (asset.name.startsWith("octopi-") && asset.name.includes("-armhf-") && asset.name.endsWith(".zip")) {
octopiUrl = asset.downloadUrl;
break;
}
}
if (!octopiUrl) core.setFailed("Could not find OctoPi download URL");
console.log(`OctoPi version: ${octopiVersion}`)
console.log(`OctoPi download URL: ${octopiUrl}`)
core.exportVariable("OCTOPI_VERSION", octopiVersion)
core.exportVariable("OCTOPI_URL", octopiUrl)
- name: "⬇ Download OctoPi"
id: octopi_download
run: |
mkdir build
cd build
curl -L -o octopi.zip ${{ env.OCTOPI_URL }}
unzip octopi.zip
rm octopi.zip
IMAGE=$(ls *.img | head -n 1)
mv $IMAGE input.img
- name: "🏗 Run CustoPiZer"
uses: OctoPrint/CustoPiZer@main
with:
workspace: "${{ github.workspace }}/build"
scripts: "${{ github.workspace }}/scripts"
environment: '{ "CAMERA_STREAMER_BRANCH": "${{ github.event.inputs.build_branch }}" }'
- name: Extract binary & info
id: extract
run: |
# copy binary from build
cp build/export/camera-streamer .
# fetch commit & export it as output
version=$(cat build/export/camera-streamer.version | cut -c2- | cut -d' ' -f1)
echo "camera-streamer-version=$version" >> "$GITHUB_OUTPUT"
# fetch info about dependencies
libcamera0_version=$(cat build/export/libcamera0.version)
echo $libcamera0_version
liblivemedia=$(cat build/export/liblivemedia.dep)
echo $liblivemedia
libavformat=$(cat build/export/libavformat.dep)
echo $libavformat
libavcodec=$(cat build/export/libavcodec.dep)
echo $libavcodec
libavutil=$(cat build/export/libavutil.dep)
echo $libavutil
libssl=$(cat build/export/libssl.dep)
echo $libssl
# build dependency string & export it as output
dependencies="libcamera0 (= $libcamera0_version), $liblivemedia, $libavformat, $libavcodec, $libavutil, $libssl"
echo "dependencies=$dependencies" >> "$GITHUB_OUTPUT"
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: camera-streamer
path: camera-streamer
package:
name: "Package"
needs: build
runs-on: ubuntu-latest
outputs:
package-version: ${{ steps.manifest.outputs.package-version }}
build-date: ${{ steps.manifest.outputs.build-date }}
steps:
- name: "⬇ Checkout"
uses: actions/checkout@v3
- name: Download artifact
uses: actions/download-artifact@v4
with:
name: camera-streamer
- name: 🏗 Set up Python 3.10
uses: actions/setup-python@v4
with:
python-version: "3.10"
- name: Prepare manifest
id: manifest
run: |
today=$(date +"%Y%m%d")
echo "build-date=$today" >> $GITHUB_OUTPUT
revision="${{ github.event.inputs.debian_revision }}"
version="${{ needs.build.outputs.camera-streamer-version }}"
if [[ "$version" == *"-"* ]]; then
version=$(echo $version | awk -F'-' '{print $1 "~" $2 "+" $3}') # 0.1-16-gcdfb62ef -> 0.1~16+gcdfb62ef
fi
version="$version-$revision"
echo "package-version=$version" >> $GITHUB_OUTPUT
cat <<EOF > manifest.yml
control:
Package: camera-streamer
Version: $version
Architecture: armhf
Maintainer: Gina Häußge <[email protected]>
Depends: ${{ needs.build.outputs.dependencies }}
Homepage: https://github.com/ayufan/camera-streamer
Description: High-performance low-latency camera streamer for Raspberry Pis, built for use with OctoPrint
installation_prefix: /usr
data_files:
bin/camera-streamer:
source: camera-streamer
EOF
- name: Build package
run: |
pip install ruamel.yaml
chmod 755 ${{ github.workspace }}/.github/termux-create-package
${{ github.workspace }}/.github/termux-create-package manifest.yml
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: camera-streamer.deb
path: camera-streamer_*.deb
release:
name: "Release"
runs-on: ubuntu-latest
needs:
- build
- package
outputs:
release-assets: ${{ steps.create_release.outputs.assets }}
steps:
- name: Download deb artifact
uses: actions/download-artifact@v4
with:
name: camera-streamer.deb
- name: Download binary artifact
uses: actions/download-artifact@v4
with:
name: camera-streamer
- name: "📝 Prepare release"
run: |
package_version="${{ needs.package.outputs.package-version }}"
version=${{ needs.build.outputs.camera-streamer-version }}
branch="${{ github.event.inputs.build_branch }}"
revision=${{ github.event.inputs.debian_revision }}
RELEASE_NAME="camera-streamer $package_version"
echo "RELEASE_NAME=$RELEASE_NAME" >> $GITHUB_ENV
RELEASE_TAG="$version-$revision"
echo "RELEASE_TAG=$RELEASE_TAG" >> $GITHUB_ENV
cat > release.md << EOF
[camera-streamer](https://github.com/ayufan/camera-streamer) v$package_version built from branch $branch.
Built against \`${{ needs.build.outputs.dependencies }}\`.
EOF
- name: "🔖 Create release & attach export"
uses: softprops/action-gh-release@v1
id: create_release
with:
name: "${{ env.RELEASE_NAME }}"
tag_name: "${{ env.RELEASE_TAG }}"
body_path: "release.md"
fail_on_unmatched_files: true
files: |
camera-streamer*.deb
camera-streamer
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
notify:
name: "Notify"
runs-on: ubuntu-latest
needs: release
steps:
- name: "♻ Prepare data"
run: |
cat > assets.json <<EOF
${{ needs.release.outputs.release-assets }}
EOF
URL=$(jq -r '.[0].browser_download_url' assets.json)
echo "DEB_URL=$URL" >> $GITHUB_ENV
- name: "📨 Notify apt repo"
uses: peter-evans/repository-dispatch@v2
with:
token: ${{ secrets.REPO_DISPATCH_ACCESS }}
repository: OctoPrint/apt.octoprint.org
event-type: add-package
client-payload: '{"url": "${{ env.DEB_URL }}", "dist": "bullseye", "component": "rpi"}'