generated from CleanroomMC/TemplateDevEnv
-
Notifications
You must be signed in to change notification settings - Fork 19
171 lines (154 loc) · 5.87 KB
/
build_and_publish.yaml
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
# This workflow must be manually triggered. It accepts a version and a release type.
# First it sets the version in gradle.properties to the new version and pushes it.
# Then it generates a log, based on commits.
# After that builds a jar and uploads it to curseforge/modrinth/GitHub releases
name: Build and Publish mod
on:
workflow_dispatch:
inputs:
version:
description: 'Mod version'
required: true
release-type:
description: 'Release type'
type: choice
default: 'beta'
options:
- 'release'
- 'beta'
- 'alpha'
publish-cf:
description: Publish to CF
default: true
type: boolean
publish-mr:
description: Publish to MR
default: true
type: boolean
publish-gh:
description: Publish to Github
default: true
type: boolean
publish-maven:
description: Publish to maven
default: true
type: boolean
overwrite:
description: 'Overwrite current tag (if exists)'
default: false
required: true
type: boolean
env:
CHANGELOG_LOCATION: "build/gh_changelog.md"
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v3
with:
token: ${{ secrets.PAT }}
- name: Read current mod version
id: read_version
run: |
mod_version=$(grep -E '^ *modVersion[[:space:]]*=' gradle.properties | cut -d'=' -f2 | tr -d '[:space:]')
echo "Current mod version: $mod_version"
if [ "$mod_version" == "${{inputs.version}}" ]; then
echo "UPDATED=true" >> $GITHUB_ENV
else
echo "UPDATED=false" >> $GITHUB_ENV
fi
# Abort if a tag already exists and the mod is updated to that version and overwriting is not allowed
# If the tag does not exist force publish to gh if publishing to cf/mr (for changelog)
- name: Check if tag already exists
run: |
if git rev-parse --verify --quiet "v${{ github.event.inputs.version }}"; then
if [ "${{ inputs.publish-gh }}" == "true" ] && [ "$UPDATED" == "true" ] && [ "${{ inputs.overwrite }}" == "false" ]; then
echo "Version tag ${{ github.event.inputs.version }} already exists and the mod is updated to that version and overwriting is forbidden."
echo "Aborting workflow!"
exit 1
fi
echo "publish-gh=${{ inputs.publish-gh }}" >> $GITHUB_ENV
else
if [ "${{ inputs.publish-cf }}" == "true" ] || [ "${{ inputs.publish-mr }}" == "true" ]; then
echo "publish-gh=true" >> $GITHUB_ENV
else
echo "publish-gh=${{ inputs.publish-gh }}" >> $GITHUB_ENV
fi
fi
- name: Set version
if: env.UPDATED == 'false' # only change new version if it's not already updated
run: sed -i "s/modVersion.*=.*/modVersion = ${{ github.event.inputs.version }}/g" gradle.properties
- name: Commit and push gradle.properties
if: env.UPDATED == 'false' # only push new version if it's not already updated
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: "Bump version to ${{ github.event.inputs.version }}"
commit_options: "--no-verify"
file_pattern: gradle.properties
tagging_message: "v${{ github.event.inputs.version }}"
- name: Check for publishing
run: |
if [ "$publish-gh" == "false" ] && [ "${{ inputs.publish-cf-mr }}" == "false" ] && [ "${{ inputs.publish-maven }}" == "false" ]; then
echo "Not publishing to Github, Curse, Modrinth or Maven."
exit 0
fi
- name: Setup Java
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '8'
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Build jars
uses: gradle/gradle-build-action@v2
with:
arguments: build
- name: Publish to GitHub
if: env.publish-gh == 'true'
uses: softprops/action-gh-release@v1
with:
tag_name: "v${{ inputs.version }}"
token: ${{ secrets.PAT }}
files: "build/libs/*.jar"
generate_release_notes: true
fail_on_unmatched_files: true
- name: Get Changelog
run: |
mkdir -p build
RELEASE_URL="https://api.github.com/repos/${{ github.repository }}/releases/tags/v${{ inputs.version }}"
RELEASE_JSON=$(curl -sSL $RELEASE_URL)
CHANGELOG="$(echo $RELEASE_JSON | jq -r '.body')"
if [ "$CHANGELOG" == "null" ]; then
echo "No changelog found" > $CHANGELOG_LOCATION
else
echo "$CHANGELOG" > $CHANGELOG_LOCATION
fi
- name: Publish to Curseforge
if: ${{ inputs.publish-cf }}
uses: gradle/gradle-build-action@v2
env:
CURSEFORGE_API_KEY: ${{ secrets.CURSEFORGE_TOKEN }}
CHANGELOG_LOCATION: ${{ env.CHANGELOG_LOCATION }}
RELEASE_TYPE: ${{ inputs.release-type }}
with:
arguments: 'curseforge'
generate-job-summary: false
- name: Publish to Modrinth
if: ${{ inputs.publish-mr }}
uses: gradle/gradle-build-action@v2
env:
MODRINTH_API_KEY: ${{ secrets.MODRINTH_TOKEN }}
CHANGELOG_LOCATION: ${{ env.CHANGELOG_LOCATION }}
RELEASE_TYPE: ${{ inputs.release-type }}
with:
arguments: 'modrinth'
generate-job-summary: false
- name: Publish to maven
if: ${{ inputs.publish-maven }}
uses: gradle/gradle-build-action@v2
with:
arguments: publish
env:
MAVEN_USER: ${{ secrets.MAVEN_NAME }}
MAVEN_PASSWORD: ${{ secrets.MAVEN_PASSWORD }}