Skip to content

Commit e8d0d31

Browse files
authored
feat(release): Update version on release and add XZ archives (#11875)
1 parent ea382df commit e8d0d31

File tree

3 files changed

+165
-7
lines changed

3 files changed

+165
-7
lines changed

.github/scripts/on-release.sh

Lines changed: 155 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,30 @@ if [ -n "${VENDOR}" ]; then
5454
echo "Setting packager: $VENDOR"
5555
fi
5656

57+
function update_version {
58+
set -e
59+
set -o pipefail
60+
61+
local tag=$1
62+
local major
63+
local minor
64+
local patch
65+
66+
# Extract major, minor, and patch from the tag
67+
# We need to make sure to remove the "v" prefix from the tag and any characters after the patch version
68+
tag=$(echo "$tag" | sed 's/^v//g' | sed 's/-.*//g')
69+
major=$(echo "$tag" | cut -d. -f1)
70+
minor=$(echo "$tag" | cut -d. -f2)
71+
patch=$(echo "$tag" | cut -d. -f3 | sed 's/[^0-9].*//') # Remove non-numeric suffixes like RC1, alpha, beta
72+
73+
echo "Major: $major, Minor: $minor, Patch: $patch"
74+
75+
"${SCRIPTS_DIR}/update-version.sh" "$major" "$minor" "$patch"
76+
77+
set +e
78+
set +o pipefail
79+
}
80+
5781
function get_file_size {
5882
local file="$1"
5983
if [[ "$OSTYPE" == "darwin"* ]]; then
@@ -199,8 +223,31 @@ set -e
199223
##
200224

201225
mkdir -p "$OUTPUT_DIR"
202-
PKG_DIR="$OUTPUT_DIR/$PACKAGE_NAME"
226+
PKG_DIR="${OUTPUT_DIR:?}/$PACKAGE_NAME"
203227
PACKAGE_ZIP="$PACKAGE_NAME.zip"
228+
PACKAGE_XZ="$PACKAGE_NAME.tar.xz"
229+
LIBS_ZIP="$PACKAGE_NAME-libs.zip"
230+
LIBS_XZ="$PACKAGE_NAME-libs.tar.xz"
231+
232+
echo "Updating version..."
233+
if ! update_version "$RELEASE_TAG"; then
234+
echo "ERROR: update_version failed!"
235+
exit 1
236+
fi
237+
git config --global github.user "github-actions[bot]"
238+
git config --global user.name "github-actions[bot]"
239+
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
240+
git add .
241+
242+
# We should only commit if there are changes
243+
need_update_commit=true
244+
if git diff --cached --quiet; then
245+
echo "Version already updated"
246+
need_update_commit=false
247+
else
248+
echo "Creating version update commit..."
249+
git commit -m "change(version): Update core version to $RELEASE_TAG"
250+
fi
204251

205252
echo "Updating submodules ..."
206253
git -C "$GITHUB_WORKSPACE" submodule update --init --recursive > /dev/null 2>&1
@@ -283,7 +330,7 @@ echo \#define ARDUINO_ESP32_GIT_DESC "$(git -C "$GITHUB_WORKSPACE" describe --ta
283330
echo \#define ARDUINO_ESP32_RELEASE_"$ver_define" >> "$PKG_DIR/cores/esp32/core_version.h"
284331
echo \#define ARDUINO_ESP32_RELEASE \""$ver_define"\" >> "$PKG_DIR/cores/esp32/core_version.h"
285332

286-
# Compress package folder
333+
# Compress ZIP package folder
287334
echo "Creating ZIP ..."
288335
pushd "$OUTPUT_DIR" >/dev/null
289336
zip -qr "$PACKAGE_ZIP" "$PACKAGE_NAME"
@@ -293,22 +340,112 @@ if [ $? -ne 0 ]; then
293340
fi
294341

295342
# Calculate SHA-256
296-
echo "Calculating SHA sum ..."
297-
PACKAGE_PATH="$OUTPUT_DIR/$PACKAGE_ZIP"
343+
echo "Calculating ZIP SHA sum ..."
344+
PACKAGE_PATH="${OUTPUT_DIR:?}/$PACKAGE_ZIP"
298345
PACKAGE_SHA=$(shasum -a 256 "$PACKAGE_ZIP" | cut -f 1 -d ' ')
299346
PACKAGE_SIZE=$(get_file_size "$PACKAGE_ZIP")
300347
popd >/dev/null
301-
rm -rf "$PKG_DIR"
302348
echo "'$PACKAGE_ZIP' Created! Size: $PACKAGE_SIZE, SHA-256: $PACKAGE_SHA"
303349
echo
304350

305-
# Upload package to release page
306-
echo "Uploading package to release page ..."
351+
# Compress XZ package folder
352+
echo "Creating XZ ..."
353+
pushd "$OUTPUT_DIR" >/dev/null
354+
tar -cJf "$PACKAGE_XZ" "$PACKAGE_NAME"
355+
if [ $? -ne 0 ]; then
356+
echo "ERROR: Failed to create $PACKAGE_XZ ($?)"
357+
exit 1
358+
fi
359+
360+
# Calculate SHA-256
361+
echo "Calculating XZ SHA sum ..."
362+
PACKAGE_XZ_PATH="${OUTPUT_DIR:?}/$PACKAGE_XZ"
363+
PACKAGE_XZ_SHA=$(shasum -a 256 "$PACKAGE_XZ" | cut -f 1 -d ' ')
364+
PACKAGE_XZ_SIZE=$(get_file_size "$PACKAGE_XZ")
365+
popd >/dev/null
366+
echo "'$PACKAGE_XZ' Created! Size: $PACKAGE_XZ_SIZE, SHA-256: $PACKAGE_XZ_SHA"
367+
echo
368+
369+
# Upload ZIP package to release page
370+
echo "Uploading ZIP package to release page ..."
307371
PACKAGE_URL=$(git_safe_upload_asset "$PACKAGE_PATH")
308372
echo "Package Uploaded"
309373
echo "Download URL: $PACKAGE_URL"
310374
echo
311375

376+
# Upload XZ package to release page
377+
echo "Uploading XZ package to release page ..."
378+
PACKAGE_XZ_URL=$(git_safe_upload_asset "$PACKAGE_XZ_PATH")
379+
echo "Package Uploaded"
380+
echo "Download URL: $PACKAGE_XZ_URL"
381+
echo
382+
383+
# Remove package folder
384+
rm -rf "$PKG_DIR"
385+
386+
# Copy Libs from lib-builder to release in ZIP and XZ
387+
388+
libs_url=$(cat "$PACKAGE_JSON_TEMPLATE" | jq -r ".packages[0].tools[] | select(.name == \"esp32-arduino-libs\") | .systems[0].url")
389+
libs_sha=$(cat "$PACKAGE_JSON_TEMPLATE" | jq -r ".packages[0].tools[] | select(.name == \"esp32-arduino-libs\") | .systems[0].checksum" | sed 's/^SHA-256://')
390+
libs_size=$(cat "$PACKAGE_JSON_TEMPLATE" | jq -r ".packages[0].tools[] | select(.name == \"esp32-arduino-libs\") | .systems[0].size")
391+
echo "Downloading libs from lib-builder ..."
392+
echo "URL: $libs_url"
393+
echo "Expected SHA: $libs_sha"
394+
echo "Expected Size: $libs_size"
395+
echo
396+
397+
echo "Downloading libs from lib-builder ..."
398+
curl -L -o "$OUTPUT_DIR/$LIBS_ZIP" "$libs_url"
399+
400+
# Check SHA and Size
401+
zip_sha=$(sha256sum "$OUTPUT_DIR/$LIBS_ZIP" | awk '{print $1}')
402+
zip_size=$(stat -c%s "$OUTPUT_DIR/$LIBS_ZIP")
403+
echo "Downloaded SHA: $zip_sha"
404+
echo "Downloaded Size: $zip_size"
405+
if [ "$zip_sha" != "$libs_sha" ] || [ "$zip_size" != "$libs_size" ]; then
406+
echo "ERROR: ZIP SHA and Size do not match"
407+
exit 1
408+
fi
409+
410+
# Extract ZIP
411+
412+
echo "Repacking libs to XZ ..."
413+
unzip -q "$OUTPUT_DIR/$LIBS_ZIP" -d "$OUTPUT_DIR"
414+
pushd "$OUTPUT_DIR" >/dev/null
415+
tar -cJf "$LIBS_XZ" "esp32-arduino-libs"
416+
popd >/dev/null
417+
418+
# Upload ZIP and XZ libs to release page
419+
420+
echo "Uploading ZIP libs to release page ..."
421+
LIBS_ZIP_URL=$(git_safe_upload_asset "$OUTPUT_DIR/$LIBS_ZIP")
422+
echo "ZIP libs Uploaded"
423+
echo "Download URL: $LIBS_ZIP_URL"
424+
echo
425+
426+
echo "Uploading XZ libs to release page ..."
427+
LIBS_XZ_URL=$(git_safe_upload_asset "$OUTPUT_DIR/$LIBS_XZ")
428+
echo "XZ libs Uploaded"
429+
echo "Download URL: $LIBS_XZ_URL"
430+
echo
431+
432+
# Update libs URLs in JSON template
433+
echo "Updating libs URLs in JSON template ..."
434+
435+
# Update all libs URLs in the JSON template
436+
libs_jq_arg="(.packages[0].tools[] | select(.name == \"esp32-arduino-libs\") | .systems[].url) = \"$LIBS_ZIP_URL\""
437+
438+
cat "$PACKAGE_JSON_TEMPLATE" | jq "$libs_jq_arg" > "$OUTPUT_DIR/package-libs-updated.json"
439+
PACKAGE_JSON_TEMPLATE="$OUTPUT_DIR/package-libs-updated.json"
440+
441+
echo "Libs URLs updated in JSON template"
442+
echo
443+
444+
# Clean up
445+
rm -rf "${OUTPUT_DIR:?}/esp32-arduino-libs"
446+
rm -rf "${OUTPUT_DIR:?}/$LIBS_ZIP"
447+
rm -rf "${OUTPUT_DIR:?}/$LIBS_XZ"
448+
312449
##
313450
## TEMP WORKAROUND FOR RV32 LONG PATH ON WINDOWS
314451
##
@@ -469,6 +606,17 @@ if [ "$RELEASE_PRE" == "false" ]; then
469606
echo
470607
fi
471608

609+
if [ "$need_update_commit" == "true" ]; then
610+
echo "Pushing version update commit..."
611+
git push
612+
new_tag_commit=$(git rev-parse HEAD)
613+
echo "New commit: $new_tag_commit"
614+
615+
echo "Moving tag $RELEASE_TAG to $new_tag_commit..."
616+
git tag -f "$RELEASE_TAG" "$new_tag_commit"
617+
git push --force origin "$RELEASE_TAG"
618+
fi
619+
472620
set +e
473621

474622
##

.github/scripts/update-version.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
# Disable shellcheck warning about using 'cat' to read a file.
33
# shellcheck disable=SC2002
44

5+
# Exit on any error and make pipelines fail if any command fails
6+
set -e
7+
set -o pipefail
8+
59
# For reference: add tools for all boards by replacing one line in each board
610
# "[board].upload.tool=esptool_py" to "[board].upload.tool=esptool_py\n[board].upload.tool.default=esptool_py\n[board].upload.tool.network=esp_ota"
711
#cat boards.txt | sed "s/\([a-zA-Z0-9_\-]*\)\.upload\.tool\=esptool_py/\1\.upload\.tool\=esptool_py\\n\1\.upload\.tool\.default\=esptool_py\\n\1\.upload\.tool\.network\=esp_ota/"
@@ -38,6 +42,11 @@ echo "Updating issue template..."
3842
cat .github/ISSUE_TEMPLATE/Issue-report.yml | \
3943
sed "s/.*\- latest master .*/ - latest master \(checkout manually\)\\n - v$ESP_ARDUINO_VERSION/g" > __issue-report.yml && mv __issue-report.yml .github/ISSUE_TEMPLATE/Issue-report.yml
4044

45+
echo "Updating GitLab variables..."
46+
cat .gitlab/workflows/common.yml | \
47+
sed "s/ESP_IDF_VERSION:.*/ESP_IDF_VERSION: \"$ESP_IDF_VERSION\"/g" | \
48+
sed "s/ESP_ARDUINO_VERSION:.*/ESP_ARDUINO_VERSION: \"$ESP_ARDUINO_VERSION\"/g" > .gitlab/workflows/__common.yml && mv .gitlab/workflows/__common.yml .gitlab/workflows/common.yml
49+
4150
echo "Updating platform.txt..."
4251
cat platform.txt | sed "s/version=.*/version=$ESP_ARDUINO_VERSION/g" > __platform.txt && mv __platform.txt platform.txt
4352

.github/workflows/release.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ jobs:
1717
- name: Checkout repository
1818
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
1919
with:
20+
ref: ${{ github.event.release.target_commitish }}
2021
fetch-depth: 0
2122

2223
- name: Set up Python

0 commit comments

Comments
 (0)