generated from CleanroomMC/TemplateDevEnv
-
Notifications
You must be signed in to change notification settings - Fork 28
164 lines (146 loc) · 5.65 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
# 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/[email protected]
with:
token: ${{ secrets.PAT }}
- name: Read current mod version
id: read_version
run: |
mod_version=$(grep "modVersion" 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/[email protected]
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/[email protected]
with:
distribution: 'temurin'
java-version: '8'
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Setup Gradle
uses: gradle/actions/[email protected]
- name: Build Project
run: ./gradlew build
- name: Publish to GitHub
if: env.publish-gh == 'true'
uses: softprops/[email protected]
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 }}
run: ./gradlew curseforge
env:
CURSEFORGE_API_KEY: ${{ secrets.CURSEFORGE_TOKEN }}
CHANGELOG_LOCATION: ${{ env.CHANGELOG_LOCATION }}
RELEASE_TYPE: ${{ inputs.release-type }}
- name: Publish to Modrinth
if: ${{ inputs.publish-mr }}
run: ./gradlew modrinth
env:
MODRINTH_API_KEY: ${{ secrets.MODRINTH_TOKEN }}
CHANGELOG_LOCATION: ${{ env.CHANGELOG_LOCATION }}
RELEASE_TYPE: ${{ inputs.release-type }}
- name: Publish to maven
if: ${{ inputs.publish-maven }}
run: ./gradlew publish
env:
MAVEN_USER: ${{ secrets.MAVEN_NAME }}
MAVEN_PASSWORD: ${{ secrets.MAVEN_PASSWORD }}