88 lines
3.3 KiB
YAML
88 lines
3.3 KiB
YAML
# On every push to master, publish a Gitea release for the pom.xml version if one
|
|
# does not exist yet. "Version changed" == "no release tagged v<version> yet", which
|
|
# also covers multi-commit pushes, force pushes and re-runs after a failed upload.
|
|
#
|
|
# Assets: target/sopa-<v>.zip (self-contained distribution) and
|
|
# target/sopa-<v>-shaded.jar (fat jar). The plain jar is not uploaded.
|
|
name: release
|
|
|
|
on:
|
|
push:
|
|
branches: [master]
|
|
|
|
concurrency:
|
|
group: release
|
|
cancel-in-progress: false
|
|
|
|
env:
|
|
MAVEN_VERSION: 3.9.11
|
|
API: ${{ github.server_url }}/api/v1/repos/${{ github.repository }}
|
|
# The automatic token can create releases on current Gitea; set a RELEASE_TOKEN
|
|
# secret (PAT with write:repository) if yours refuses it.
|
|
TOKEN: ${{ secrets.RELEASE_TOKEN || github.token }}
|
|
|
|
jobs:
|
|
release:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
|
|
- uses: actions/setup-java@v4
|
|
with:
|
|
distribution: temurin
|
|
java-version: '21'
|
|
cache: maven
|
|
|
|
- name: Install Maven
|
|
run: |
|
|
curl -fsSL "https://archive.apache.org/dist/maven/maven-3/${MAVEN_VERSION}/binaries/apache-maven-${MAVEN_VERSION}-bin.tar.gz" \
|
|
| tar -xz -C "$RUNNER_TEMP"
|
|
echo "$RUNNER_TEMP/apache-maven-${MAVEN_VERSION}/bin" >> "$GITHUB_PATH"
|
|
|
|
- name: Check whether this version is already released
|
|
id: version
|
|
run: |
|
|
VERSION=$(mvn -B -q help:evaluate -Dexpression=project.version -DforceStdout)
|
|
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
|
|
STATUS=$(curl -s -o /dev/null -w '%{http_code}' \
|
|
-H "Authorization: token $TOKEN" "$API/releases/tags/v$VERSION")
|
|
case "$STATUS" in
|
|
404) echo "release=true" >> "$GITHUB_OUTPUT"; echo "v$VERSION is new, releasing." ;;
|
|
200) echo "release=false" >> "$GITHUB_OUTPUT"; echo "v$VERSION already released, skipping." ;;
|
|
*) echo "Unexpected HTTP $STATUS from release lookup"; exit 1 ;;
|
|
esac
|
|
|
|
# The Liberica JDKs (~700 MB) the pom downloads for jlink.
|
|
- name: Cache distribution JDKs
|
|
if: steps.version.outputs.release == 'true'
|
|
uses: actions/cache@v4
|
|
with:
|
|
path: .jdks
|
|
key: jdks-${{ hashFiles('pom.xml') }}
|
|
restore-keys: jdks-
|
|
|
|
- name: Build
|
|
if: steps.version.outputs.release == 'true'
|
|
run: mvn -B package
|
|
|
|
- name: Create release and upload assets
|
|
if: steps.version.outputs.release == 'true'
|
|
env:
|
|
VERSION: ${{ steps.version.outputs.version }}
|
|
run: |
|
|
ZIP="target/sopa-$VERSION.zip"
|
|
JAR="target/sopa-$VERSION-shaded.jar"
|
|
test -f "$ZIP" && test -f "$JAR"
|
|
|
|
BODY=$(jq -n --arg tag "v$VERSION" --arg sha "$GITHUB_SHA" \
|
|
'{tag_name: $tag, target_commitish: $sha, name: $tag, draft: false, prerelease: false}')
|
|
ID=$(curl -fsS -X POST -H "Authorization: token $TOKEN" -H "Content-Type: application/json" \
|
|
-d "$BODY" "$API/releases" | jq -r .id)
|
|
echo "Created release $ID"
|
|
|
|
for f in "$ZIP" "$JAR"; do
|
|
curl -fsS -X POST -H "Authorization: token $TOKEN" \
|
|
-F "attachment=@$f" "$API/releases/$ID/assets?name=$(basename "$f")" > /dev/null
|
|
echo "Uploaded $(basename "$f")"
|
|
done
|