Skip to content

Commit 9085f28

Browse files
committed
chore: rewrite CI/CD workflows for multi-version builds [skip sync]
1 parent a084307 commit 9085f28

3 files changed

Lines changed: 214 additions & 143 deletions

File tree

.github/workflows/build.yml

Lines changed: 64 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,70 @@
11
name: Build
2+
23
on:
3-
push:
4-
branches:
5-
- master
6-
workflow_dispatch:
4+
push:
5+
branches:
6+
- dev
7+
- 1.20.x
8+
- 1.21.x
9+
- 26.1.x
10+
workflow_dispatch:
711

812
permissions:
9-
contents: write
13+
contents: write
1014

1115
jobs:
12-
build:
13-
runs-on: ubuntu-24.04
14-
steps:
15-
- name: Checkout repository
16-
uses: actions/checkout@v4
17-
with:
18-
fetch-depth: 0
19-
20-
- name: Setup JDK
21-
uses: actions/setup-java@v4
22-
with:
23-
java-version: "21"
24-
distribution: "temurin"
25-
cache: "gradle"
26-
27-
- name: Make gradle wrapper executable
28-
run: chmod +x ./gradlew
29-
30-
- name: Build
31-
run: ./gradlew build
32-
33-
- name: Get Version
34-
id: get_version
35-
run: |
36-
VERSION=$(grep "mod_version" gradle.properties | cut -d'=' -f2)
37-
echo "version=$VERSION" >> $GITHUB_OUTPUT
38-
39-
- name: Prepare build branch
40-
run: |
41-
mkdir -p deploy
42-
cp build/libs/*.jar deploy/
43-
cd deploy
44-
git init
45-
git config user.name "github-actions"
46-
git config user.email "github-actions@github.com"
47-
git checkout -b build
48-
git add .
49-
git commit -m "Build v${{ steps.get_version.outputs.version }} - $(date +'%Y-%m-%d %H:%M:%S')"
50-
git remote add origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git
51-
git push -f origin build
16+
build:
17+
runs-on: ubuntu-24.04
18+
steps:
19+
- name: Checkout repository
20+
uses: actions/checkout@v4
21+
with:
22+
fetch-depth: 0
23+
24+
- name: Setup Java
25+
uses: actions/setup-java@v4
26+
with:
27+
java-version: "25"
28+
distribution: "zulu"
29+
cache: "gradle"
30+
31+
- name: Make gradle wrapper executable
32+
run: chmod +x ./gradlew
33+
34+
- name: Read mod version
35+
id: mod_info
36+
run: echo "mod_version=$(grep '^mod_version' gradle.properties | cut -d= -f2)" >> $GITHUB_OUTPUT
37+
38+
- name: Build all versions
39+
run: |
40+
mkdir -p dist
41+
VERSION="${{ steps.mod_info.outputs.mod_version }}"
42+
43+
while read -r version_data; do
44+
VER=$(echo "$version_data" | jq -r '.version')
45+
MC_SRC=$(echo "$version_data" | jq -r '.mcVersion // .version')
46+
MC_VER=$(echo "$version_data" | jq -r '.minecraft_version')
47+
FABRIC_API=$(echo "$version_data" | jq -r '.fabric_api_version')
48+
YARN=$(echo "$version_data" | jq -r '.yarn_mappings // empty')
49+
LOADER=$(echo "$version_data" | jq -r '.loader_version // empty')
50+
51+
PROP_ARGS=(-PmcVersion="$MC_SRC" -Pminecraft_version="$MC_VER" -Pfabric_api_version="$FABRIC_API")
52+
[ -n "$YARN" ] && PROP_ARGS+=(-Pyarn_mappings="$YARN")
53+
[ -n "$LOADER" ] && PROP_ARGS+=(-Ploader_version="$LOADER")
54+
55+
./gradlew clean build "${PROP_ARGS[@]}" --no-daemon -q 2>&1 || exit 1
56+
57+
cp "build/libs/stackabletools-${VERSION}.jar" "dist/stackabletools-${VERSION}-mc${VER}.jar"
58+
done < <(jq -c '.versions[]' versions.json)
59+
60+
- name: Push artifacts to build branch
61+
run: |
62+
cd dist
63+
git init
64+
git config user.name "github-actions"
65+
git config user.email "github-actions@github.com"
66+
git checkout -b build
67+
git add .
68+
git commit -m "Build v${{ steps.mod_info.outputs.mod_version }} - $(date +'%Y-%m-%d %H:%M:%S')"
69+
git remote add origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git
70+
git push -f origin build

.github/workflows/publish.yml

Lines changed: 45 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,69 @@
11
name: Publish to CurseForge & Modrinth
2+
23
on:
34
release:
45
types: [published]
56
workflow_dispatch:
67

78
jobs:
9+
setup:
10+
runs-on: ubuntu-24.04
11+
outputs:
12+
matrix: ${{ steps.gen_matrix.outputs.matrix }}
13+
steps:
14+
- uses: actions/checkout@v4
15+
- id: gen_matrix
16+
run: |
17+
MATRIX=$(jq -c '{include: [.versions[] | {
18+
version: .version,
19+
mc_src: (.mcVersion // .version),
20+
mc_ver: .minecraft_version,
21+
fabric_api: .fabric_api_version,
22+
yarn: (.yarn_mappings // ""),
23+
loader: (.loader_version // "")
24+
}]}' versions.json)
25+
echo "matrix=$MATRIX" >> $GITHUB_OUTPUT
26+
827
publish:
28+
needs: setup
929
runs-on: ubuntu-24.04
30+
strategy:
31+
matrix: ${{ fromJSON(needs.setup.outputs.matrix) }}
1032
steps:
11-
- name: Checkout Master Repository
12-
uses: actions/checkout@v4
33+
- uses: actions/checkout@v4
34+
35+
- name: Setup Java
36+
uses: actions/setup-java@v4
1337
with:
14-
ref: master
38+
java-version: "25"
39+
distribution: "zulu"
40+
cache: "gradle"
1541

16-
- name: Get Mod Info
17-
id: mod_info
42+
- name: Make gradle wrapper executable
43+
run: chmod +x ./gradlew
44+
45+
- name: Build for ${{ matrix.version }}
1846
run: |
19-
VERSION=$(grep "mod_version" gradle.properties | cut -d'=' -f2)
20-
MC_VERSION=$(grep "minecraft_version" gradle.properties | cut -d'=' -f2)
21-
echo "version=$VERSION" >> $GITHUB_OUTPUT
22-
echo "mc_version=$MC_VERSION" >> $GITHUB_OUTPUT
47+
PROPS=(-DmcVersion="${{ matrix.mc_src }}" -PmcVersion="${{ matrix.mc_src }}" -Pminecraft_version="${{ matrix.mc_ver }}" -Pfabric_api_version="${{ matrix.fabric_api }}")
48+
[ -n "${{ matrix.yarn }}" ] && PROPS+=(-Pyarn_mappings="${{ matrix.yarn }}")
49+
[ -n "${{ matrix.loader }}" ] && PROPS+=(-Ploader_version="${{ matrix.loader }}")
50+
./gradlew build "${PROPS[@]}" --no-daemon -q
2351
24-
- name: Download Artifacts from Build branch
25-
uses: actions/checkout@v4
26-
with:
27-
ref: build
28-
path: build-artifacts
52+
- name: Get mod version
53+
id: mod_info
54+
run: echo "mod_version=$(grep '^mod_version' gradle.properties | cut -d= -f2)" >> $GITHUB_OUTPUT
2955

3056
- name: Publish to CurseForge + Modrinth
3157
uses: tristankechlo/publish-mc-mod@v2.0.0
3258
with:
33-
mc-version: ${{ steps.mod_info.outputs.mc_version }}
34-
mod-version: ${{ steps.mod_info.outputs.version }}
59+
mc-version: ${{ matrix.mc_ver }}
60+
mod-version: ${{ steps.mod_info.outputs.mod_version }}
3561
curseforge-id: ${{ secrets.CURSEFORGE_PROJECT_ID }}
3662
modrinth-id: ${{ secrets.MODRINTH_PROJECT_ID }}
37-
version-range: ${{ steps.mod_info.outputs.mc_version }}
63+
version-range: ${{ matrix.mc_ver }}
3864
version-type: "release"
3965
loaders: "fabric"
40-
fabric-glob: "build-artifacts/stackabletools-${{ steps.mod_info.outputs.version }}.jar"
41-
changelog: "Official release of v${{ steps.mod_info.outputs.version }}"
66+
fabric-glob: "build/libs/stackabletools-${{ steps.mod_info.outputs.mod_version }}.jar"
67+
changelog: "Release v${{ steps.mod_info.outputs.mod_version }} — ${{ matrix.version }}"
4268
curseforge-token: ${{ secrets.CURSEFORGE_API_KEY }}
4369
modrinth-token: ${{ secrets.MODRINTH_API_TOKEN }}

.github/workflows/release.yml

Lines changed: 105 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,86 +1,112 @@
11
name: Multi-Release
22

33
on:
4-
workflow_dispatch:
5-
inputs:
6-
release-body:
7-
description: "Changelog for this release"
8-
type: string
9-
required: false
10-
default: "Manual release from build branch."
4+
workflow_dispatch:
5+
inputs:
6+
release-body:
7+
description: "Changelog for this release"
8+
type: string
9+
required: false
10+
default: ""
1111

1212
permissions:
13-
contents: write
13+
contents: write
1414

1515
jobs:
16-
release:
17-
runs-on: ubuntu-24.04
18-
steps:
19-
- name: Checkout repository (Master)
20-
uses: actions/checkout@v4
21-
with:
22-
ref: master
23-
path: master-repo
24-
fetch-depth: 0
25-
26-
- name: Bump version if needed
27-
id: version_check
28-
shell: bash
29-
run: |
30-
cd master-repo
31-
git config user.name "github-actions"
32-
git config user.email "github-actions@github.com"
33-
34-
# Function to increment patch version
35-
increment_version() {
36-
local v=$1
37-
local major=$(echo $v | cut -d. -f1)
38-
local minor=$(echo $v | cut -d. -f2)
39-
local patch=$(echo $v | cut -d. -f3)
40-
echo "$major.$minor.$((patch + 1))"
41-
}
42-
43-
# Load version from gradle.properties
44-
VERSION=$(grep "mod_version" gradle.properties | cut -d'=' -f2)
45-
git fetch --tags
46-
47-
# Check if tag already exists and increment version until it's unique
48-
while git rev-parse "v$VERSION" >/dev/null 2>&1; do
49-
echo "Tag v$VERSION already exists. Counting up..."
50-
VERSION=$(increment_version $VERSION)
51-
done
52-
53-
# Get current version again for comparison
54-
CURRENT_VERSION=$(grep "mod_version" gradle.properties | cut -d'=' -f2)
55-
if [ "$VERSION" != "$CURRENT_VERSION" ]; then
56-
echo "Updating version in gradle.properties to $VERSION"
57-
sed -i "s/mod_version=$CURRENT_VERSION/mod_version=$VERSION/" gradle.properties
58-
git add gradle.properties
59-
git commit -m "chore: bump version to $VERSION [skip ci]"
60-
git push origin master
61-
fi
62-
63-
echo "version=$VERSION" >> $GITHUB_OUTPUT
64-
65-
- name: Checkout Build branch
66-
uses: actions/checkout@v4
67-
with:
68-
ref: build
69-
path: build-artifacts
70-
71-
- name: Push Tag
72-
run: |
73-
cd master-repo
74-
git tag v${{ steps.version_check.outputs.version }}
75-
git push origin v${{ steps.version_check.outputs.version }}
76-
77-
- name: Create GitHub Release
78-
uses: softprops/action-gh-release@v2
79-
with:
80-
tag_name: v${{ steps.version_check.outputs.version }}
81-
name: Release v${{ steps.version_check.outputs.version }}
82-
body: ${{ github.event.inputs.release-body }}
83-
generate_release_notes: true
84-
files: build-artifacts/*.jar
85-
env:
86-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
16+
release:
17+
runs-on: ubuntu-24.04
18+
steps:
19+
- name: Checkout repository
20+
uses: actions/checkout@v4
21+
with:
22+
fetch-depth: 0
23+
24+
- name: Setup Java
25+
uses: actions/setup-java@v4
26+
with:
27+
java-version: "25"
28+
distribution: "zulu"
29+
cache: "gradle"
30+
31+
- name: Make gradle wrapper executable
32+
run: chmod +x ./gradlew
33+
34+
- name: Read mod version
35+
id: mod_info
36+
run: echo "mod_version=$(grep '^mod_version' gradle.properties | cut -d= -f2)" >> $GITHUB_OUTPUT
37+
38+
- name: Build all versions
39+
run: |
40+
mkdir -p dist
41+
VERSION="${{ steps.mod_info.outputs.mod_version }}"
42+
43+
while read -r version_data; do
44+
VER=$(echo "$version_data" | jq -r '.version')
45+
MC_SRC=$(echo "$version_data" | jq -r '.mcVersion // .version')
46+
MC_VER=$(echo "$version_data" | jq -r '.minecraft_version')
47+
FABRIC_API=$(echo "$version_data" | jq -r '.fabric_api_version')
48+
YARN=$(echo "$version_data" | jq -r '.yarn_mappings // empty')
49+
LOADER=$(echo "$version_data" | jq -r '.loader_version // empty')
50+
51+
echo "--- Building $VER ($MC_VER) ---"
52+
53+
PROP_ARGS=(-PmcVersion="$MC_SRC" -Pminecraft_version="$MC_VER" -Pfabric_api_version="$FABRIC_API")
54+
[ -n "$YARN" ] && PROP_ARGS+=(-Pyarn_mappings="$YARN")
55+
[ -n "$LOADER" ] && PROP_ARGS+=(-Ploader_version="$LOADER")
56+
57+
./gradlew clean build "${PROP_ARGS[@]}" --no-daemon -q 2>&1 || exit 1
58+
59+
JAR="build/libs/stackabletools-${VERSION}.jar"
60+
if [ -f "$JAR" ]; then
61+
cp "$JAR" "dist/stackabletools-${VERSION}-mc${VER}.jar"
62+
echo " -> dist/stackabletools-${VERSION}-mc${VER}.jar"
63+
fi
64+
echo ""
65+
done < <(jq -c '.versions[]' versions.json)
66+
67+
- name: List built artifacts
68+
run: ls -lh dist/
69+
70+
- name: Bump version and push tag
71+
id: version_tag
72+
run: |
73+
git config user.name "github-actions"
74+
git config user.email "github-actions@github.com"
75+
76+
increment_version() {
77+
local v=$1
78+
local major=$(echo "$v" | cut -d. -f1)
79+
local minor=$(echo "$v" | cut -d. -f2)
80+
local patch=$(echo "$v" | cut -d. -f3)
81+
echo "$major.$minor.$((patch + 1))"
82+
}
83+
84+
VERSION=$(grep '^mod_version' gradle.properties | cut -d= -f2)
85+
git fetch --tags
86+
87+
while git rev-parse "v$VERSION" >/dev/null 2>&1; do
88+
VERSION=$(increment_version "$VERSION")
89+
done
90+
91+
CURRENT_VERSION=$(grep '^mod_version' gradle.properties | cut -d= -f2)
92+
if [ "$VERSION" != "$CURRENT_VERSION" ]; then
93+
sed -i "s/^mod_version=$CURRENT_VERSION/mod_version=$VERSION/" gradle.properties
94+
git add gradle.properties
95+
git commit -m "chore: bump version to $VERSION [skip ci]"
96+
git push origin "${GITHUB_REF#refs/heads/}"
97+
fi
98+
99+
git tag "v$VERSION"
100+
git push origin "v$VERSION"
101+
echo "version=$VERSION" >> $GITHUB_OUTPUT
102+
103+
- name: Create GitHub Release
104+
uses: softprops/action-gh-release@v2
105+
with:
106+
tag_name: v${{ steps.version_tag.outputs.version }}
107+
name: Release v${{ steps.version_tag.outputs.version }}
108+
body: ${{ github.event.inputs.release-body }}
109+
generate_release_notes: true
110+
files: dist/*.jar
111+
env:
112+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)