-
Notifications
You must be signed in to change notification settings - Fork 8
233 lines (229 loc) · 8.26 KB
/
Copy pathjava-cd.yaml
File metadata and controls
233 lines (229 loc) · 8.26 KB
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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
on:
workflow_dispatch:
inputs:
logLevel:
description: 'Log level (info or debug)'
required: true
default: 'info'
push:
tags:
# Semver release tags
- 'v[0-9]+.[0-9]+.[0-9]+*'
# Continuous delivery
name: Java CD
jobs:
generate:
name: Generate changelog
runs-on: ubuntu-latest
steps:
# Checkout repository
- uses: actions/checkout@v2
# Ruby is needed to generate changelog
- name: Setup Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: 3.0
bundler-cache: true
# Generate project changelog with gradle
- name: Generate changelog
env:
CHANGELOG_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
uses: burrunan/gradle-cache-action@v1
with:
arguments: generateChangelog --stacktrace
# Cache generated changelog
- name: Cache changelog
uses: actions/cache@v2
with:
path: ./CHANGELOG.md
key: ${{ runner.os }}-changelog-${{ github.sha }}
build:
name: Build on Linux
runs-on: ubuntu-latest
steps:
# Checkout repository
- uses: actions/checkout@v2
# Setup Java environment
- name: Setup JDK 1.8
uses: actions/setup-java@v1
with:
java-version: 1.8
# Pull gradle project files from cache
- name: Cache gradle files
id: cache-gradle
uses: actions/cache@v2
with:
path: |
./.gradle
./buildSrc/.gradle
key: ${{ runner.os }}-gradle-${{ hashFiles('**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-
# Check if cache was pulled correctly
- name: Validate cache
id: cache-validate
run: |
echo Validating gradle cache...
if [ "${{ steps.cache-gradle.outputs.cache-hit }}" != true ]; then
echo ::set-output name=fail::true
echo ::error Gradle project files were not pulled from cache
fi
# Assemble the output of this project with gradle
- name: Assemble distribution
uses: burrunan/gradle-cache-action@v1
with:
arguments: assembleDist -x generateChangelog --stacktrace
# Cache distribution files
- name: Cache distribution
id: cache-build
uses: actions/cache@v2
with:
path: |
./build/distributions
key: ${{ runner.os }}-dist-${{ github.sha }}
release:
name: Release project
runs-on: ubuntu-latest
needs: [ build, generate ]
steps:
# Checkout repository
- uses: actions/checkout@v2
with:
ref: ${{ github.ref }} # Checkout target tag
fetch-depth: 0 # Fetch all branches and tags
# Ruby is needed to generate changelog
- name: Setup Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: 3.0
bundler-cache: true
# Print information about working tree
- name: Inspect working tree
run: |
printf "Working tree files: \n%s\n\n" "$(ls | sed 's/.*/-- &/')"
if [ -d ./build ]; then
printf "Build files found: \n%s\n\n" "$(ls ./build | sed 's/.*/-- &/')"
fi
if [ -d ./build/distributions ]; then
printf "Distributions found: \n%s\n" "$(ls ./build/distributions | sed 's/.*/-- &/')"
fi
# Delete the changelog, it will be pulled from cache in next step
if [ -f ./CHANGELOG.md ]; then
rm ./CHANGELOG.md
if [ $? != 0 ]; then
echo ::error Unable to delete CHANGELOG.md
fi
fi
# Pull gradle project files from cache
- name: Cache gradle files
id: cache-gradle
uses: actions/cache@v2
with:
path: |
./.gradle
./buildSrc/.gradle
key: ${{ runner.os }}-gradle-${{ hashFiles('**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-
# Pull generated changelog from cache
- name: Cache changelog
id: cache-changelog
uses: actions/cache@v2
with:
path: ./CHANGELOG.md
key: ${{ runner.os }}-changelog-${{ github.sha }}
# Pull distribution files from cache
- name: Cache distribution
id: cache-build
uses: actions/cache@v2
with:
path: |
./build/distributions
key: ${{ runner.os }}-dist-${{ github.sha }}
# Check if cache was pulled correctly
- name: Validate cache
id: cache-validate
run: |
echo Validating changelog cache...
if [ "${{ steps.cache-gradle.outputs.cache-hit }}" != true ]; then
echo ::set-output name=fail::true
echo ::error Gradle project files were not pulled from cache
fi
if [ "${{ steps.cache-changelog.outputs.cache-hit }}" != true ]; then
echo ::set-output name=fail::true
echo ::error Changelog was not pulled from cache
fi
if [ "${{ steps.cache-build.outputs.cache-hit }}" != true ]; then
echo ::set-output name=fail::true
echo ::error distributions were not pulled from cache
fi
# Read previous tag created in repository
# Parse and see if it's a pre-release
- name: Read last tag
id: read-tag
run: |
echo ::set-output name=tag::$(git describe --abbrev=0 --match v[0-9]*.[0-9]*.[0-9]* ${{ github.ref }}^)
echo ::set-output name=ref::$(echo ${{ github.ref }} | cut -c 11-)
echo ::set-output name=name::$(echo ${{ github.ref }} | cut -c 12-)
if [[ ${{ github.ref }} =~ ^.*\-(alpha|beta|rc).*$ ]]; then
echo ::set-output name=isPreRelease::true
fi
# Generate changelog including only latest tag
- uses: burrunan/gradle-cache-action@v1
name: Generate release text
env:
CHANGELOG_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
arguments: generateChangelog
properties: |
cg.sinceTag=${{ steps.read-tag.outputs.tag }}
cg.output=./release_text.md
cg.header=''
# Remove notice from generated changelog
- name: Trim release text
run: |
head -n -3 release_text.md > tmp.txt
tail -n +4 tmp.txt > release_text.md
less release_text.md
# Create a release in Github repository
- name: Create Github release
id: create-release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.read-tag.outputs.ref }}
release_name: ${{ steps.read-tag.outputs.name }}
prerelease: ${{ steps.read-tag.outputs.isPreRelease }}
body_path: ./release_text.md
draft: true
# Upload distribution artifact to release
- name: Upload distribution zip
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create-release.outputs.upload_url }}
asset_path: ./build/distributions/pz-zdoc-${{ steps.read-tag.outputs.name }}.zip
asset_name: pz-zdoc-${{ steps.read-tag.outputs.name }}.zip
asset_content_type: application/zip
# Upload distribution artifact to release
- name: Upload distribution tar
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create-release.outputs.upload_url }}
asset_path: ./build/distributions/pz-zdoc-${{ steps.read-tag.outputs.name }}.tar
asset_name: pz-zdoc-${{ steps.read-tag.outputs.name }}.tar
asset_content_type: application/tar
# Publish to Sonatype repository
- uses: burrunan/gradle-cache-action@v1
name: Publish to Sonatype
with:
arguments: publishToSonatypeAndCloseStagingRepository
properties: |
signingKey=${{ secrets.GPG_SIGNING_KEY }}
signingPassword=${{ secrets.GPG_SIGNING_PASSWORD }}
sonatypeUsername=${{ secrets.SONATYPE_USERNAME }}
sonatypePassword=${{ secrets.SONATYPE_PASSWORD }}