Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
hu-ja-ja committed Feb 13, 2025
2 parents 53e5412 + 8cabe4e commit bf18594
Show file tree
Hide file tree
Showing 53 changed files with 226 additions and 404 deletions.
41 changes: 22 additions & 19 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,9 @@ on:
type: boolean
required: false
default: false
target_subproject:
description: see release.yml, leave it empty to build all
type: string
required: false
default: ''

jobs:

build:
runs-on: ubuntu-latest

Expand All @@ -36,29 +32,39 @@ jobs:
restore-keys: |
${{ runner.os }}-gradle-
- name: Read common properties
id: properties_g
uses: christian-draeger/read-properties@1.1.1
with:
path: gradle.properties
properties: 'mod_name mod_version'

- name: Build with gradle
run: |
chmod +x gradlew
if [ -z "${{ inputs.target_subproject }}" ]; then
echo "Building all subprojects"
./gradlew build-all
else
args=$(echo "${{ inputs.target_subproject }}" | tr ',' '\n' | sed 's/^/build-/')
echo "Building with arguments=$args"
./gradlew $args
fi
./gradlew build-all
env:
BUILD_ID: ${{ github.run_number }}
BUILD_RELEASE: ${{ inputs.release }}

- name: Merge Jars
run: |
mkdir build/
mkdir build/libs/
python .github/workflows/scripts/merger.py
env:
BUILD_ID: ${{ github.run_number }}
BUILD_RELEASE: ${{ inputs.release }}
FILE_SUFFIX: build/libs/${{ steps.properties_g.outputs.mod_name }}-v${{ steps.properties_g.outputs.mod_version }}

- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: build-artifacts
path: versions/*/build/libs/
path: build/libs/

summary:
runs-on: ubuntu-22.04
runs-on: ubuntu-latest
needs:
- build

Expand All @@ -76,7 +82,4 @@ jobs:

- name: Make build summary
run: |
pip install jproperties
python .github/workflows/scripts/summary.py
env:
TARGET_SUBPROJECT: ${{ inputs.target_subproject }}
python .github/workflows/scripts/summary.py
2 changes: 2 additions & 0 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ on:
- "src/**"
- "versions/**"
- ".github/**"
- "buildSrc/**"
- "settings.json"
pull_request:


Expand Down
12 changes: 2 additions & 10 deletions .github/workflows/matrix_prep.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,6 @@ name: _step.matrix_prepare

on:
workflow_call:
inputs:
target_subproject:
description: see release.yml, for generating matrix entries
type: string
required: false
default: ''
outputs:
matrix:
description: The generated run matrix
Expand All @@ -16,14 +10,12 @@ on:

jobs:
matrix_prep:
runs-on: ubuntu-22.04
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- id: setmatrix
run: python3 .github/workflows/scripts/matrix.py # ubuntu-22.04 uses Python 3.10.6
env:
TARGET_SUBPROJECT: ${{ inputs.target_subproject }}
run: python3 .github/workflows/scripts/matrix.py

outputs:
matrix: ${{ steps.setmatrix.outputs.matrix }}
111 changes: 9 additions & 102 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,66 +1,18 @@
name: Release

# release: <default> (release title)
# dispatch (all): Manual release for $target_release_tag
# dispatch (specified): Manual release for $target_release_tag (subproject: $target_subproject)
run-name: |-
${{ github.event_name == 'workflow_dispatch' && format('Manual release for {0}{1}', inputs.target_release_tag, inputs.target_subproject && format(' (subproject: {0})', inputs.target_subproject) || '') || '' }}
on:
release:
types:
- published
workflow_dispatch:
inputs:
target_subproject:
description: |-
The subproject name(s) of the specified Minecraft version to be released, seperated with ",".
By default all subprojects will be released
type: string
required: false
default: ''
target_release_tag:
description: The tag of the release you want to append the artifact to
type: string
required: true


jobs:
show_action_parameters:
runs-on: ubuntu-latest
steps:
- name: Show action parameters
run: |
cat <<EOF > $GITHUB_STEP_SUMMARY
## Action Parameters
- target_subproject: \`${{ github.event.inputs.target_subproject }}\`
- target_release_tag: \`${{ github.event.inputs.target_release_tag }}\`
EOF
matrix_prep:
uses: ./.github/workflows/matrix_prep.yml
with:
target_subproject: ${{ github.event.inputs.target_subproject }}

# ensure the input release tag is valid
validate_release:
runs-on: ubuntu-latest
steps:
- name: Get github release information
if: ${{ github.event_name == 'workflow_dispatch' }}
uses: cardinalby/git-get-release-action@1.2.5
env:
GITHUB_TOKEN: ${{ github.token }}
with:
tag: ${{ github.event.inputs.target_release_tag }}

build:
uses: ./.github/workflows/build.yml
secrets: inherit
needs:
- validate_release
with:
target_subproject: ${{ github.event.inputs.target_subproject }}
release: true

release:
Expand All @@ -80,69 +32,24 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Display context
run: |
echo ref_name = ${{ github.ref_name }}
echo target_subproject = ${{ github.event.inputs.target_subproject }}
echo target_release_tag = ${{ github.event.inputs.target_release_tag }}
- name: Download build artifacts
uses: actions/download-artifact@v4
with:
name: build-artifacts
path: build-artifacts

- name: Get github release information
if: ${{ github.event_name == 'workflow_dispatch' }}
id: get_release
uses: cardinalby/git-get-release-action@1.2.5
env:
GITHUB_TOKEN: ${{ github.token }}
with:
tag: ${{ github.event.inputs.target_release_tag }}

- name: Generate publish related information
id: release_info
run: |
if [ $GITHUB_EVENT_NAME == 'release' ]
then
# Leave an empty value here, so Kir-Antipov/mc-publish will infer the tag from the action context
echo "tag_name=" >> $GITHUB_OUTPUT
elif [ $GITHUB_EVENT_NAME == 'workflow_dispatch' ]
then
echo "tag_name=${{ github.event.inputs.target_release_tag }}" >> $GITHUB_OUTPUT
else
echo Unknown github event name $GITHUB_EVENT_NAME
exit 1
fi
- name: Read common properties
id: properties_g
uses: christian-draeger/read-properties@1.1.1
with:
path: gradle.properties
properties: 'mod_name mod_version'

- name: Read version-specific properties
id: properties_v
uses: christian-draeger/read-properties@1.1.1
with:
path: ${{ format('versions/{0}/gradle.properties', matrix.subproject) }}
properties: 'minecraft_version game_versions platform'

- name: Fix game version
id: game_versions
run: |
# Fixed \n in game_versions isn't parsed by christian-draeger/read-properties as a line separator
echo 'value<<EOF' >> $GITHUB_OUTPUT
echo -e "${{ steps.properties_v.outputs.game_versions }}" >> $GITHUB_OUTPUT
echo 'EOF' >> $GITHUB_OUTPUT
- name: Prepare file information
id: file_info
run: |
shopt -s extglob
FILE_PATHS=$(ls ${{ format('build-artifacts/{0}/build/libs/!(*-@(dev|sources|shadow)).jar', matrix.subproject) }})
FILE_PATHS=$(ls "build-artifacts/${{ steps.properties_g.outputs.mod_name }}-v${{ steps.properties_g.outputs.mod_version }}-mc${{ matrix.version }}.jar")
if (( ${#FILE_PATHS[@]} != 1 )); then
echo "Error: Found ${#FILE_PATHS[@]} files, expected exactly 1"
exit 1
Expand All @@ -165,7 +72,7 @@ jobs:
result-encoding: string
env:
CHANGELOG: |-
${{ format('{0}{1}', github.event.release.body, steps.get_release.outputs.body) }}
${{ github.event.release.body }}
-------
Expand All @@ -182,23 +89,23 @@ jobs:
modrinth-id: VozTPxB4
modrinth-token: ${{ secrets.MODRINTH_API_TOKEN }}

github-tag: ${{ steps.release_info.outputs.tag_name }}
github-tag:
github-token: ${{ secrets.GITHUB_TOKEN }}

files: ${{ steps.file_info.outputs.path }}

name: ${{ format('{0} v{1} for mc{2}', steps.properties_g.outputs.mod_name, steps.properties_g.outputs.mod_version, steps.properties_v.outputs.minecraft_version) }}
version: ${{ format('v{1}-mc{0}', steps.properties_v.outputs.minecraft_version, steps.properties_g.outputs.mod_version) }}
name: ${{ format('{0} v{1} for mc{2}', steps.properties_g.outputs.mod_name, steps.properties_g.outputs.mod_version, matrix.version) }}
version: ${{ format('v{1}-mc{0}', matrix.version, steps.properties_g.outputs.mod_version) }}

# WIP: always using beta channel
version-type: beta

modrinth-loaders: ${{ steps.properties_v.outputs.platform }}
game-versions: ${{ steps.game_versions.outputs.value }}
modrinth-loaders: ${{ matrix.platforms }}
game-versions: ${{ matrix.game_versions }}
game-version-filter: any

github-changelog: ${{ format('{0}{1}', github.event.release.body, steps.get_release.outputs.body) }}
github-changelog: ${{ github.event.release.body }}
modrinth-changelog: ${{ steps.changelog.outputs.result }}

retry-attempts: 3
retry-delay: 10000
retry-delay: 10000
25 changes: 2 additions & 23 deletions .github/workflows/scripts/matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,18 @@
A script to scan through the versions directory and collect all folder names as the subproject list,
then output a json as the github action include matrix
"""
__author__ = 'Fallen_Breath'
__author__ = 'Fallen_Breath and topi_banana'

import json
import os
import sys


def main():
target_subproject_env = os.environ.get('TARGET_SUBPROJECT', '')
target_subprojects = list(filter(None, target_subproject_env.split(',') if target_subproject_env != '' else []))
print('target_subprojects: {}'.format(target_subprojects))

with open('settings.json') as f:
settings: dict = json.load(f)

if len(target_subprojects) == 0:
subprojects = settings['versions']
else:
subprojects = []
for subproject in settings['versions']:
if subproject in target_subprojects:
subprojects.append(subproject)
target_subprojects.remove(subproject)
if len(target_subprojects) > 0:
print('Unexpected subprojects: {}'.format(target_subprojects), file=sys.stderr)
sys.exit(1)

matrix_entries = []
for subproject in subprojects:
matrix_entries.append({
'subproject': subproject,
})
matrix = {'include': matrix_entries}
matrix = {'include': settings['versions']}
with open(os.environ['GITHUB_OUTPUT'], 'w') as f:
f.write('matrix={}\n'.format(json.dumps(matrix)))

Expand Down
Loading

0 comments on commit bf18594

Please sign in to comment.