chore: setup ci #27
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
--- | |
name: Lifecycle | |
"on": | |
push: | |
branches: | |
- main | |
pull_request: | |
types: | |
- closed | |
- opened | |
- synchronize | |
- reopened | |
workflow_dispatch: | |
inputs: | |
versions: | |
description: Comma-delimited mc versions to build and run (i.e. 1.20.4,1.21) | |
default: "all" | |
ref: | |
description: Git ref to checkout before build (i.e. my-feature-branch ) | |
default: "main" | |
concurrency: # FIXME: prevent release commit cancellation | |
group: > | |
${{ github.workflow }}- | |
${{ github.event_name }}- | |
${{ github.event.inputs.ref || github.ref }} | |
cancel-in-progress: true | |
jobs: | |
testbuild: | |
name: TestBuild | |
runs-on: blacksmith-2vcpu-ubuntu-2204 | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 1 | |
- if: steps.cache.outputs.cache-hit != 'true' | |
name: Setup Java 8 | |
uses: useblacksmith/setup-java@v5 | |
with: | |
distribution: temurin | |
java-version: 8 | |
- if: steps.cache.outputs.cache-hit != 'true' | |
name: Setup Java 16 | |
uses: useblacksmith/setup-java@v5 | |
with: | |
distribution: temurin | |
java-version: 16 | |
- if: steps.cache.outputs.cache-hit != 'true' | |
name: Setup Java 17 | |
uses: useblacksmith/setup-java@v5 | |
with: | |
distribution: temurin | |
java-version: 17 | |
- if: steps.cache.outputs.cache-hit != 'true' | |
name: Setup Java 21 | |
uses: useblacksmith/setup-java@v5 | |
with: | |
distribution: temurin | |
java-version: 21 | |
- if: steps.cache.outputs.cache-hit != 'true' | |
name: Setup Gradle | |
uses: useblacksmith/setup-gradle/setup-gradle@v6 | |
with: | |
cache-read-only: false | |
build-scan-publish: true | |
build-scan-terms-of-use-url: https://gradle.com/terms-of-service | |
build-scan-terms-of-use-agree: true | |
- if: | | |
steps.cache.outputs.cache-hit != 'true' | |
&& !inputs.release | |
name: Gradle build | |
run: > | |
./gradlew build --stacktrace | |
- name: Upload artifacts | |
uses: actions/upload-artifact@v4 | |
with: | |
name: jars | |
path: | | |
**/build/libs/*.jar | |
release-please: | |
name: Release Please | |
if: github.event_name == 'fake' # FIXME: remove, testing purposes | |
runs-on: blacksmith-2vcpu-ubuntu-2204 | |
outputs: | |
release_created: ${{ steps.release-please.outputs.release_created }} | |
tag_name: ${{ steps.release-please.outputs.tag_name }} | |
permissions: | |
contents: write | |
pull-requests: write | |
steps: | |
- if: github.event_name == 'push' # TODO: explicit on push to main | |
id: release-please | |
name: Run Release Please | |
uses: googleapis/release-please-action@v4 | |
with: | |
token: ${{ secrets.GITHUB_TOKEN }} | |
matrices: | |
if: github.event.action != 'closed' | |
name: Construct matrices | |
needs: release-please | |
runs-on: blacksmith-2vcpu-ubuntu-2204 | |
outputs: | |
build-matrix: ${{ steps.matrices.outputs.build-matrix }} | |
run-matrix: ${{ steps.matrices.outputs.run-matrix }} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 1 | |
ref: ${{ inputs.ref || github.ref }} | |
- if: github.event_name != 'workflow_dispatch' | |
id: paths | |
name: Get paths | |
run: | | |
{ delimiter="$(openssl rand -hex 8)" | |
echo "filter<<${delimiter}" | |
for dir in $(find . -maxdepth 1 -type d -not -path "./.git*" -print | cut -d/ -f2-); do | |
echo "'$dir' : ['$dir/**']" | |
done; echo "${delimiter}"; } >> "${GITHUB_OUTPUT}" | |
echo "${GITHUB_OUTPUT}" | |
cat "${GITHUB_OUTPUT}" || true | |
- if: github.event_name != 'workflow_dispatch' | |
id: filter | |
name: Filter | |
uses: dorny/[email protected] | |
with: | |
filters: | | |
${{ steps.paths.outputs.filter }} | |
# TODO: if only README, LICENSE, .gitignore changed we do not need to run MC | |
- id: matrices # TODO: build origin matrices dynamically, consider collapsing this into a .py | |
name: Construct matrices | |
run: | | |
import os | |
import json | |
build_matrix = {"include": []} | |
run_matrix = {"version": []} | |
build_data = [ | |
# we need to build everything with java >= 11 for manifold, it gets compiled to java 8 | |
# for now no api builds {"mc": "api", "java": "8"}, | |
{"mc": "1.21.3", "lex": "53.0.7", "neo": "11-beta", "java": "21"}, | |
{"mc": "1.21.1", "lex": "52.0.2", "neo": "4", "java": "21"}, | |
{"mc": "1.21", "lex": "51.0.24", "neo": "96-beta", "java": "21"}, | |
{"mc": "1.20.6", "lex": "50.1.10", "neo": "119", "java": "21"}, | |
{"mc": "1.20.4", "lex": "49.0.38", "neo": "219", "java": "21"}, | |
{"mc": "1.20.3", "lex": "49.0.2", "neo": "8-beta", "java": "21"}, | |
{"mc": "1.20.2", "lex": "48.1.0", "neo": "88", "java": "21"}, | |
{"mc": "1.20.1", "lex": "47.2.23", "java": "21"}, | |
{"mc": "1.19.4", "lex": "45.2.9", "java": "21"}, | |
{"mc": "1.19.3", "lex": "44.1.23", "java": "21"}, | |
{"mc": "1.19.2", "lex": "43.3.9", "java": "21"}, | |
{"mc": "1.19.1", "lex": "42.0.9", "java": "21"}, | |
{"mc": "1.19", "lex": "41.1.0", "java": "21"}, | |
{"mc": "1.18.2", "lex": "40.2.18", "java": "21"}, | |
{"mc": "1.17.1", "lex": "37.1.1", "java": "16"}, | |
{"mc": "1.16.5", "lex": "36.2.42", "java": "21"}, | |
{"mc": "1.12.2", "lex": "14.23.5.2860", "java": "21"}, | |
{"mc": "1.8.9", "lex": "11.15.1.2318-1.8.9", "java": "21"}, | |
{"mc": "1.7.10", "lex": "10.13.4.1614-1.7.10", "java": "21"} | |
] | |
run_data = [ | |
{"mc": "1.21.3", "type": "lexforge", "modloader": "forge", "regex": ".*forge.*", "java": "21"}, | |
{"mc": "1.21.3", "type": "neoforge", "modloader": "neoforge", "regex": ".*neoforge.*", "java": "21"}, | |
{"mc": "1.21.3", "type": "fabric", "modloader": "fabric", "regex": ".*fabric.*", "java": "21"}, | |
{"mc": "1.21.1", "type": "lexforge", "modloader": "forge", "regex": ".*forge.*", "java": "21"}, | |
{"mc": "1.21.1", "type": "neoforge", "modloader": "neoforge", "regex": ".*neoforge.*", "java": "21"}, | |
{"mc": "1.21.1", "type": "fabric", "modloader": "fabric", "regex": ".*fabric.*", "java": "21"}, | |
{"mc": "1.21", "type": "lexforge", "modloader": "forge", "regex": ".*forge.*", "java": "21"}, | |
{"mc": "1.21", "type": "neoforge", "modloader": "neoforge", "regex": ".*neoforge.*", "java": "21"}, | |
{"mc": "1.21", "type": "fabric", "modloader": "fabric", "regex": ".*fabric.*", "java": "21"}, | |
{"mc": "1.20.6", "type": "lexforge", "modloader": "forge", "regex": ".*forge.*", "java": "21"}, | |
{"mc": "1.20.6", "type": "neoforge", "modloader": "neoforge", "regex": ".*neoforge.*", "java": "21"}, | |
{"mc": "1.20.6", "type": "fabric", "modloader": "fabric", "regex": ".*fabric.*", "java": "21"}, | |
{"mc": "1.20.4", "type": "lexforge", "modloader": "forge", "regex": ".*forge.*", "java": "17"}, | |
{"mc": "1.20.4", "type": "neoforge", "modloader": "neoforge", "regex": ".*neoforge.*", "java": "17"}, | |
{"mc": "1.20.4", "type": "fabric", "modloader": "fabric", "regex": ".*fabric.*", "java": "17"}, | |
{"mc": "1.20.3", "type": "lexforge", "modloader": "forge", "regex": ".*forge.*", "java": "17"}, | |
{"mc": "1.20.3", "type": "neoforge", "modloader": "neoforge", "regex": ".*neoforge.*", "java": "17"}, | |
{"mc": "1.20.3", "type": "fabric", "modloader": "fabric", "regex": ".*fabric.*", "java": "17"}, | |
{"mc": "1.20.2", "type": "lexforge", "modloader": "forge", "regex": ".*forge.*", "java": "17"}, | |
{"mc": "1.20.2", "type": "neoforge", "modloader": "neoforge", "regex": ".*neoforge.*", "java": "17"}, | |
{"mc": "1.20.2", "type": "fabric", "modloader": "fabric", "regex": ".*fabric.*", "java": "17"}, | |
{"mc": "1.20.1", "type": "lexforge", "modloader": "forge", "regex": ".*forge.*", "java": "17"}, | |
{"mc": "1.20.1", "type": "fabric", "modloader": "fabric", "regex": ".*fabric.*", "java": "17"}, | |
{"mc": "1.19.4", "type": "fabric", "modloader": "fabric", "regex": ".*fabric.*", "java": "17"}, | |
{"mc": "1.19.4", "type": "lexforge", "modloader": "forge", "regex": ".*forge.*", "java": "17"}, | |
{"mc": "1.19.3", "type": "fabric", "modloader": "fabric", "regex": ".*fabric.*", "java": "17"}, | |
{"mc": "1.19.3", "type": "lexforge", "modloader": "forge", "regex": ".*forge.*", "java": "17"}, | |
{"mc": "1.19.2", "type": "fabric", "modloader": "fabric", "regex": ".*fabric.*", "java": "17"}, | |
{"mc": "1.19.2", "type": "lexforge", "modloader": "forge", "regex": ".*forge.*", "java": "17"}, | |
{"mc": "1.19.1", "type": "fabric", "modloader": "fabric", "regex": ".*fabric.*", "java": "17"}, | |
{"mc": "1.19.1", "type": "lexforge", "modloader": "forge", "regex": ".*forge.*", "java": "17"}, | |
{"mc": "1.19", "type": "fabric", "modloader": "fabric", "regex": ".*fabric.*", "java": "17"}, | |
{"mc": "1.19", "type": "lexforge", "modloader": "forge", "regex": ".*forge.*", "java": "17"}, | |
{"mc": "1.18.2", "type": "fabric", "modloader": "fabric", "regex": ".*fabric.*", "java": "17"}, | |
{"mc": "1.18.2", "type": "lexforge", "modloader": "forge", "regex": ".*forge.*", "java": "17"}, | |
{"mc": "1.17.1", "type": "fabric", "modloader": "fabric", "regex": ".*fabric.*", "java": "16"}, | |
{"mc": "1.17.1", "type": "lexforge", "modloader": "forge", "regex": ".*forge.*", "java": "16"}, | |
{"mc": "1.16.5", "type": "fabric", "modloader": "fabric", "regex": ".*fabric.*", "java": "8"}, | |
{"mc": "1.16.5", "type": "lexforge", "modloader": "forge", "regex": ".*forge.*", "java": "8"}, | |
{"mc": "1.12.2", "type": "lexforge", "modloader": "forge", "regex": ".*forge.*", "java": "8"}, | |
{"mc": "1.8.9", "type": "lexforge", "modloader": "forge", "regex": ".*orge.*", "java": "8"}, | |
{"mc": "1.7.10", "type": "lexforge", "modloader": "forge", "regex": ".*orge.*", "java": "8"} | |
] | |
versions_to_run = [] | |
match os.getenv('GITHUB_EVENT_NAME'): | |
case 'pull_request': | |
if "${{ steps.filter.outcome }}" == "success": | |
# TODO: if only README or LICENSE changed, no need to run all versions! | |
# dirs_to_filter = json.loads('${{ steps.filter.outputs.changes }}') | |
versions_to_run = ['all'] | |
case 'workflow_dispatch': | |
input_versions = '${{ github.event.inputs.versions }}' | |
print(input_versions) | |
if input_versions == 'all': | |
# If "all" is specified in the input, run all possible builds and runs | |
versions_to_run = ['all'] | |
else: | |
# Otherwise, filter based on the versions listed in the input | |
versions_to_run = [item.strip() for item in input_versions.split(',')] | |
case 'push': | |
if '${{ needs.release-please.outputs.release_created }}' == 'true': | |
# If a release is created, use the full matrices | |
versions_to_run = ['all'] | |
if 'all' in versions_to_run: | |
build_matrix['include'], run_matrix['version'] = build_data, run_data | |
else: | |
build_matrix['include'].extend([item for item in build_data if item["mc"] in versions_to_run]) | |
run_matrix['version'].extend([item for item in run_data if item["mc"] in versions_to_run]) | |
with open(os.environ['GITHUB_OUTPUT'], 'a') as fh: | |
print(json.dumps(build_matrix, indent=2)) | |
fh.write(f'build-matrix={json.dumps(build_matrix)}\n') | |
print(json.dumps(run_matrix, indent=2)) | |
fh.write(f'run-matrix={json.dumps(run_matrix)}\n') | |
shell: python {0} | |
build: | |
if: fromJSON(needs.matrices.outputs.build-matrix).include[0] != null | |
name: Build | |
needs: matrices | |
strategy: | |
fail-fast: false | |
matrix: | |
${{ insert }}: ${{ fromJSON(needs.matrices.outputs.build-matrix) }} | |
uses: ./.github/workflows/flex-build.yml | |
with: | |
mc: ${{ matrix.mc }} | |
lex: ${{ matrix.lex }} | |
neo: ${{ matrix.neo }} | |
java: ${{ matrix.java }} | |
run: | |
if: github.event_name != 'push' | |
name: Run tests | |
needs: | |
- matrices | |
- build | |
runs-on: blacksmith-2vcpu-ubuntu-2204 | |
strategy: | |
fail-fast: false | |
matrix: | |
${{ insert }}: ${{ fromJSON(needs.matrices.outputs.run-matrix) }} | |
xvfb: [true, false] | |
steps: | |
- name: Checkout # TODO: simplify away this step, currently needed for `uses: ./` | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 1 | |
- name: Download artifact | |
uses: actions/download-artifact@v4 | |
with: | |
name: jars-${{ matrix.version.mc }} | |
- name: Bootstrap mods | |
run: | | |
mkdir -p run/mods | |
cp mc-runtime-test-*-${{ matrix.version.type }}-release.jar run/mods | |
- name: Setup Java temurin-${{ matrix.version.java }} | |
uses: useblacksmith/setup-java@v5 | |
with: | |
java-version: ${{ matrix.version.java }} | |
distribution: temurin | |
- name: Run game | |
timeout-minutes: 3 | |
uses: headlesshq/[email protected] | |
with: | |
mc: ${{ matrix.version.mc }} | |
mc-runtime-test: none | |
modloader: ${{ matrix.version.modloader }} | |
regex: ${{ matrix.version.regex }} | |
java: ${{ matrix.version.java }} | |
xvfb: ${{ matrix.xvfb }} | |
headlessmc-command: ${{ !matrix.xvfb && '-lwjgl' || '' }} --retries 3 --jvm -Djava.awt.headless=true | |
release: | |
if: needs.release-please.outputs.release_created == 'true' | |
needs: | |
- release-please | |
- build | |
name: Release | |
permissions: | |
contents: write | |
runs-on: blacksmith-2vcpu-ubuntu-2204 | |
steps: | |
- name: Download artifacts | |
uses: actions/download-artifact@v4 | |
- name: Upload release artifacts | |
uses: svenstaro/upload-release-action@v2 | |
with: | |
repo_token: ${{ secrets.GITHUB_TOKEN }} | |
file: jars-*/*-release.jar | |
tag: ${{ needs.release-please.outputs.tag_name }} | |
overwrite: true | |
file_glob: true | |
- name: Upload api artifacts | |
uses: svenstaro/upload-release-action@v2 | |
with: | |
repo_token: ${{ secrets.GITHUB_TOKEN }} | |
file: jars-*/*-api-*.jar # TODO: make API jar names consistent with release jars, then simplify away this step | |
tag: ${{ needs.release-please.outputs.tag_name }} | |
overwrite: true | |
file_glob: true | |
clean: # TODO: run this conditionally per #22 | |
name: Clean up | |
needs: | |
- run | |
- release | |
runs-on: blacksmith-2vcpu-ubuntu-2204 | |
steps: | |
- name: Delete artifacts | |
uses: geekyeggo/[email protected] | |
with: | |
name: | | |
jars-* | |
failOnError: false |