14
14
workflow_dispatch :
15
15
16
16
concurrency :
17
- # Allow concurrent run for main, MR, and tag
18
- # Disallow concurrent runs on same MRs, tags, and main (triggered by dispatch, schedule, or push)
19
17
group : ${{ format('{0}-{1}', github.job, github.ref) }}
20
18
cancel-in-progress : true
21
19
@@ -30,15 +28,27 @@ jobs:
30
28
- name : Checkout code
31
29
uses : actions/checkout@v3
32
30
33
- - name : Set up JDK
34
- uses : actions/setup-java@v3
31
+ - name : Cache Gradle dependencies
32
+ uses : actions/cache@v2
33
+ with :
34
+ path : |
35
+ ~/.gradle/caches
36
+ ~/.gradle/wrapper
37
+ key : ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
38
+ restore-keys : |
39
+ ${{ runner.os }}-gradle-
40
+
41
+ - name : Retrieve Project Name
42
+ run : echo "::set-output name=PROJECT_NAME::$(${{github.workspace}}/gradlew -q printProjectName)"
43
+ id : project_name
44
+
45
+ - name : Get Project Name
46
+ run : echo "PROJECT_NAME=${{steps.project_name.outputs.PROJECT_NAME}}" >> $GITHUB_ENV
47
+
48
+ - name : Common Setup
49
+ uses : ./.github/actions/common-setup
35
50
with :
36
51
java-version : ${{ matrix.java }}
37
- distribution : ' zulu'
38
-
39
- - name : Grant execute permission for gradlew
40
- if : runner.os == 'Linux'
41
- run : chmod +x gradlew
42
52
43
53
- name : Build with Gradle
44
54
run : ./gradlew assemble --info
49
59
name : ${{ matrix.os }} Java ${{ matrix.java }} build results
50
60
path : ${{ github.workspace }}/build/libs/
51
61
62
+ outputs :
63
+ project_name : ${{ steps.project_name.outputs.PROJECT_NAME }}
64
+
52
65
test :
53
66
name : Run unit tests
54
67
runs-on : ${{ matrix.os }}
62
75
- name : Checkout code
63
76
uses : actions/checkout@v3
64
77
78
+ - name : Cache Gradle dependencies
79
+ uses : actions/cache@v2
80
+ with :
81
+ path : |
82
+ ~/.gradle/caches
83
+ ~/.gradle/wrapper
84
+ key : ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
85
+ restore-keys : |
86
+ ${{ runner.os }}-gradle-
87
+
65
88
- name : Set up JDK
66
89
uses : actions/setup-java@v3
67
90
with :
@@ -134,18 +157,20 @@ jobs:
134
157
- release
135
158
# Run if on main or tag
136
159
if : always() && (github.ref_name == 'main' || github.ref_type == 'tag')
160
+ env :
161
+ PROJECT_NAME : ${{ needs.build.outputs.project_name }}
137
162
steps :
138
163
- name : Set snapshot environment
139
164
if : github.ref_name == 'main'
140
165
run : |
141
166
echo "RELEASE_TYPE=snapshot" >> $GITHUB_ENV
142
- echo "RELEASE_ADDR=https://github.com/CrimsonWarpedcraft/plugin-template /actions/runs/${{ github.run_id }}" >> $GITHUB_ENV
167
+ echo "RELEASE_ADDR=https://github.com/${{ github.repository }} /actions/runs/${{ github.run_id }}" >> $GITHUB_ENV
143
168
144
169
- name : Set release environment
145
170
if : github.ref_type == 'tag'
146
171
run : |
147
172
echo "RELEASE_TYPE=release" >> $GITHUB_ENV
148
- echo "RELEASE_ADDR=https://github.com/CrimsonWarpedcraft/plugin-template /releases/tag/${{ github.ref_name }}" >> $GITHUB_ENV
173
+ echo "RELEASE_ADDR=https://github.com/${{ github.repository }} /releases/tag/${{ github.ref_name }}" >> $GITHUB_ENV
149
174
150
175
- name : Notify on success
151
176
if : needs.build.result == 'success' && needs.test.result == 'success' && (needs.release.result == 'success' || github.event_name == 'schedule')
@@ -154,9 +179,9 @@ jobs:
154
179
webhook_id : ${{ secrets.DISCORD_WEBHOOK_ID }}
155
180
webhook_token : ${{ secrets.DISCORD_WEBHOOK_TOKEN }}
156
181
color : " #00FF00"
157
- username : " ExamplePlugin Release Bot"
182
+ username : " ${{ env.PROJECT_NAME }} Release Bot"
158
183
message : >
159
- An ExamplePlugin ${{ env.RELEASE_TYPE }} was deployed:
184
+ An ${{ env.PROJECT_NAME }} ${{ env.RELEASE_TYPE }} was deployed by ${{ github.actor }} :
160
185
${{ env.RELEASE_ADDR }}
161
186
162
187
- name : Notify on failure
@@ -166,7 +191,7 @@ jobs:
166
191
webhook_id : ${{ secrets.DISCORD_WEBHOOK_ID }}
167
192
webhook_token : ${{ secrets.DISCORD_WEBHOOK_TOKEN }}
168
193
color : " #FF0000"
169
- username : " ExamplePlugin Release Bot"
194
+ username : " ${{ env.PROJECT_NAME }} Release Bot"
170
195
message : >
171
- An ExamplePlugin ${{ env.RELEASE_TYPE }} failed:
172
- https://github.com/CrimsonWarpedcraft/plugin-template /actions/runs/${{ github.run_id }}
196
+ An ${{ env.PROJECT_NAME }} ${{ env.RELEASE_TYPE }} ran by ${{ github.actor }} failed:
197
+ https://github.com/${{ github.repository }} /actions/runs/${{ github.run_id }}
0 commit comments