From 5ee25db5161b5a2355b104e73d29710b43554fc1 Mon Sep 17 00:00:00 2001 From: Dmitri Polchinski Date: Mon, 24 Feb 2025 02:07:40 +0400 Subject: [PATCH] ci: add native image build and release workflow --- .github/scripts/pre-release.sh | 16 ++++++++ .github/{ => scripts}/test.sh | 4 +- .github/workflows/ci.yml | 67 +++++++++++++++++++++++++++++++++- README.md | 2 +- project.scala | 3 +- 5 files changed, 87 insertions(+), 5 deletions(-) create mode 100755 .github/scripts/pre-release.sh rename .github/{ => scripts}/test.sh (75%) diff --git a/.github/scripts/pre-release.sh b/.github/scripts/pre-release.sh new file mode 100755 index 0000000..a089382 --- /dev/null +++ b/.github/scripts/pre-release.sh @@ -0,0 +1,16 @@ +#!/usr/bin/env bash + +set -euo pipefail + +releases=$1 +debug=${2:-} + +[[ -n "$debug" ]] && tree + +mkdir -p "$releases" +artifacts=(bf-x86_64-apple-darwin bf-x86_64-linux) + +for artifact in "${artifacts[@]}"; do + chmod +x "$artifact/bf" + tar cvfz "$releases/$artifact.tar.gz" "$artifact/bf" +done diff --git a/.github/test.sh b/.github/scripts/test.sh similarity index 75% rename from .github/test.sh rename to .github/scripts/test.sh index c82b674..0ad1dbc 100755 --- a/.github/test.sh +++ b/.github/scripts/test.sh @@ -12,9 +12,9 @@ if [ ! -f "$file" ]; then fi if [ -n "$input" ]; then - output=$(echo -n "$input" | scala-cli run . -q -- "$(cat "$file")") + output=$(echo -n "$input" | scala-cli run . -q -- "$(< "$file")") else - output=$(scala-cli run . -q -- "$(cat "$file")") + output=$(scala-cli run . -q -- "$(< "$file")") fi if [ "$output" = "$expected" ]; then diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index cb47151..e9207e3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -61,5 +61,70 @@ jobs: fi echo "Running examples/$name.b $input" - .github/test.sh "$name" "$expected" "$input" + .github/scripts/test.sh "$name" "$expected" "$input" done + + build-native: + strategy: + matrix: + os: [ macos-latest, ubuntu-latest ] + include: + - name: MacOS + os: macos-latest + artifact: bf-x86_64-apple-darwin + - name: Ubuntu + os: ubuntu-latest + artifact: bf-x86_64-linux + + name: Graal Build + runs-on: ${{ matrix.os }} + needs: [ test, example ] + + steps: + - uses: actions/checkout@v4 + - uses: coursier/cache-action@v6 + - uses: VirtusLab/scala-cli-setup@main + with: + power: true + + - name: Build + run: | + scala-cli --power package . -o ./out/bf --native-image \ + --graalvm-java-version 21 \ + --graalvm-version 21 \ + --graalvm-args "--verbose" \ + --graalvm-args "--no-fallback" \ + --graalvm-args "--native-image-info" \ + --graalvm-args "-H:+ReportExceptionStackTraces" \ + --graalvm-args "-H:-UseServiceLoaderFeature" + + - name: Upload artifacts + uses: actions/upload-artifact@v4 + with: + name: ${{ matrix.artifact }} + path: ./out/bf + if-no-files-found: error + retention-days: 1 + + release: + name: Release + runs-on: ubuntu-latest + needs: [ test, example, build-native ] + if: "startsWith(github.ref, 'refs/tags/')" + + steps: + - uses: actions/checkout@v4 + + - name: Download artifacts + uses: actions/download-artifact@v4 + + - name: Prepare release + run: .github/scripts/pre-release.sh releases + + - name: Release + uses: softprops/action-gh-release@v2 + with: + generate_release_notes: true + fail_on_unmatched_files: true + files: releases/* + token: ${{ secrets.GITHUB_TOKEN }} diff --git a/README.md b/README.md index 34843e0..fbb0a3a 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ scala-cli test . You can find example programs in the `examples/` directory and run them using: ```bash -scala-cli run . -- "$(cat path-to-example)" +scala-cli run . -- "$(< path-to-example)" ``` All examples are sourced from [wikipedia.org](https://en.wikipedia.org/wiki/Brainfuck#Examples) and [brainfuck.org](https://brainfuck.org/). diff --git a/project.scala b/project.scala index 3262b23..310af07 100644 --- a/project.scala +++ b/project.scala @@ -1,6 +1,7 @@ //> using scala "3.3.5" -//> using jvm 17 +//> using jvm 21 +//> using options -deprecation -feature -explain //> using options -Wunused:imports,implicits,privates -Werror //> using option -Ykind-projector