Skip to content

Commit 28d7c82

Browse files
committed
Merge branch 'ci/update_version'
2 parents ef453a5 + 4f46569 commit 28d7c82

File tree

2 files changed

+145
-7
lines changed

2 files changed

+145
-7
lines changed

.github/scripts/on-release.sh

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

57+
function update_version {
58+
local tag=$1
59+
local major
60+
local minor
61+
local patch
62+
63+
# Extract major, minor, and patch from the tag
64+
# We need to make sure to remove the "v" prefix from the tag and any characters after the patch version
65+
tag=$(echo "$tag" | sed 's/^v//g' | sed 's/-.*//g')
66+
major=$(echo "$tag" | cut -d. -f1)
67+
minor=$(echo "$tag" | cut -d. -f2)
68+
patch=$(echo "$tag" | cut -d. -f3)
69+
70+
echo "Major: $major, Minor: $minor, Patch: $patch"
71+
72+
"${SCRIPTS_DIR}/update-version.sh" "$major" "$minor" "$patch"
73+
}
74+
5775
function get_file_size {
5876
local file="$1"
5977
if [[ "$OSTYPE" == "darwin"* ]]; then
@@ -89,6 +107,13 @@ function git_safe_upload_asset {
89107
fi
90108

91109
up_size=$(echo "$upload_res" | jq -r '.size')
110+
111+
# Check if up_size is a valid integer (not null or empty)
112+
if [ "$up_size" = "null" ] || [ -z "$up_size" ] || ! [ "$up_size" -eq "$up_size" ] 2>/dev/null; then
113+
>&2 echo "ERROR: Could not get uploaded file size from API response. Response: $upload_res"
114+
return 1
115+
fi
116+
92117
if [ "$up_size" -ne "$size" ]; then
93118
>&2 echo "ERROR: Uploaded size does not match! $up_size != $size"
94119
#git_delete_asset
@@ -199,8 +224,28 @@ set -e
199224
##
200225

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

205250
echo "Updating submodules ..."
206251
git -C "$GITHUB_WORKSPACE" submodule update --init --recursive > /dev/null 2>&1
@@ -283,7 +328,7 @@ echo \#define ARDUINO_ESP32_GIT_DESC "$(git -C "$GITHUB_WORKSPACE" describe --ta
283328
echo \#define ARDUINO_ESP32_RELEASE_"$ver_define" >> "$PKG_DIR/cores/esp32/core_version.h"
284329
echo \#define ARDUINO_ESP32_RELEASE \""$ver_define"\" >> "$PKG_DIR/cores/esp32/core_version.h"
285330

286-
# Compress package folder
331+
# Compress ZIP package folder
287332
echo "Creating ZIP ..."
288333
pushd "$OUTPUT_DIR" >/dev/null
289334
zip -qr "$PACKAGE_ZIP" "$PACKAGE_NAME"
@@ -293,22 +338,99 @@ if [ $? -ne 0 ]; then
293338
fi
294339

295340
# Calculate SHA-256
296-
echo "Calculating SHA sum ..."
297-
PACKAGE_PATH="$OUTPUT_DIR/$PACKAGE_ZIP"
341+
echo "Calculating ZIP SHA sum ..."
342+
PACKAGE_PATH="${OUTPUT_DIR:?}/$PACKAGE_ZIP"
298343
PACKAGE_SHA=$(shasum -a 256 "$PACKAGE_ZIP" | cut -f 1 -d ' ')
299344
PACKAGE_SIZE=$(get_file_size "$PACKAGE_ZIP")
300345
popd >/dev/null
301-
rm -rf "$PKG_DIR"
302346
echo "'$PACKAGE_ZIP' Created! Size: $PACKAGE_SIZE, SHA-256: $PACKAGE_SHA"
303347
echo
304348

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

381+
# Upload XZ package to release page
382+
echo "Uploading XZ package to release page ..."
383+
PACKAGE_XZ_URL=$(git_safe_upload_asset "$PACKAGE_XZ_PATH")
384+
echo "Package Uploaded"
385+
echo "Download URL: $PACKAGE_XZ_URL"
386+
echo
387+
388+
# Remove package folder
389+
rm -rf "$PKG_DIR"
390+
391+
# Copy Libs from lib-builder to release in ZIP and XZ
392+
393+
echo "Downloading libs from lib-builder ..."
394+
libs_url=$(cat "$PACKAGE_JSON_TEMPLATE" | jq -r ".packages[0].tools[] | select(.name == \"esp32-arduino-libs\") | .systems[0].url")
395+
libs_sha=$(cat "$PACKAGE_JSON_TEMPLATE" | jq -r ".packages[0].tools[] | select(.name == \"esp32-arduino-libs\") | .systems[0].checksum")
396+
libs_size=$(cat "$PACKAGE_JSON_TEMPLATE" | jq -r ".packages[0].tools[] | select(.name == \"esp32-arduino-libs\") | .systems[0].size")
397+
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+
if [ "$zip_sha" != "$libs_sha" ] || [ "$zip_size" != "$libs_size" ]; then
404+
echo "ERROR: ZIP SHA and Size do not match"
405+
exit 1
406+
fi
407+
408+
# Extract ZIP
409+
410+
echo "Repacking libs to XZ ..."
411+
mkdir -p "${OUTPUT_DIR:?}/tmp-libs"
412+
unzip "$OUTPUT_DIR/$LIBS_ZIP" -d "$OUTPUT_DIR/tmp-libs"
413+
tar -cJf "$OUTPUT_DIR/$LIBS_XZ" "$OUTPUT_DIR/tmp-libs"
414+
415+
# Upload ZIP and XZ libs to release page
416+
417+
echo "Uploading ZIP libs to release page ..."
418+
LIBS_ZIP_URL=$(git_safe_upload_asset "$OUTPUT_DIR/$LIBS_ZIP")
419+
echo "ZIP libs Uploaded"
420+
echo "Download URL: $LIBS_ZIP_URL"
421+
echo
422+
423+
echo "Uploading XZ libs to release page ..."
424+
LIBS_XZ_URL=$(git_safe_upload_asset "$OUTPUT_DIR/$LIBS_XZ")
425+
echo "XZ libs Uploaded"
426+
echo "Download URL: $LIBS_XZ_URL"
427+
echo
428+
429+
# Clean up
430+
rm -rf "${OUTPUT_DIR:?}/tmp-libs"
431+
rm -rf "${OUTPUT_DIR:?}/$LIBS_ZIP"
432+
rm -rf "${OUTPUT_DIR:?}/$LIBS_XZ"
433+
312434
##
313435
## TEMP WORKAROUND FOR RV32 LONG PATH ON WINDOWS
314436
##
@@ -469,6 +591,17 @@ if [ "$RELEASE_PRE" == "false" ]; then
469591
echo
470592
fi
471593

594+
if [ "$need_update_commit" == "true" ]; then
595+
echo "Pushing version update commit..."
596+
git push
597+
new_tag_commit=$(git rev-parse HEAD)
598+
echo "New commit: $new_tag_commit"
599+
600+
echo "Moving tag $RELEASE_TAG to $new_tag_commit..."
601+
git tag -f "$RELEASE_TAG" "$new_tag_commit"
602+
git push --force origin "$RELEASE_TAG"
603+
fi
604+
472605
set +e
473606

474607
##

.github/scripts/update-version.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ echo "Updating issue template..."
3838
cat .github/ISSUE_TEMPLATE/Issue-report.yml | \
3939
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
4040

41+
echo "Updating GitLab variables..."
42+
cat .gitlab/workflows/common.yml | \
43+
sed "s/ESP_IDF_VERSION:.*/ESP_IDF_VERSION: \"$ESP_IDF_VERSION\"/g" | \
44+
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
45+
4146
echo "Updating platform.txt..."
4247
cat platform.txt | sed "s/version=.*/version=$ESP_ARDUINO_VERSION/g" > __platform.txt && mv __platform.txt platform.txt
4348

0 commit comments

Comments
 (0)