Skip to content

Publish JFLib

Publish JFLib #5

Workflow file for this run

name: Publish
run-name: Publish JFLib
on:
workflow_dispatch:
inputs:
changelogHeader:
description: 'Message to place at the top of the changelog.'
required: false
type: string
lastTagOverride:
description: 'Previous tag for changelog generation'
required: false
type: string
permissions:
packages: write
contents: write
jobs:
publish:
strategy:
matrix:
java: [21]
os: [ubuntu-22.04]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout Repo
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up JDK${{ matrix.java }}
uses: actions/setup-java@v4
with:
java-version: ${{ matrix.java }}
distribution: 'temurin'
- name: setup gradle
uses: gradle/gradle-build-action@v2.12.0
with:
gradle-home-cache-includes: |
caches
notifications
loom-cache
- name: make gradle wrapper executable
if: ${{ runner.os != 'Windows' }}
run: chmod +x ./gradlew
- name: Pull Mod Version
id: pull-new-version
run: |
grep 'module_version=' gradle.properties | sed 's/module_version=/new_tag=v/g' >> $GITHUB_OUTPUT
- name: Set previous tag from override
if: ${{ inputs.lastTagOverride != null }}
run: |
if git show-ref --tags --verify --quiet "refs/tags/${{ inputs.lastTagOverride }}"; then
echo "lastTagOverride exists"
exit 0
else
echo "lastTagOverride doesn't exist, failing"
exit 1
fi
echo "PREVIOUS_TAG=${{ inputs.lastTagOverride }}" >> "$GITHUB_ENV"
- name: Set previous tag from git history
if: ${{ inputs.lastTagOverride == null }}
run: |
previous=`git describe --tags --abbrev=0`
if [ $previous ]; then
echo "PREVIOUS_TAG=$previous" >> "$GITHUB_ENV"
else
echo "PREVIOUS_TAG=NONE" >> "$GITHUB_ENV"
fi
- id: new-tag-generator
name: Format new tag from input and branch
run: |
branch=$(git rev-parse --abbrev-ref HEAD)
newTag=${{ steps.pull-new-version.outputs.new_tag }}+$branch
echo "NEW_TAG=$newTag" >> "$GITHUB_ENV"
echo "NEW_TAG=$newTag" >> "$GITHUB_OUTPUT"
- name: Check new version doesn't exist
run: |
if git show-ref --tags --verify --quiet "refs/tags/${{ steps.new-tag-generator.outputs.NEW_TAG }}"; then
echo "newTag already exists, failing"
exit 1
else
echo "newTag doesn't exist"
exit 0
fi
- name: Output build spec
run: |
echo "Previous: $PREVIOUS_TAG"
echo "New: $NEW_TAG"
- name: Create version tag
uses: actions/github-script@v6
with:
script: |
github.rest.git.createRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: "refs/tags/${{ steps.new-tag-generator.outputs.NEW_TAG }}",
sha: context.sha
})
- name: Fetch new tag for changelog generation
run: git fetch --tags
- name: build & run tests
run: ./gradlew check build
- name: Publish to GitHub Packages and GitHub Release
run: ./gradlew publish githubRelease -PchangelogHeaderAddon="${{ inputs.changelogHeader }}"
env:
RELEASE: true
GITHUB_ACTOR: ${{ secrets.GITHUB_ACTOR }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Capture build artifacts
if: ${{ runner.os == 'Linux' }}
uses: actions/upload-artifact@v4
with:
name: Artifacts
path: |
build/libs/