Skip to content

Commit 150b6f7

Browse files
committed
First try at OctoPi release triggers
1 parent a55ec5b commit 150b6f7

File tree

1 file changed

+98
-21
lines changed

1 file changed

+98
-21
lines changed

.github/workflows/custopize.yml

Lines changed: 98 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@ name: "CustoPiZe"
22

33
on:
44
repository_dispatch:
5-
types: [octoprint_release]
5+
types: [octopi_release, octoprint_release]
66
workflow_dispatch:
77
inputs:
8+
octopi_version:
9+
description: "OctoPi version (leave empty to use latest stable release)"
10+
required: false
11+
default: ''
812
octoprint_version:
913
description: "OctoPrint version (leave empty to use latest stable release)"
1014
required: false
@@ -19,6 +23,80 @@ jobs:
1923
- name: "⬇ Checkout"
2024
uses: actions/checkout@v2
2125

26+
- name: "🔎 Determine OctoPi version"
27+
uses: actions/github-script@v4
28+
with:
29+
script: |
30+
let release = null;
31+
32+
let version = '';
33+
if (context.eventName === "respository_dispatch" && context.payload.type === "octopi_release") {
34+
version = context.payload.client_payload.version;
35+
} else if (context.eventName === "workflow_dispatch") {
36+
version = context.payload.inputs.octopi_version;
37+
}
38+
39+
if (version) {
40+
const query = `query {
41+
repository(name: "guysoft", owner: "Octopi") {
42+
release(tagName:"${version}") {
43+
tagName
44+
releaseAssets(first:5) {
45+
nodes {
46+
name
47+
downloadUrl
48+
}
49+
}
50+
}
51+
}
52+
}`;
53+
54+
const result = await github.graphql(query);
55+
console.log({result});
56+
57+
release = result.repository.release;
58+
59+
} else {
60+
const query = `query {
61+
repository(owner:"guysoft", name:"OctoPi") {
62+
latestRelease {
63+
tagName
64+
releaseAssets(first:5) {
65+
nodes {
66+
name
67+
downloadUrl
68+
}
69+
}
70+
}
71+
}
72+
}`;
73+
74+
const result = await github.graphql(query);
75+
console.log({result});
76+
77+
release = result.repository.latestRelease;
78+
}
79+
80+
if (!release || !release.tagName || !release.releaseAssets || !release.releaseAssets.nodes) core.setFailed("Could not find OctoPi release");
81+
82+
const octopiVersion = release.tagName;
83+
84+
let octopiUrl = null;
85+
for (const asset of release.releaseAssets.nodes) {
86+
if (asset.name.startsWith("octopi-") && asset.name.endsWith(".zip")) {
87+
octopiUrl = asset.downloadUrl;
88+
break;
89+
}
90+
}
91+
92+
if (!octopiUrl) core.setFailed("Could not find OctoPi download URL");
93+
94+
console.log(`OctoPi version: ${octopiVersion}`)
95+
console.log(`OctoPi download URL: ${octopiUrl}`)
96+
97+
core.exportVariable("OCTOPI_VERSION", octopiVersion)
98+
core.exportVariable("OCTOPI_URL", octopiUrl)
99+
22100
- name: "🔎 Determine OctoPrint version"
23101
run: |
24102
if [[ "${{ github.event_name }}" = "repository_dispatch" ]]; then
@@ -34,24 +112,23 @@ jobs:
34112
# Make sure we have a published version
35113
curl -fsSL --output /dev/null --head https://pypi.org/pypi/OctoPrint/$OCTOPRINT_VERSION/ || exit 1
36114
115+
echo "OctoPrint version: $OCTOPRINT_VERSION"
116+
37117
echo "OCTOPRINT_VERSION=$OCTOPRINT_VERSION" >> $GITHUB_ENV
38118
39-
- name: "⬇ Download latest OctoPi"
119+
- name: "⬇ Download OctoPi"
40120
id: octopi_download
41121
run: |
42122
mkdir build
43123
cd build
44-
wget https://octopi.octoprint.org/latest -O octopi.zip
124+
wget ${{ env.OCTOPI_URL }} -O octopi.zip
45125
46126
unzip octopi.zip
47127
rm octopi.zip
48128
49129
IMAGE=$(ls *.img | head -n 1)
50130
mv $IMAGE input.img
51131
52-
OCTOPI_VERSION=$(basename -s .img $IMAGE | awk -F"-" '{print $NF}')
53-
echo "OCTOPI_VERSION=$OCTOPI_VERSION" >> $GITHUB_ENV
54-
55132
- name: "🏗 Run CustoPiZer"
56133
run: |
57134
sudo modprobe loop
@@ -129,18 +206,18 @@ jobs:
129206
}
130207
EOF
131208
132-
- name: "🔖 Create release & attach assets"
133-
uses: softprops/action-gh-release@v1
134-
with:
135-
name: "${{ env.RELEASE_NAME }}"
136-
tag_name: "${{ env.RELEASE_TAG }}"
137-
body: "${{ env.RELEASE_BODY }}"
138-
prerelease: ${{ contains(env.OCTOPRINT_VERSION, 'rc') }}
139-
fail_on_unmatched_files: true
140-
files: |
141-
build/${{ env.IMAGE }}.zip
142-
build/${{ env.IMAGE }}.zip.md5
143-
build/${{ env.IMAGE }}.zip.sha256
144-
build/rpi-imager.json
145-
env:
146-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
209+
#- name: "🔖 Create release & attach assets"
210+
# uses: softprops/action-gh-release@v1
211+
# with:
212+
# name: "${{ env.RELEASE_NAME }}"
213+
# tag_name: "${{ env.RELEASE_TAG }}"
214+
# body: "${{ env.RELEASE_BODY }}"
215+
# prerelease: ${{ contains(env.OCTOPRINT_VERSION, 'rc') }}
216+
# fail_on_unmatched_files: true
217+
# files: |
218+
# build/${{ env.IMAGE }}.zip
219+
# build/${{ env.IMAGE }}.zip.md5
220+
# build/${{ env.IMAGE }}.zip.sha256
221+
# build/rpi-imager.json
222+
# env:
223+
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)