Skip to content

build

build #44

Workflow file for this run

# 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" ]
permissions:
contents: write
jobs:
build:
strategy:
matrix:
# Use these Java versions
java: [
17, # Current Java LTS & minimum supported by Minecraft
]
# and run on both Linux and macOS
os: [ubuntu-latest, macos-latest]
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: gradle clean build
run: ./gradlew clean build
- name: extract changelog
if: ${{ runner.os == 'Linux' && matrix.java == '17' && github.event.inputs.publish }} # only publish from one OS with latest Java
id: changelog
run: |
echo "changelog=$(./gradlew -q printChangelog)" >> "$GITHUB_OUTPUT"
- name: extract version number
if: ${{ runner.os == 'Linux' && matrix.java == '17' && github.event.inputs.publish }} # only publish from one OS with latest Java
id: version
run: |
echo "version=$(./gradlew -q printVersion)" >> "$GITHUB_OUTPUT"
- name: extract version display name
if: ${{ runner.os == 'Linux' && matrix.java == '17' && github.event.inputs.publish }} # only publish from one OS with latest Java
id: versionDisplay
run: |
echo "versionDisplay=$(./gradlew -q printVersionDisplay)" >> "$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 == 'Linux' && matrix.java == '17' && github.event.inputs.publish }} # only publish from one OS with latest Java
run: echo ${{ steps.version.outputs.version }}
- name: show changelog
if: ${{ runner.os == 'Linux' && matrix.java == '17' && github.event.inputs.publish }} # only publish from one OS with latest Java
run: echo "${{ steps.changelog.outputs.changelog }}"
continue-on-error: true
- 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
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.changelog.outputs.changelog }}
tag: ${{ steps.version.outputs.version }}
name: ${{ steps.versionDisplay.outputs.versionDisplay }}