-
Notifications
You must be signed in to change notification settings - Fork 0
246 lines (209 loc) · 7.76 KB
/
Copy pathdeploy.yml
File metadata and controls
246 lines (209 loc) · 7.76 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
234
235
236
237
238
239
240
241
242
243
244
245
246
name: Publish
on:
push:
branches: [ main ]
concurrency:
group: main-${{ github.sha }}
cancel-in-progress: true
permissions:
contents: write
pages: write
id-token: write
jobs:
test-and-coverage:
name: Tests & Coverage
runs-on: ubuntu-latest
outputs:
coverage: ${{ steps.coverage.outputs.percentage }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
distribution: zulu
java-version: 17
- uses: gradle/actions/setup-gradle@v4
- name: Run tests with coverage
run: >
./gradlew
:json-cmp:jvmTest
koverXmlReport
- name: Parse coverage percentage
id: coverage
run: |
REPORT="build/reports/kover/report.xml"
if [ -f "$REPORT" ]; then
MISSED=$(grep -oP 'type="INSTRUCTION"[^/]*missed="\K[0-9]+' "$REPORT" | head -1)
COVERED=$(grep -oP 'type="INSTRUCTION"[^/]*covered="\K[0-9]+' "$REPORT" | head -1)
TOTAL=$((MISSED + COVERED))
if [ "$TOTAL" -gt 0 ]; then
PERCENTAGE=$((COVERED * 100 / TOTAL))
else
PERCENTAGE=0
fi
else
PERCENTAGE=0
fi
echo "percentage=$PERCENTAGE" >> "$GITHUB_OUTPUT"
- name: Upload coverage report
uses: actions/upload-artifact@v4
with:
name: coverage-report
path: build/reports/kover/
update-badges:
name: Update Badges
needs: test-and-coverage
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: main
- name: Determine coverage badge color
id: badge
run: |
COVERAGE=${{ needs.test-and-coverage.outputs.coverage }}
if [ "$COVERAGE" -ge 80 ]; then
COLOR="brightgreen"
elif [ "$COVERAGE" -ge 60 ]; then
COLOR="green"
elif [ "$COVERAGE" -ge 40 ]; then
COLOR="yellowgreen"
elif [ "$COVERAGE" -ge 20 ]; then
COLOR="orange"
else
COLOR="red"
fi
echo "color=$COLOR" >> "$GITHUB_OUTPUT"
- name: Read version from gradle.properties
id: version
run: |
VERSION=$(grep 'jsoncmp.version=' gradle.properties | cut -d= -f2)
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
- name: Update README badges
run: |
COVERAGE=${{ needs.test-and-coverage.outputs.coverage }}
COLOR=${{ steps.badge.outputs.color }}
REPO=${{ github.repository }}
VERSION=${{ steps.version.outputs.version }}
BUILD_BADGE="[](https://github.com/${REPO}/actions/workflows/deploy.yml)"
COVERAGE_BADGE="[](https://github.com/${REPO}/actions/workflows/deploy.yml)"
VERSION_ESCAPED=$(echo "$VERSION" | sed 's/-/--/g')
MAVEN_BADGE="[](https://central.sonatype.com/artifact/dev.skymansandy/json-cmp)"
BADGE_LINE="${BUILD_BADGE} ${COVERAGE_BADGE} ${MAVEN_BADGE}"
if grep -q '^\[!\[Build\]' README.md; then
sed -i "1,/^\[!\[Build\]/s|^\[!\[Build\].*|${BADGE_LINE}|" README.md
elif grep -q '^\[!\[Coverage\]' README.md; then
sed -i "1,/^\[!\[Coverage\]/s|^\[!\[Coverage\].*|${BADGE_LINE}|" README.md
else
sed -i "1a\\\\${BADGE_LINE}\n" README.md
fi
- name: Update version in README and docs
run: |
VERSION=${{ steps.version.outputs.version }}
sed -i "s|implementation(\"dev.skymansandy:json-cmp:[^\"]*\")|implementation(\"dev.skymansandy:json-cmp:${VERSION}\")|" README.md
find docs -name '*.md' -exec sed -i "s|implementation(\"dev.skymansandy:json-cmp:[^\"]*\")|implementation(\"dev.skymansandy:json-cmp:${VERSION}\")|" {} +
- name: Commit badge updates
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add README.md
git diff --staged --quiet || git commit -m "ci: Update README badges [skip ci]"
git push
check-skip:
name: Check Skip Conditions
runs-on: ubuntu-latest
outputs:
skip_release: ${{ steps.check.outputs.skip_release }}
steps:
- name: Check if chore commit
id: check
run: |
COMMIT_MSG="${{ github.event.head_commit.message }}"
FIRST_LINE=$(echo "$COMMIT_MSG" | head -n 1)
if [[ "$FIRST_LINE" == chore:* ]]; then
echo "skip_release=true" >> "$GITHUB_OUTPUT"
else
echo "skip_release=false" >> "$GITHUB_OUTPUT"
fi
publish:
name: Publish to Maven Central
needs: [test-and-coverage, check-skip]
if: needs.check-skip.outputs.skip_release != 'true'
runs-on: macos-latest
environment: default
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
distribution: zulu
java-version: 17
- uses: gradle/actions/setup-gradle@v4
- name: Publish and release to Maven Central
env:
ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.OSSRH_USERNAME }}
ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.OSSRH_PASSWORD }}
ORG_GRADLE_PROJECT_signingInMemoryKey: ${{ secrets.GPG_PRIVATE_KEY }}
ORG_GRADLE_PROJECT_signingInMemoryKeyPassword: ${{ secrets.GPG_PASSPHRASE }}
run: ./gradlew publishAndReleaseToMavenCentral --no-configuration-cache
deploy-docs:
name: Deploy Docs
needs: test-and-coverage
runs-on: ubuntu-latest
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.x"
- name: Install MkDocs and theme
run: pip install mkdocs-material
- name: Build docs
run: mkdocs build
- name: Setup Pages
uses: actions/configure-pages@v5
- name: Upload Pages artifact
uses: actions/upload-pages-artifact@v3
with:
path: site/
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
github-release:
name: GitHub Release
needs: [test-and-coverage, update-badges]
if: always() && needs.test-and-coverage.result == 'success'
continue-on-error: true
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
distribution: zulu
java-version: 17
- uses: gradle/actions/setup-gradle@v4
- name: Build APK
run: ./gradlew :androidApp:assembleRelease
- name: Read version from gradle.properties
id: version
run: |
VERSION=$(grep 'jsoncmp.version=' gradle.properties | cut -d= -f2)
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
- name: Create GitHub Release with APK
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
VERSION=${{ steps.version.outputs.version }}
TAG="v${VERSION}"
APK_PATH=$(find androidApp/build/outputs/apk/release -name '*.apk' | head -1)
APK_NAME="JsonCMP-Sample-${VERSION}.apk"
cp "$APK_PATH" "$APK_NAME"
if gh release view "$TAG" > /dev/null 2>&1; then
echo "Release $TAG already exists, skipping."
else
gh release create "$TAG" \
"$APK_NAME" \
--title "$TAG" \
--generate-notes \
--target main
fi