Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for configuring Squeak version and bitness #9

Merged
merged 6 commits into from
Dec 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,18 @@ 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: ./
id: create-image
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 }}
17 changes: 15 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://squeak.org/downloads> 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

Expand All @@ -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:
Expand Down Expand Up @@ -58,6 +59,18 @@ MovingEyeMorph extraExampleSqueakIsWatchingYou openCenteredInWorld.
<td>Required?</td>
</tr>
<tbody>
<tr>
<td><code>squeak-version</code></td>
<td>The version of Squeak to be used.</td>
<td><code>trunk</code>, <code>6.0</code></td>
<td><i>required</i></td>
</tr>
<tr>
<td><code>squeak-bitness</code></td>
<td>The bitness of the image to be created. Defaults to <code>64</code>.</td>
<td><code>64</code>, <code>32</code> (⚠ currently not supported on GitHub Actions, see <a href="https://github.com/actions/runner/issues/1181">actions/runner#1181</a>)</td>
<td><i>optional</i></td>
</tr>
<tr>
<td><code>prepare-script</code></td>
<td>A script to be filed into the image before saving it.</td>
Expand Down
9 changes: 9 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -27,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 }}
36 changes: 29 additions & 7 deletions src/create_image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -15,19 +31,21 @@ fileinScript="$(realpath "prepareImage.st")"
mkdir -p ../output && cd ../output

# Download and extract latest Trunk release
files_server="http://files.squeak.org/trunk"
wgetArgs=(--progress=dot:giga)
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)"
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"
wget "$files_server/$build/$buildAio"
unzip \
-d allInOne/ "$buildAio" \
dir="$build-All-in-One/"
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"

# Prepare image
cd allInOne
cd "$dir"
if [[ "$CI" == true ]]; then
VMOPTIONS="-headless"
fi
Expand All @@ -42,3 +60,7 @@ zip \
-u -r \
"../$buildAio" .
# TODO optimize: Ignore *.mo files here again (-x does not work)

# Remove temporary files
cd ..
rm -rf "$dir"
2 changes: 1 addition & 1 deletion test/extract.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
18 changes: 18 additions & 0 deletions test/test.st
Original file line number Diff line number Diff line change
@@ -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 |
Expand All @@ -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.
25 changes: 21 additions & 4 deletions test/test_local.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading