-
Notifications
You must be signed in to change notification settings - Fork 275
192 lines (190 loc) · 7.8 KB
/
publish-release.yml
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
name: Publish Release
on:
release:
types: [published]
jobs:
Get-Properties:
runs-on: ubuntu-latest
outputs:
release-type: ${{ steps.type.outputs.release-type }}
carpet-version: ${{ steps.properties.outputs.mod_version }}
minecraft-version: ${{ steps.properties.outputs.minecraft_version }}
curse-versions: ${{ steps.properties.outputs.release-curse-versions }}
matrix-exclude-branch: ${{ steps.processmatrix.outputs.matrix-to-exclude }}
extra-branch-name: ${{ steps.properties.outputs.release-extra-branch-name }}
extra-branch-curse-version: ${{ steps.properties.outputs.release-extra-curse-version }}
steps:
- name: Checkout the sources
uses: actions/checkout@v3
- name: Determine release type
id: type
run: |
if ${{ github.event.release.prerelease }}; then
echo "release-type=beta" >> $GITHUB_OUTPUT
else
echo "release-type=release" >> $GITHUB_OUTPUT
fi
- name: Read relevant fields from gradle.properties
id: properties
run: | # From christian-draeger/read-properties, using the action makes it extremely messy until christian-draeger/read-properties#2
path='./gradle.properties'
for property in mod_version minecraft_version release-curse-versions release-extra-branch release-extra-branch-name release-extra-curse-version
do
result=$(sed -n "/^[[:space:]]*$property[[:space:]]*=[[:space:]]*/s/^[[:space:]]*$property[[:space:]]*=[[:space:]]*//p" "$path")
echo "$property: $result"
echo "$property=$result" >> $GITHUB_OUTPUT
done
- name: Process property for matrix
id: processmatrix
run: |
if ! ${{ steps.properties.outputs.release-extra-branch }}; then
echo "matrix-to-exclude=Snapshots" >> $GITHUB_OUTPUT
fi
- uses: actions/github-script@v6
env:
READ_VERSION: ${{ steps.properties.outputs.mod_version }}
with:
script: |
const { READ_VERSION } = process.env;
console.log('Read version is: ' + READ_VERSION);
let releases = (await github.rest.repos.listReleases({
owner: context.repo.owner,
repo: context.repo.repo
})).data;
console.log('Previous release was: ' + releases[1].name);
for (let release of releases.slice(1)) {
if (release.name.includes(READ_VERSION))
core.setFailed('Version number is the same as a previous release!')
}
Build-And-Publish:
runs-on: ubuntu-latest
needs: [Get-Properties]
strategy:
matrix:
branch: [Release, Snapshots]
exclude:
- branch: ${{ needs.Get-Properties.outputs.matrix-exclude-branch }}
steps:
- name: Get info from branch to run
id: getbranchinfo
run: |
if ${{ matrix.branch == 'Snapshots'}}; then
echo "branchname=${{ needs.Get-Properties.outputs.extra-branch-name }}" >> $GITHUB_OUTPUT
echo "version=${{ needs.Get-Properties.outputs.extra-branch-curse-version }}" >> $GITHUB_OUTPUT
echo "curse-versions=${{ needs.Get-Properties.outputs.extra-branch-curse-version }}" >> $GITHUB_OUTPUT
else
echo "version=${{ needs.Get-Properties.outputs.minecraft-version }}" >> $GITHUB_OUTPUT
echo "curse-versions=${{ needs.Get-Properties.outputs.curse-versions }}" >> $GITHUB_OUTPUT
fi
- name: Checkout the sources
uses: actions/checkout@v3
with:
ref: ${{ steps.getbranchinfo.outputs.branchname }}
- name: Set up JDK 21
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: 21
cache: 'gradle'
- name: Grant execute permission to gradlew
run: chmod +x gradlew
- name: Build with Gradle
run: ./gradlew build
- name: Find correct JAR
id: findjar
run: |
output="$(find build/libs/ ! -name "*-dev.jar" ! -name "*-sources.jar" -type f -printf "%f\n")"
echo "jarname=$output" >> $GITHUB_OUTPUT
- name: Save build artifacts in the action
uses: actions/upload-artifact@v3
with:
name: Artifacts for ${{ matrix.branch }}
path: build/libs
- name: Upload to the Github release
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ github.event.release.upload_url }}
asset_path: build/libs/${{ steps.findjar.outputs.jarname }}
asset_name: ${{ steps.findjar.outputs.jarname }}
asset_content_type: application/java-archive
- name: Upload to Curseforge
uses: itsmeow/curseforge-upload@v3
with:
token: ${{ secrets.CF_API_TOKEN }}
project_id: 349239
game_endpoint: minecraft
file_path: build/libs/${{ steps.findjar.outputs.jarname }}
changelog_type: markdown
changelog: ${{ github.event.release.body }}
display_name: Carpet v${{ needs.Get-Properties.outputs.carpet-version }} for ${{ steps.getbranchinfo.outputs.version }}
game_versions: 7499,4458,${{ steps.getbranchinfo.outputs.curse-versions }} #Fabric,Java 8,[version (s) for the branch]
release_type: ${{ needs.Get-Properties.outputs.release-type }}
- name: Ask Gradle to publish
run: ./gradlew publish
- name: Save publish folder in action's artifacts # Remove when automated
uses: actions/upload-artifact@v3
with:
name: Maven publishing artifacts for ${{ matrix.branch }}
path: publish/carpet/fabric-carpet/
Publish-To-Discord:
runs-on: ubuntu-latest
needs: [Build-And-Publish]
steps:
- name: Publish to discord
uses: Crec0/announce-n-crosspost@v1
with:
bot-token: ${{ secrets.DISCORD_BOT_TOKEN }}
channel: '897934715200339999'
content: |
**${{ github.event.release.name }}** has been released!
${{ github.event.release.body }}
Get it on Github Releases: <${{ github.event.release.html_url }}>
Or on CurseForge
Merge-Scarpet-Docs:
runs-on: ubuntu-latest
steps:
- name: Checkout the sources
uses: actions/checkout@v3
with:
ref: master
- name: Merge docs
run: |
./mergedoc.sh
- name: Commit merged docs
continue-on-error: true
run: |
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
git commit -am "Merge docs for '${{ github.event.release.name }}'" || exit 0
git push
Update-Rules-Wiki:
runs-on: ubuntu-latest
steps:
- name: Checkout Carpet sources
uses: actions/checkout@v3
- name: Set up JDK 21
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: 21
cache: 'gradle'
- name: Checkout wiki
uses: actions/checkout@v3
with:
repository: ${{github.repository}}.wiki
path: wiki
- name: Run rule printer into the wiki page
run: |
chmod +x gradlew
./gradlew runServer --args="-- -carpetDumpRules -dumpPath ../wiki/Current-Available-Settings.md"
- name: Commit updated wiki page
continue-on-error: true
run: |
cd wiki
git config --global user.name 'github-actions-bot' # Releases don't have valid commiter info :(
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
git commit -am "Update wiki for '${{ github.event.release.name }}'" || exit 0
git push