-
Notifications
You must be signed in to change notification settings - Fork 0
204 lines (170 loc) · 8.23 KB
/
build-and-release.yml
File metadata and controls
204 lines (170 loc) · 8.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
name: Build and Release
on:
push:
branches:
- main
jobs:
build-and-release:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
fetch-tags: true
- name: Check for version in commit message
id: check_version
run: |
COMMIT_MSG=$(git log -1 --pretty=%B)
echo "Commit message: $COMMIT_MSG"
# Check if commit message contains a semver pattern
if [[ $COMMIT_MSG =~ v?([0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9.-]+)?(\+[a-zA-Z0-9.-]+)?) ]]; then
VERSION="${BASH_REMATCH[1]}"
TAG="$VERSION"
echo "Found version: $VERSION"
echo "SHOULD_RELEASE=true" >> $GITHUB_OUTPUT
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
echo "TAG=$TAG" >> $GITHUB_OUTPUT
# Determine release type
if [[ "$VERSION" == *"-alpha"* ]]; then
echo "RELEASE_TYPE=alpha" >> $GITHUB_OUTPUT
elif [[ "$VERSION" == *"-beta"* ]]; then
echo "RELEASE_TYPE=beta" >> $GITHUB_OUTPUT
else
echo "RELEASE_TYPE=release" >> $GITHUB_OUTPUT
fi
echo "Release type: $RELEASE_TYPE"
else
echo "No version found in commit message"
echo "SHOULD_RELEASE=false" >> $GITHUB_OUTPUT
fi
- name: Setup JDK 21
uses: actions/setup-java@v4
with:
java-version: '21'
distribution: 'temurin'
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v4
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Run Data
run: ./gradlew runData
- name: Build with Gradle
run: ./gradlew build
- name: Get mod info
id: mod_info
run: |
MOD_VERSION=$(sed -n 's/^mod_version=//p' gradle.properties | tr -d ' \r\n')
MC_VERSION=$(sed -n 's/^minecraft_version=//p' gradle.properties | tr -d ' \r\n')
NEO_VERSION=$(sed -n 's/^neo_version=//p' gradle.properties | tr -d ' \r\n')
MOD_ID=$(sed -n 's/^mod_id=//p' gradle.properties | tr -d ' \r\n')
MOD_NAME=$(sed -n 's/^mod_name=//p' gradle.properties | tr -d ' \r\n')
CURSEFORGE_PROJECT_ID=$(sed -n 's/^curseforge_project_id=//p' gradle.properties | tr -d ' \r\n')
MODRINTH_PROJECT_SLUG=$(sed -n 's/^modrinth_project_slug=//p' gradle.properties | tr -d ' \r\n')
echo "Mod version: $MOD_VERSION"
echo "Minecraft version: $MC_VERSION"
echo "NeoForge Build version: $NEO_VERSION"
cat >> $GITHUB_OUTPUT << EOF
MOD_VERSION=${MOD_VERSION}
MC_VERSION=${MC_VERSION}
NEO_VERSION=${NEO_VERSION}
MOD_ID=${MOD_ID}
MOD_NAME=${MOD_NAME}
CURSEFORGE_PROJECT_ID=${CURSEFORGE_PROJECT_ID}
MODRINTH_PROJECT_SLUG=${MODRINTH_PROJECT_SLUG}
EOF
- name: Find built JAR files
id: find_jars
run: |
echo "JAR_PATH=$(find build/libs -name "*.jar" -not -name "*-sources.jar" -not -name "*-javadoc.jar" | head -1)"
echo "JAR_PATH=$(find build/libs -name "*.jar" -not -name "*-sources.jar" -not -name "*-javadoc.jar" | head -1)" >> $GITHUB_OUTPUT
echo "SOURCES_JAR_PATH=$(find build/libs -name "*-sources.jar" | head -1)"
echo "SOURCES_JAR_PATH=$(find build/libs -name "*-sources.jar" | head -1)" >> $GITHUB_OUTPUT
echo "JAVADOC_JAR_PATH=$(find build/libs -name "*-javadoc.jar" | head -1)"
echo "JAVADOC_JAR_PATH=$(find build/libs -name "*-javadoc.jar" | head -1)" >> $GITHUB_OUTPUT
echo "JAR_NAME=$(basename $(find build/libs -name "*.jar" -not -name "*-sources.jar" -not -name "*-javadoc.jar" | head -1))"
echo "JAR_NAME=$(basename $(find build/libs -name "*.jar" -not -name "*-sources.jar" -not -name "*-javadoc.jar" | head -1))" >> $GITHUB_OUTPUT
- name: Get previous tag
id: prev_tag
run: |
# Get the most recent tag (for comparison against current commit)
tag=$(git tag --sort=-creatordate | head -1 || true)
echo "Most recent tag: $tag"
echo "tag=$tag" >> "$GITHUB_OUTPUT"
- name: Get commit log
id: commit_log
run: |
if [ -z "${{ steps.prev_tag.outputs.tag }}" ]; then
echo "log=- First release" >> "$GITHUB_OUTPUT"
else
# Use a temporary file to avoid heredoc delimiter issues
TEMP_LOG=$(mktemp)
git log ${{ steps.prev_tag.outputs.tag }}..HEAD --pretty=format:"- %s (%an)" > "$TEMP_LOG"
# Use unique delimiter with timestamp (capture once to ensure consistency)
DELIMITER="COMMIT_LOG_DELIMITER_$(date +%s)"
echo "log<<$DELIMITER" >> "$GITHUB_OUTPUT"
cat "$TEMP_LOG" >> "$GITHUB_OUTPUT"
echo "" >> "$GITHUB_OUTPUT"
echo "$DELIMITER" >> "$GITHUB_OUTPUT"
rm "$TEMP_LOG"
fi
# Only create tag and release if version was found in commit message
- name: Create tag
if: steps.check_version.outputs.SHOULD_RELEASE == 'true'
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git tag -a ${{ steps.check_version.outputs.TAG }} -m "Release ${{ steps.check_version.outputs.TAG }}"
git push origin ${{ steps.check_version.outputs.TAG }}
- name: Create Release and Upload JARs
if: steps.check_version.outputs.SHOULD_RELEASE == 'true'
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ steps.check_version.outputs.TAG }}
name: "${{ steps.mod_info.outputs.MOD_NAME }} v${{ steps.check_version.outputs.TAG }}"
body: |
## ${{ steps.mod_info.outputs.MOD_NAME }} v${{ steps.check_version.outputs.TAG }}
### Changes
${{ steps.commit_log.outputs.log }}
### Build Information
- **Minecraft Version:** ${{ steps.mod_info.outputs.MC_VERSION }}
- **NeoForge Version:** ${{ steps.mod_info.outputs.NEO_VERSION }}
- **Mod Version:** ${{ steps.mod_info.outputs.MOD_VERSION }}
### Download
Available on [CurseForge](https://www.curseforge.com/minecraft/mc-mods/${{ steps.mod_info.outputs.MOD_ID }}) and below.
draft: false
prerelease: ${{ contains(steps.check_version.outputs.VERSION, '-') }}
files: build/libs/*.jar
token: ${{ secrets.GITHUB_TOKEN }}
- name: Upload to CurseForge
if: steps.check_version.outputs.SHOULD_RELEASE == 'true' && env.CURSEFORGE_TOKEN != ''
env:
CURSEFORGE_TOKEN: ${{ secrets.CURSEFORGE_TOKEN }}
RELEASE_TYPE: release
CHANGELOG: ${{ github.event.head_commit.message }}
MOD_VERSION: ${{ steps.mod_info.outputs.MOD_VERSION }}
MC_VERSION: ${{ steps.mod_info.outputs.MC_VERSION }}
MOD_ID: ${{ steps.mod_info.outputs.MOD_ID }}
MOD_NAME: ${{ steps.mod_info.outputs.MOD_NAME }}
CURSEFORGE_PROJECT_ID: ${{ steps.mod_info.outputs.CURSEFORGE_PROJECT_ID }}
run: ./gradlew curseforge --no-configuration-cache
- name: Upload to Modrinth
if: steps.check_version.outputs.SHOULD_RELEASE == 'true' && env.MODRINTH_TOKEN != ''
env:
MODRINTH_TOKEN: ${{ secrets.MODRINTH_TOKEN }}
RELEASE_TYPE: ${{ steps.check_version.outputs.RELEASE_TYPE }}
CHANGELOG: ${{ github.event.head_commit.message }}
MOD_VERSION: ${{ steps.mod_info.outputs.MOD_VERSION }}
MC_VERSION: ${{ steps.mod_info.outputs.MC_VERSION }}
MOD_ID: ${{ steps.mod_info.outputs.MOD_ID }}
MOD_NAME: ${{ steps.mod_info.outputs.MOD_NAME }}
MODRINTH_PROJECT_SLUG: ${{ steps.mod_info.outputs.MODRINTH_PROJECT_SLUG }}
run: ./gradlew modrinth
# Always upload artifacts for every build (even without release)
- name: Upload build artifacts
uses: actions/upload-artifact@v4
with:
name: build-artifacts
path: build/libs/*.jar