Skip to content

Commit

Permalink
✅ 初始提交
Browse files Browse the repository at this point in the history
  • Loading branch information
1024-byteeeee committed Dec 9, 2023
0 parents commit 630329f
Show file tree
Hide file tree
Showing 46 changed files with 1,660 additions and 0 deletions.
79 changes: 79 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
name: step.build

on:
workflow_call:
inputs:
release:
type: boolean
required: false
default: false
target_subproject:
description: The subproject name of the specified Minecraft version to be built. Leave it empty to build all
type: string
required: false
default: ''

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: 17

- name: Cache gradle files
uses: actions/cache@v3
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
./.gradle/loom-cache
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle', '**/gradle.properties', '**/*.accesswidener') }}
restore-keys: |
${{ runner.os }}-gradle-
- name: Get subproject name to build
id: subproject_info
run: |
if [ "${{ inputs.target_subproject }}" != "" ]
then
echo "prefix=${{ inputs.target_subproject }}:" >> $GITHUB_OUTPUT
else
echo "prefix=" >> $GITHUB_OUTPUT
fi
- name: Build with Gradle
run: |
chmod +x gradlew
./gradlew ${{ steps.subproject_info.outputs.prefix }}build --no-daemon
env:
BUILD_ID: ${{ github.run_number }}
BUILD_RELEASE: ${{ inputs.release }}

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

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

steps:
- uses: actions/checkout@v3

- name: Download build artifacts
uses: actions/download-artifact@v3
with:
name: build-artifacts
path: build-artifacts

- name: Make build summary
run: python3 .github/workflows/scripts/summary.py # Python 3.10.6
env:
TARGET_SUBPROJECT: ${{ inputs.target_subproject }}
16 changes: 16 additions & 0 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Dev Builds

on:
push:
paths:
- "*.gradle"
- "gradle.properties"
- "src/**"
- "versions/**"
- ".github/**"
pull_request:


jobs:
build:
uses: ./.github/workflows/build.yml
29 changes: 29 additions & 0 deletions .github/workflows/matrix_includes.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
[
{
"subproject_dir": "1.16.5"
},
{
"subproject_dir": "1.17.1"
},
{
"subproject_dir": "1.18.2"
},
{
"subproject_dir": "1.19.4"
},
{
"subproject_dir": "1.20"
},
{
"subproject_dir": "1.20.1"
},
{
"subproject_dir": "1.20.2"
},
{
"subproject_dir": "1.20.3"
},
{
"subproject_dir": "1.20.4"
}
]
39 changes: 39 additions & 0 deletions .github/workflows/matrix_prep.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: step.matrix_prepare

on:
workflow_call:
inputs:
target_subproject:
description: The subproject name of the specified Minecraft version for generating matrix entry
type: string
required: false
default: ''
outputs:
matrix:
description: The generated run matrix
value: ${{ jobs.matrix_prep.outputs.matrix }}


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

- 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 }}
- id: setmatrix
uses: JoshuaTheMiller/conditional-build-matrix@v1.0.1
with:
# inputFile: '.github/workflows/matrix_includes.json' # Default input file path
filter: '[? `${{ github.event_name }}` == `release` || `${{ github.event.inputs.target_subproject }}` == `` || `"${{ github.event.inputs.target_subproject }}"` == subproject_dir ]'

- name: Print matrix
run: echo ${{ steps.setmatrix.outputs.matrix }}

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

on:
release:
types:
- published
workflow_dispatch:
inputs:
target_subproject:
description: The subproject name of the specified Minecraft version to 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 }}

build:
uses: ./.github/workflows/build.yml
with:
target_subproject: ${{ github.event.inputs.target_subproject }}
release: true

release:
needs:
- matrix_prep
- build
runs-on: ubuntu-latest

strategy:
matrix: ${{ fromJson(needs.matrix_prep.outputs.matrix) }}

steps:
- uses: actions/checkout@v3

- name: Download build artifacts
uses: actions/download-artifact@v3
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.4
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
echo "tag_name=" >> $GITHUB_OUTPUT # leave an empty value here so softprops/action-gh-release will use the default value
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_dir) }}
properties: 'minecraft_version game_versions'

- 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: Publish Minecraft Mods
uses: Kir-Antipov/mc-publish@v3.2
with:
modrinth-id: ZE76X2SR
modrinth-token: ${{ secrets.MODRINTH_API_TOKEN }}

curseforge-id: _INSERT_CURSEFORGE_MOD_ID_HERE_
curseforge-token: ${{ secrets.CF_API_TOKEN }}

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

files-primary: ${{ format('build-artifacts/{0}/build/libs/!(*-@(dev|sources)).jar', matrix.subproject_dir) }}
files-secondary: ''

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('mc{0}-v{1}', steps.properties_v.outputs.minecraft_version, steps.properties_g.outputs.mod_version) }}
version-type: release
changelog: ${{ format('{0}{1}', github.event.release.body, steps.get_release.outputs.body) }} # one of them should be an empty string (null)

loaders: fabric
game-versions: ${{ steps.game_versions.outputs.value }}
version-resolver: exact

retry-attempts: 3
retry-delay: 10000
40 changes: 40 additions & 0 deletions .github/workflows/scripts/summary.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
"""
A script to scan through all valid mod jars in build-artifacts.zip/$version/build/libs,
and generate an artifact summary table for that to GitHub action step summary
"""
__author__ = 'Fallen_Breath'

import glob
import json
import os


def read_prop(file_name: str, key: str) -> str:
with open(file_name) as prop:
return next(filter(
lambda l: l.split('=', 1)[0].strip() == key,
prop.readlines()
)).split('=', 1)[1].lstrip()


target_subproject = os.environ.get('TARGET_SUBPROJECT', '')
with open('.github/workflows/matrix_includes.json') as f:
matrix: list[dict] = json.load(f)

with open(os.environ['GITHUB_STEP_SUMMARY'], 'w') as f:
f.write('## Build Artifacts Summary\n\n')
f.write('| Subproject | for Minecraft | Files |\n')
f.write('| --- | --- | --- |\n')

for m in matrix:
subproject = m['subproject_dir']
if target_subproject != '' and subproject != target_subproject:
continue
game_versions = read_prop('versions/{}/gradle.properties'.format(subproject), 'game_versions')
game_versions = game_versions.strip().replace('\\n', ', ')
file_names = glob.glob('build-artifacts/{}/build/libs/*.jar'.format(subproject))
file_names = ', '.join(map(
lambda fn: '`{}`'.format(os.path.basename(fn)),
filter(lambda fn: not fn.endswith('-sources.jar') and not fn.endswith('-dev.jar'), file_names)
))
f.write('| {} | {} | {} |\n'.format(subproject, game_versions, file_names))
34 changes: 34 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# gradle

.gradle/
build/
out/
classes/

# eclipse

*.launch

# idea

.idea/
*.iml
*.ipr
*.iws

# vscode

.settings/
.vscode/
bin/
.classpath
.project

# macos

*.DS_Store

# fabric

run/*
!run/options.txt
Loading

0 comments on commit 630329f

Please sign in to comment.