name: Release # Publish a mod build on every version tag. Every release carries both a # versioned jar and a stable `lovisual.jar`, so the site's one-click download # link (the site serves lovisual.jar from our own server) always resolves. on: push: tags: - 'v*' permissions: contents: write jobs: # A release made by hand through the API must not trigger a second build. check: runs-on: ubuntu-latest outputs: exists: ${{ steps.probe.outputs.exists }} steps: - id: probe env: API: ${{ github.server_url }}/api/v1/repos/${{ github.repository }} TAG: ${{ github.ref_name }} run: | code="$(curl -s -o /dev/null -w '%{http_code}' "$API/releases/tags/$TAG" || true)" if [ "$code" = "200" ]; then echo "exists=true" >>"$GITHUB_OUTPUT"; echo "Release $TAG already published, nothing to do."; else echo "exists=false" >>"$GITHUB_OUTPUT"; fi release: needs: check if: needs.check.outputs.exists != 'true' runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 with: fetch-depth: 0 - name: Set up JDK 25 uses: actions/setup-java@v4 with: distribution: temurin java-version: '25' - name: Grant the Gradle wrapper the exec bit working-directory: mod run: chmod +x ./gradlew - name: Build the mod working-directory: mod run: ./gradlew --no-daemon build - name: Collect the remapped jar id: jar run: | set -euo pipefail version="${GITHUB_REF_NAME#v}" jar="$(find mod/build/libs -maxdepth 1 -type f -name '*.jar' \ ! -name '*-sources.jar' ! -name '*-javadoc.jar' \ -printf '%s %p\n' | sort -rn | head -1 | cut -d' ' -f2-)" test -n "$jar" cp "$jar" lovisual-"$version".jar cp "$jar" lovisual.jar echo "version=$version" >>"$GITHUB_OUTPUT" echo "Packaged $jar as lovisual-$version.jar and lovisual.jar" # The repository lives on Forgejo, so the release goes through its API. # One-time setup: Settings > Actions > Secrets > RELEASE_TOKEN (an API # token with write access to this repository's releases). - name: Publish the Forgejo release env: TOKEN: ${{ secrets.RELEASE_TOKEN }} API: ${{ github.server_url }}/api/v1/repos/${{ github.repository }} TAG: ${{ github.ref_name }} VERSION: ${{ steps.jar.outputs.version }} run: | set -euo pipefail test -n "$TOKEN" || { echo "RELEASE_TOKEN secret is missing"; exit 1; } sha256sum lovisual.jar > lovisual.jar.sha256 prev="$(git describe --tags --abbrev=0 "$TAG^" 2>/dev/null || true)" range="${prev:+$prev..}$TAG" notes="$(git log --no-merges --pretty='- %s' "$range" | head -60)" body="$(python3 -c 'import json,sys; print(json.dumps({"tag_name":sys.argv[1],"name":sys.argv[1],"body":sys.argv[2]}))' "$TAG" "$notes")" id="$(curl -fsS -X POST "$API/releases" -H "Authorization: token $TOKEN" \ -H 'Content-Type: application/json' -d "$body" \ | python3 -c 'import json,sys; print(json.load(sys.stdin)["id"])')" for f in "lovisual-$VERSION.jar" lovisual.jar lovisual.jar.sha256; do curl -fsS -X POST "$API/releases/$id/assets?name=$f" -H "Authorization: token $TOKEN" \ -F "attachment=@$f" >/dev/null echo "uploaded $f" done