generated from CrimsonWarpedcraft/plugin-template
-
-
Notifications
You must be signed in to change notification settings - Fork 1
172 lines (148 loc) · 4.71 KB
/
main.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
name: Build, Test, and Release
on:
push:
branches:
- 'main'
tags:
- 'v*' # For v1.0, v0.1.0, etc
paths:
- 'src/main/java/**'
pull_request:
branches:
- 'main'
paths:
- 'src/main/java/**'
schedule:
- cron: '0 0 * * 6'
workflow_dispatch:
concurrency:
group: ${{ format('{0}-{1}', github.job, github.ref) }}
cancel-in-progress: true
jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ ubuntu-latest, windows-latest ]
java: [ 17 ]
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Cache Gradle dependencies
uses: actions/cache@v4
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-
- name: Common Setup
uses: ./.github/actions/common-setup
with:
java-version: ${{ matrix.java }}
- name: Retrieve Project Name
run: echo "PROJECT_NAME=$(${{github.workspace}}/gradlew -q printProjectName)" >> $GITHUB_OUTPUT
id: project_name
- name: Get Project Name
run: echo "PROJECT_NAME=${{steps.project_name.outputs.PROJECT_NAME}}" >> $GITHUB_ENV
- name: Build with Gradle
run: ./gradlew assemble --info
- name: Upload build results
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.os }} Java ${{ matrix.java }} build results
path: ${{ github.workspace }}/build/libs/
outputs:
project_name: ${{ steps.project_name.outputs.PROJECT_NAME }}
test:
name: Run unit tests
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ ubuntu-latest, windows-latest ]
java: [ 17 ]
needs:
- build
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Cache Gradle dependencies
uses: actions/cache@v4
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-
- name: Common Setup
uses: ./.github/actions/common-setup
with:
java-version: ${{ matrix.java }}
- name: Test with Gradle
run: ./gradlew check --debug
- name: Upload test results
if: ${{ always() }}
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.os }} Java ${{ matrix.java }} test results
path: ${{ github.workspace }}/build/reports/
release:
needs:
- build
- test
runs-on: ubuntu-latest
if: github.ref_type == 'tag' || (github.ref_name == 'main' && github.event_name != 'schedule')
steps:
- name: Set snapshot environment
if: github.ref_name == 'main'
run: |
echo "RELEASE_TAG=0.0.0-RC-1" >> $GITHUB_ENV
- name: Set release environment
if: github.ref_type == 'tag'
run: |
echo "RELEASE_TAG=${{ github.ref_name }}" >> $GITHUB_ENV
- name: Checkout code
uses: actions/checkout@v4
- name: Common Setup
uses: ./.github/actions/common-setup
with:
java-version: 17
- name: Publish with Gradle
run: ./gradlew -Pver=${{ env.RELEASE_TAG }} release
- name: Create Release
uses: softprops/action-gh-release@v2
id: release
if: github.ref_type == 'tag'
with:
files: ${{ github.workspace }}/build/libs/*
generate_release_notes: true
name: ${{ format('Release {0}', github.ref_name) }}
prerelease: ${{ contains(github.ref_name, '-rc-') }}
fail_on_unmatched_files: true
draft: true
outputs:
url: ${{ steps.release.outputs.url }}
notify:
name: Send job complete notification
runs-on: ubuntu-latest
needs:
- build
- test
- release
# Run if on main or tag
if: always() && (github.ref_name == 'main' || github.ref_type == 'tag')
env:
PROJECT_NAME: ${{ needs.build.outputs.project_name }}
steps:
- name: Set snapshot environment
if: github.ref_name == 'main'
run: |
echo "RELEASE_TYPE=snapshot" >> $GITHUB_ENV
echo "RELEASE_ADDR=https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}" >> $GITHUB_ENV
- name: Set release draft environment
if: github.ref_type == 'tag'
run: |
echo "RELEASE_TYPE=release draft" >> $GITHUB_ENV
echo "RELEASE_ADDR=${{ needs.release.outputs.url }}" >> $GITHUB_ENV