Skip to content

Release

Release #53

Workflow file for this run

# Inspired by & copied from JReleaser sample:
# https://github.com/aalmiray/q-cli/blob/main/.github/workflows/release.yml
name: Release
on:
workflow_dispatch:
inputs:
version:
description: "Release version"
required: true
next:
description: "Next version"
required: false
jobs:
version:
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v4.1.5
- name: Set up Java
uses: actions/setup-java@v4.2.1
with:
java-version: 17
distribution: 'adopt'
- name: Cache Maven packages
uses: actions/cache@v4.0.2
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2
- name: Set release version
id: version
run: |
RELEASE_VERSION=${{ github.event.inputs.version }}
NEXT_VERSION=${{ github.event.inputs.next }}
PLAIN_VERSION=`echo ${RELEASE_VERSION} | awk 'match($0, /^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)/) { print substr($0, RSTART, RLENGTH); }'`
COMPUTED_NEXT_VERSION="${PLAIN_VERSION}-SNAPSHOT"
if [ -z $NEXT_VERSION ]
then
NEXT_VERSION=$COMPUTED_NEXT_VERSION
fi
mvn -B versions:set versions:commit -DnewVersion=$RELEASE_VERSION
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config --global user.name "GitHub Action"
git commit -a -m "chore: Releasing version $RELEASE_VERSION"
git push origin HEAD:main
git rev-parse HEAD > HEAD
echo $RELEASE_VERSION > RELEASE_VERSION
echo $PLAIN_VERSION > PLAIN_VERSION
echo $NEXT_VERSION > NEXT_VERSION
- name: Upload version files
uses: actions/upload-artifact@v4.3.3
with:
name: artifacts
path: |
HEAD
*_VERSION
# Build native executable per runner
build:
needs: [ version ]
name: build-${{ matrix.os }}
strategy:
fail-fast: true
matrix:
os: [ ubuntu-latest, macOS-12, macOS-arm64-latest, windows-latest ]
gu-binary: [ gu, gu.cmd ]
exclude:
- os: ubuntu-latest
gu-binary: gu.cmd
- os: macOS-12
gu-binary: gu.cmd
- os: macos-arm64-latest
gu-binary: gu.cmd
- os: windows-latest
gu-binary: gu
runs-on: ${{ matrix.os }}
steps:
- name: Download all build artifacts
uses: actions/download-artifact@v4.1.7
- name: Read HEAD ref
id: head
uses: juliangruber/read-file-action@v1.1.7
with:
path: artifacts/HEAD
- name: Check out repository
uses: actions/checkout@v4.1.5
with:
ref: ${{ steps.head.outputs.content }}
# This action supports Windows; it does nothing on Linux and macOS.
- name: Add Developer Command Prompt for Microsoft Visual C++
uses: ilammy/msvc-dev-cmd@v1.13.0
- name: Setup GraalVM
uses: graalvm/setup-graalvm@v1.2.1
with:
distribution: 'graalvm'
java-version: 17
components: 'native-image'
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Get musl toolchain and compile libz against it
id: prepare-musl
run: |
TMP_DIR=$(mktemp -d)
pushd $TMP_DIR
curl -LOJ http://more.musl.cc/10/x86_64-linux-musl/x86_64-linux-musl-native.tgz
tar -xvf x86_64-linux-musl-native.tgz
curl -LOJ https://zlib.net/fossils/zlib-1.3.tar.gz
tar -xzf zlib-1.3.tar.gz
cd zlib-1.3
TOOLCHAIN_DIR=$TMP_DIR/x86_64-linux-musl-native
CC=$TOOLCHAIN_DIR/bin/gcc
./configure --prefix=$TOOLCHAIN_DIR --static
make
make install
echo "TOOLCHAIN_DIR=$TOOLCHAIN_DIR" >> $GITHUB_OUTPUT
if: matrix.os == 'ubuntu-latest'
- name: Cache Maven packages
uses: actions/cache@v4.0.2
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2
- name: Build static native image for Linux
run: |
PATH=${TOOLCHAIN_DIR}/bin:$PATH; mvn -B -Pnative package
env:
TOOLCHAIN_DIR: ${{ steps.prepare-musl.outputs.TOOLCHAIN_DIR }}
if: matrix.os == 'ubuntu-latest'
- name: Build static native image for Windows / macOS
run: |
mvn -B -Pnative package
if: matrix.os != 'ubuntu-latest'
- name: Create distribution
run: mvn -B -Pdist package -DskipTests
- name: Upload build artifacts
uses: actions/upload-artifact@v4.3.3
with:
name: artifacts-${{ matrix.os }}
path: |
target/distributions/*.zip
target/distributions/*.tar.gz
# Collect all executables and release
release:
needs: [ build ]
runs-on: ubuntu-latest
permissions: write-all
steps:
# must read HEAD before checkout
- name: Download all build artifacts
uses: actions/download-artifact@v4.1.7
- name: Read HEAD ref
id: head
uses: juliangruber/read-file-action@v1.1.7
with:
path: artifacts/HEAD
- name: Read versions
id: version
run: |
RELEASE_VERSION=`cat artifacts/RELEASE_VERSION`
PLAIN_VERSION=`cat artifacts/PLAIN_VERSION`
NEXT_VERSION=`cat artifacts/NEXT_VERSION`
echo "RELEASE_VERSION = $RELEASE_VERSION"
echo "PLAIN_VERSION = $PLAIN_VERSION"
echo "NEXT_VERSION = $NEXT_VERSION"
echo "RELEASE_VERSION=$RELEASE_VERSION" >> $GITHUB_OUTPUT
echo "PLAIN_VERSION=$PLAIN_VERSION" >> $GITHUB_OUTPUT
echo "NEXT_VERSION=$NEXT_VERSION" >> $GITHUB_OUTPUT
- name: Check out repository
uses: actions/checkout@v4.1.5
with:
fetch-depth: 0
- name: Check out correct Git ref
run: git checkout ${{ steps.head.outputs.content }}
# checkout will clobber downloaded artifacts; we have to download them again
- name: Download all build artifacts
uses: actions/download-artifact@v4.1.7
with:
path: /tmp/artifacts
- name: Move build artifacts to correct folder
run: |
targets=("ubuntu-latest" "macOS-latest" "macOS-arm64-latest" "windows-latest")
mkdir -p artifacts
find /tmp/artifacts/ -name "mcs*" -exec mv -v {} artifacts/ \;
- name: Set up Java
uses: actions/setup-java@v4.2.1
with:
java-version: 17
distribution: 'adopt'
- name: Cache Maven packages
uses: actions/cache@v4.0.2
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2
- name: Release with JReleaser
run: mvn -B -Prelease -DartifactsDir=artifacts jreleaser:full-release
env:
JRELEASER_GITHUB_TOKEN: ${{ secrets.GH_PAT }}
JRELEASER_HOMEBREW_GITHUB_TOKEN: ${{ secrets.GH_PAT }}
JRELEASER_SNAP_GITHUB_TOKEN: ${{ secrets.GH_PAT }}
JRELEASER_CHOCOLATEY_GITHUB_TOKEN: ${{ secrets.GH_PAT }}
JRELEASER_SCOOP_GITHUB_TOKEN: ${{ secrets.GH_PAT }}
JRELEASER_SDKMAN_CONSUMER_KEY: ${{ secrets.JRELEASER_SDKMAN_CONSUMER_KEY }}
JRELEASER_SDKMAN_CONSUMER_TOKEN: ${{ secrets.JRELEASER_SDKMAN_CONSUMER_TOKEN }}
JRELEASER_TWITTER_CONSUMER_KEY: ${{ secrets.JRELEASER_TWITTER_CONSUMER_KEY }}
JRELEASER_TWITTER_CONSUMER_SECRET: ${{ secrets.JRELEASER_TWITTER_CONSUMER_SECRET }}
JRELEASER_TWITTER_ACCESS_TOKEN: ${{ secrets.JRELEASER_TWITTER_ACCESS_TOKEN }}
JRELEASER_TWITTER_ACCESS_TOKEN_SECRET: ${{ secrets.JRELEASER_TWITTER_ACCESS_TOKEN_SECRET }}
JRELEASER_MASTODON_ACCESS_TOKEN: ${{ secrets.JRELEASER_MASTODON_ACCESS_TOKEN }}
JRELEASER_BLUESKY_PASSWORD: ${{ secrets.JRELEASER_BLUESKY_PASSWORD }}
- name: Capture JReleaser output
if: always()
uses: actions/upload-artifact@v4.3.3
with:
name: jreleaser-release-output
retention-days: 7
path: |
target/jreleaser/trace.log
target/jreleaser/output.properties
- name: Set next version
env:
NEXT_VERSION: ${{ steps.version.outputs.NEXT_VERSION }}
run: |
mvn -B versions:set versions:commit -DnewVersion=$NEXT_VERSION
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config --global user.name "GitHub Action"
git commit -a -m "chore: Prepare next version: $NEXT_VERSION"
git push origin HEAD:main