-
Notifications
You must be signed in to change notification settings - Fork 0
210 lines (177 loc) · 6.34 KB
/
Copy pathdeploy.yml
File metadata and controls
210 lines (177 loc) · 6.34 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
name: Publish
on:
push:
branches: [ main ]
concurrency:
group: main-${{ github.sha }}
cancel-in-progress: true
permissions:
contents: write
packages: 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://github.com/${REPO}/packages)"
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
publish:
name: Publish SDK
needs: test-and-coverage
runs-on: macos-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
distribution: zulu
java-version: 17
- uses: gradle/actions/setup-gradle@v4
- name: Publish to GitHub Packages
env:
MAVEN_REPO_USERNAME: ${{ github.actor }}
MAVEN_REPO_PASSWORD: ${{ secrets.GITHUB_TOKEN }}
run: ./gradlew publishAllPublicationsToGitHubPackagesRepository
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: [publish, update-badges]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- 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
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
VERSION=${{ steps.version.outputs.version }}
TAG="v${VERSION}"
if gh release view "$TAG" > /dev/null 2>&1; then
echo "Release $TAG already exists, skipping."
else
gh release create "$TAG" \
--title "$TAG" \
--generate-notes \
--target main
fi