From a501233230c26a0f670fd80a478f525c048519ce Mon Sep 17 00:00:00 2001 From: Christoph Thiede Date: Thu, 28 Dec 2023 20:02:23 +0100 Subject: [PATCH 1/6] Add support for configuring Squeak version and bitness --- .github/workflows/test.yml | 8 +++++++- README.md | 17 +++++++++++++++-- src/create_image.sh | 25 +++++++++++++++++++++---- test/test.st | 18 ++++++++++++++++++ test/test_local.sh | 25 +++++++++++++++++++++---- 5 files changed, 82 insertions(+), 11 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 2777501..fe65361 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -9,6 +9,10 @@ on: jobs: test: runs-on: ubuntu-latest + strategy: + matrix: + squeak-version: ['trunk', '6.0', '5.3'] + squeak-bitness: [64] # GitHub Actions only supports 64-bit Ubuntu https://github.com/actions/runner/issues/1181 steps: - uses: actions/checkout@v2 - uses: ./ @@ -16,5 +20,7 @@ jobs: with: prepare-script: test/prepare.st postpare-script: test/postpare.st + squeak-version: ${{ matrix.squeak-version }} + squeak-bitness: ${{ matrix.squeak-bitness }} - run: test/extract.sh "${{ steps.create-image.outputs.bundle-path }}" - - run: output/image/squeak.sh -headless "$(realpath test/test.st)" + - run: output/image/squeak.sh -headless "$(realpath test/test.st)" -- ${{ matrix.squeak-version }} ${{ matrix.squeak-bitness }} diff --git a/README.md b/README.md index 68b197f..bdffd07 100644 --- a/README.md +++ b/README.md @@ -8,8 +8,8 @@ You can use this action in your workflow to automatically deploy a **one-click/all-in-one image bundle of Squeak** containing **your app or modifications.** - The bundle is fetched from and will contain a **ready-to-use image** and **VM binaries** for all supported platforms (head over to [squeak-smalltalk/squeak-app](https://github.com/squeak-smalltalk/squeak-app) for more information). -- Currently, **only the latest version** of the Squeak [Trunk](http://source.squeak.org/trunk) is supported. -- Currently, only 64-bit binaries are supported. +- You can run **custom scripts** to **prepare** the image before saving it or to **postpare** it when it is opened again. +- You can choose the **Squeak version** and **bitness** of the image. ## Usage @@ -30,6 +30,7 @@ jobs: - uses: LinqLover/create-image@latest id: create-image with: + squeak-version: 6.0 prepare-script: ./scripts/prepareImage.st - uses: actions/upload-artifact@master with: @@ -58,6 +59,18 @@ MovingEyeMorph extraExampleSqueakIsWatchingYou openCenteredInWorld. Required? + + squeak-version + The version of Squeak to be used. + trunk, 6.0 + required + + + squeak-bitness + The bitness of the image to be created. Defaults to 64. + 64, 32 (⚠ currently not supported on GitHub Actions) + optional + prepare-script A script to be filed into the image before saving it. diff --git a/src/create_image.sh b/src/create_image.sh index af926e9..82873ef 100755 --- a/src/create_image.sh +++ b/src/create_image.sh @@ -2,6 +2,22 @@ set -eo pipefail # Read & validate inputs +if [[ -z "$SQUEAK_VERSION" ]]; then + echo "SQUEAK_VERSION is not set" + exit 1 +fi +squeakVersion="$SQUEAK_VERSION" +squeakBitness=64 +if [[ "$SQUEAK_BITNESS" ]]; then + if [[ "$SQUEAK_BITNESS" != 32 && "$SQUEAK_BITNESS" != 64 ]]; then + echo "SQUEAK_BITNESS must be 32 or 64" + exit 1 + fi + squeakBitness="$SQUEAK_BITNESS" +fi +if [[ "$squeakBitness" == 32 ]]; then + echo "WARNING: 32bit may not be supported on GitHub Actions" +fi if [[ "$PREPARE_SCRIPT" ]]; then prepareScript="$(realpath "$PREPARE_SCRIPT")" fi @@ -15,19 +31,20 @@ fileinScript="$(realpath "prepareImage.st")" mkdir -p ../output && cd ../output # Download and extract latest Trunk release -files_server="http://files.squeak.org/trunk" +files_server="http://files.squeak.org/$squeakVersion" files_index="files.html" wget -O "$files_index" "$files_server" -build="$(grep -P -o '(?<=a href=")Squeak[^<>]*?-64bit(?=\/")' "$files_index" | tail -1)" +build="$(grep -P -o "(?<=a href=\")Squeak[^<>]*?-${squeakBitness}bit(?=\/\")" "$files_index" | tail -1)" buildAio="$build-All-in-One.zip" +dir="$build-All-in-One/" wget "$files_server/$build/$buildAio" unzip \ - -d allInOne/ "$buildAio" \ + -d "$dir" "$buildAio" \ -x '*.mo' # skip superfluous localization files (optimization) echo "bundle-path=$(realpath "$buildAio")" >> "$GITHUB_OUTPUT" # Prepare image -cd allInOne +cd "$dir" if [[ "$CI" == true ]]; then VMOPTIONS="-headless" fi diff --git a/test/test.st b/test/test.st index f15ad8c..4faa6dd 100644 --- a/test/test.st +++ b/test/test.st @@ -1,3 +1,4 @@ +| arguments expectedVersion systemVersion actualVersion | "Make sure to handle errors properly" TranscriptStream redirectToStdOut: true. thisContext insertSender: (Context contextOn: UnhandledError, ProvideAnswerNotification do: [:ex | @@ -24,5 +25,22 @@ self description: 'test: image has already been tested'. Smalltalk globals at: #CIPrepareImageTestPostpared put: DateAndTime now. +arguments := Smalltalk arguments. +arguments first = '--' ifTrue: [arguments := arguments allButFirst]. "<= Squeak 5.3" +expectedVersion := arguments first. +systemVersion := SystemVersion current. +actualVersion :=systemVersion isAlpha + ifTrue: ['trunk'] + ifFalse: ['{1}.{2}' format: {systemVersion majorVersionNumber. systemVersion minorVersionNumber}]. +self + assert: actualVersion = expectedVersion + description: ('test: image version is {1} but expected {2}' format: {actualVersion. expectedVersion}). + +expectedBitness := arguments second asNumber. +actualBitness := Smalltalk image wordSize * 8. +self + assert: actualBitness = expectedBitness + description: ('test: image bitness is {1} but expected {2}' format: {actualBitness. expectedBitness}). + Transcript showln: 'All tests passed!!'. Smalltalk snapshot: false andQuit: true. diff --git a/test/test_local.sh b/test/test_local.sh index 5723c7b..1cf7389 100644 --- a/test/test_local.sh +++ b/test/test_local.sh @@ -3,7 +3,24 @@ # 🤞 Crossing fingers that this script will not become out of sync with the workflow file set -eo pipefail -output=$(PREPARE_SCRIPT=test/prepare.st POSTPARE_SCRIPT=test/postpare.st src/create_image.sh | tee /dev/tty) -bundlePath=$(echo "$output" | sed -n 's/.*::set-output name=bundle-path::\(.*\)/\1/p') -test/extract.sh "$bundlePath" -output/image/squeak.sh "$(realpath test/test.st)" +if [[ -z "$SQUEAK_VERSION" ]]; then + versions=(trunk 6.0 5.3) +else + versions=("$SQUEAK_VERSION") +fi +if [[ -z "$SQUEAK_BITNESS" ]]; then + bitnesses=(64) +else + bitnesses=("$SQUEAK_BITNESS") +fi + +for version in "${versions[@]}"; do + for bitness in "${bitnesses[@]}"; do + echo "Testing Squeak $version $bitness" + output=$(SQUEAK_VERSION="$version" SQUEAK_BITNESS="$bitness" PREPARE_SCRIPT=test/prepare.st POSTPARE_SCRIPT=test/postpare.st GITHUB_OUTPUT=/dev/stdout src/create_image.sh | tee /dev/tty) + bundlePath=$(echo "$output" | sed -n 's/.*bundle-path=\(.*\)/\1/p') + test/extract.sh "$bundlePath" + output/image/squeak.sh "$(realpath test/test.st)" -- "$version" "$bitness" + rm -rf output/image + done +done From 381bba96ff23e865126059e99937855a72d35fe4 Mon Sep 17 00:00:00 2001 From: Christoph Thiede Date: Thu, 28 Dec 2023 20:02:52 +0100 Subject: [PATCH 2/6] Automatically clean up temporary files --- src/create_image.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/create_image.sh b/src/create_image.sh index 82873ef..48397ad 100755 --- a/src/create_image.sh +++ b/src/create_image.sh @@ -59,3 +59,7 @@ zip \ -u -r \ "../$buildAio" . # TODO optimize: Ignore *.mo files here again (-x does not work) + +# Remove temporary files +cd .. +rm -rf "$dir" From 7cbc93b6d2ba87389808b7d9dd385252f03c431d Mon Sep 17 00:00:00 2001 From: Christoph Thiede Date: Thu, 28 Dec 2023 20:06:15 +0100 Subject: [PATCH 3/6] docs: reference https://github.com/actions/runner/issues/1181 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index bdffd07..7b6df57 100644 --- a/README.md +++ b/README.md @@ -68,7 +68,7 @@ MovingEyeMorph extraExampleSqueakIsWatchingYou openCenteredInWorld. squeak-bitness The bitness of the image to be created. Defaults to 64. - 64, 32 (⚠ currently not supported on GitHub Actions) + 64, 32 (⚠ currently not supported on GitHub Actions, see actions/runner#1181) optional From efef46edbf353a554755a5e150062c8bd69ef012 Mon Sep 17 00:00:00 2001 From: Christoph Thiede Date: Thu, 28 Dec 2023 20:09:30 +0100 Subject: [PATCH 4/6] Update action.yml --- action.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/action.yml b/action.yml index 498b1af..c9364ef 100644 --- a/action.yml +++ b/action.yml @@ -1,6 +1,13 @@ name: "Create Image" description: "Create and prepare a customized Squeak all-in-one image for the latest Trunk version of Squeak" inputs: + squeak-version: + description: "The version of Squeak to be used" + required: true + squeak-bitness: + description: "The bitness of the image to be created" + required: false + default: "64" prepare-script: description: "Path to `.st` file that will be executed before saving the image" required: false From 1e9bc2f9e225bb45b4b8943b615b0bb2ec0ffd97 Mon Sep 17 00:00:00 2001 From: Christoph Thiede Date: Thu, 28 Dec 2023 20:11:06 +0100 Subject: [PATCH 5/6] Propagate new inputs in action.yml --- action.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/action.yml b/action.yml index c9364ef..40b026b 100644 --- a/action.yml +++ b/action.yml @@ -34,5 +34,7 @@ runs: run: ${{ github.action_path }}/src/create_image.sh shell: bash env: + SQUEAK_VERSION: ${{ inputs.squeak-version }} + SQUEAK_BITNESS: ${{ inputs.squeak-bitness }} PREPARE_SCRIPT: ${{ inputs.prepare-script }} POSTPARE_SCRIPT: ${{ inputs.postpare-script }} From c40a5c3b8bc07e0528307b1e379a820c23aeae51 Mon Sep 17 00:00:00 2001 From: Christoph Thiede Date: Thu, 28 Dec 2023 20:23:34 +0100 Subject: [PATCH 6/6] reduce noise on stdout --- src/create_image.sh | 7 ++++--- test/extract.sh | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/create_image.sh b/src/create_image.sh index 48397ad..920b2cd 100755 --- a/src/create_image.sh +++ b/src/create_image.sh @@ -31,14 +31,15 @@ fileinScript="$(realpath "prepareImage.st")" mkdir -p ../output && cd ../output # Download and extract latest Trunk release +wgetArgs=(--progress=dot:giga) files_server="http://files.squeak.org/$squeakVersion" files_index="files.html" -wget -O "$files_index" "$files_server" +wget "${wgetArgs[@]}" -O "$files_index" "$files_server" build="$(grep -P -o "(?<=a href=\")Squeak[^<>]*?-${squeakBitness}bit(?=\/\")" "$files_index" | tail -1)" buildAio="$build-All-in-One.zip" dir="$build-All-in-One/" -wget "$files_server/$build/$buildAio" -unzip \ +wget "${wgetArgs[@]}" "$files_server/$build/$buildAio" +unzip -q \ -d "$dir" "$buildAio" \ -x '*.mo' # skip superfluous localization files (optimization) echo "bundle-path=$(realpath "$buildAio")" >> "$GITHUB_OUTPUT" diff --git a/test/extract.sh b/test/extract.sh index 9c604b0..cc562c4 100755 --- a/test/extract.sh +++ b/test/extract.sh @@ -11,7 +11,7 @@ test -n "$1" || error "invalid archive file" extracted="$output/image" mkdir -p "$extracted" -unzip "$1" -d "$extracted" +unzip -q "$1" -d "$extracted" ls "$extracted" test -f "$extracted/squeak.bat"