Set up autopublishing #27
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Automatically build the project and run any configured tests for every push | |
# and submitted pull request. This can help catch issues that only occur on | |
# certain platforms or Java versions, and provides a first line of defence | |
# against bad commits. | |
name: build | |
on: | |
workflow_dispatch: | |
inputs: | |
publish: | |
description: Publish to Modrinth, CurseForge and GitHub | |
required: true | |
default: "false" | |
patch: | |
description: Patch number, 0 for first | |
required: true | |
push: | |
branches: [ "main", "develop" ] | |
pull_request: | |
branches: [ "main", "develop" ] | |
jobs: | |
build: | |
strategy: | |
matrix: | |
# Use these Java versions | |
java: [ | |
17, # Current Java LTS & minimum supported by Minecraft | |
] | |
# and run on both Linux and Windows | |
os: [ubuntu-22.04, windows-2022] | |
runs-on: ${{ matrix.os }} | |
env: | |
PUBLISH_SUFFIX: snapshots | |
MODRINTH_TOKEN: ${{ secrets.MODRINTH_TOKEN }} | |
CURSEFORGE_TOKEN: ${{ secrets.CURSEFORGE_TOKEN }} | |
PATCH_NUMBER: ${{ github.event.inputs.patch }} | |
PUBLISHING: ${{ github.event.inputs.publish }} | |
steps: | |
- name: checkout repository | |
uses: actions/checkout@v3 | |
- name: validate gradle wrapper | |
uses: gradle/wrapper-validation-action@v1 | |
- name: setup jdk ${{ matrix.java }} | |
uses: actions/setup-java@v3 | |
with: | |
java-version: ${{ matrix.java }} | |
distribution: 'temurin' | |
cache: gradle | |
- name: make gradle wrapper executable | |
if: ${{ runner.os != 'Windows' }} | |
run: chmod +x ./gradlew | |
- name: extract version | |
if: ${{ runner.os != 'Windows' }} | |
id: getversion | |
run: | | |
echo "version=$(.github/scripts/extract_version.sh)" >> "$GITHUB_OUTPUT" | |
- name: gradle clean build | |
env: | |
VERSION_NAME: ${{ steps.getversion.outputs.version }} | |
run: ./gradlew clean build | |
- name: extract changelog | |
if: ${{ runner.os != 'Windows' }} | |
id: getchangelog | |
env: | |
VERSION_NAME: ${{ steps.getversion.outputs.version }} | |
run: | | |
echo "changelog=$(./gradlew -q printChangelog)" >> "$GITHUB_OUTPUT" | |
# windows throws an error if the second parameter for | |
# echo is not set, which it will never be, because it's | |
# only set for Linux | |
- name: show version | |
if: ${{ runner.os != 'Windows' }} | |
run: echo ${{ steps.getversion.outputs.version }} | |
- name: show changelog | |
if: ${{ runner.os != 'Windows' }} | |
run: echo "${{ steps.getchangelog.outputs.changelog }}" | |
continue-on-error: true | |
# - name: cache gradle files | |
# uses: actions/cache@v2 | |
# with: | |
# path: | | |
# ~/.gradle/caches | |
# ~/.gradle/loom-cache | |
# ~/.gradle/wrapper | |
# key: ${{ runner.os }}-gradle-${{ hashFiles('**/gradle-wrapper.properties') }} | |
# restore-keys: ${{ runner.os }}-gradle | |
- name: capture build artifacts | |
if: ${{ runner.os == 'Linux' && matrix.java == '17' }} # Only upload artifacts built from latest java on one OS | |
uses: actions/upload-artifact@v3 | |
with: | |
name: Artifacts | |
path: build/libs/ | |
# - name: publish to Modrinth and CurseForge | |
# env: | |
# VERSION_NAME: ${{ steps.getversion.outputs.version }} | |
# if: ${{ runner.os == 'Linux' && matrix.java == '17' && github.event.inputs.publish }} # only publish from one OS with latest Java | |
# run: ./gradlew publishMod | |
- name: create GitHub Release | |
if: ${{ runner.os == 'Linux' && matrix.java == '17' && github.event.inputs.publish }} # only publish from one OS with latest Java | |
uses: ncipollo/release-action@v1 | |
with: | |
artifacts: "LICENSE,build/libs/*.jar" | |
body: ${{ steps.getchangelog.outputs.changelog }} | |
tag: ${{ steps.getversion.outputs.version }} |