|
1 | 1 | name: Multi-Release |
2 | 2 |
|
3 | 3 | 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: "" |
11 | 11 |
|
12 | 12 | permissions: |
13 | | - contents: write |
| 13 | + contents: write |
14 | 14 |
|
15 | 15 | 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