-
Notifications
You must be signed in to change notification settings - Fork 0
189 lines (158 loc) · 6.18 KB
/
Copy pathrelease.yml
File metadata and controls
189 lines (158 loc) · 6.18 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
name: ClientCore Releases
on:
push:
branches:
- '**'
workflow_dispatch:
permissions:
contents: write
concurrency:
group: clientcore-release-${{ github.ref }}
cancel-in-progress: false
env:
GRADLE_OPTS: "-Dorg.gradle.daemon=false"
jobs:
build_release:
name: Build & Publish Releases
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Java JDK 25
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: '25'
cache: gradle
- name: Build Plugin
run: |
chmod +x ./gradlew
./gradlew clean build
- name: Prepare Release Metadata
id: meta
shell: bash
run: |
set -euo pipefail
VERSION=$(./gradlew properties -q | awk '/^version:/ { print $2; exit }')
if [ -z "$VERSION" ]; then
echo "Gradle project version could not be detected." >&2
exit 1
fi
SHORT_SHA=$(git rev-parse --short HEAD)
COMMIT_COUNT=$(git rev-list --count HEAD)
VERSION_TAG="v${VERSION}"
DEV_TAG="latest-devbuild"
JAR_FILE=$(find build/libs -maxdepth 1 -type f -name "*.jar" ! -name "*-sources.jar" ! -name "*-javadoc.jar" | sort | head -n 1)
if [ -z "$JAR_FILE" ] || [ ! -f "$JAR_FILE" ]; then
echo "No build jar found in build/libs." >&2
exit 1
fi
mkdir -p dist
RELEASE_JAR="dist/ClientCore-${VERSION}.jar"
DEV_JAR="dist/ClientCore-build-${COMMIT_COUNT}.jar"
cp "$JAR_FILE" "$RELEASE_JAR"
cp "$JAR_FILE" "$DEV_JAR"
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
echo "version_tag=$VERSION_TAG" >> "$GITHUB_OUTPUT"
echo "dev_tag=$DEV_TAG" >> "$GITHUB_OUTPUT"
echo "short_sha=$SHORT_SHA" >> "$GITHUB_OUTPUT"
echo "release_jar=$RELEASE_JAR" >> "$GITHUB_OUTPUT"
echo "dev_jar=$DEV_JAR" >> "$GITHUB_OUTPUT"
- name: Generate Changelogs
id: changelog
shell: bash
run: |
set -euo pipefail
VERSION_TAG="${{ steps.meta.outputs.version_tag }}"
VERSION="${{ steps.meta.outputs.version }}"
SHORT_SHA="${{ steps.meta.outputs.short_sha }}"
{
echo "## ClientCore ${VERSION}"
echo
echo "- Version: \`${VERSION}\`"
echo "- Commit: \`${GITHUB_SHA}\`"
echo "- Branch: \`${GITHUB_REF_NAME}\`"
echo "- Build: [#${GITHUB_RUN_NUMBER}](${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID})"
} > version_changelog.md
{
echo "## Latest ClientCore Dev Build"
echo
echo "- Version: \`${VERSION}\`"
echo "- Commit: \`${GITHUB_SHA}\`"
echo "- Branch: \`${GITHUB_REF_NAME}\`"
echo "- Build: [#${GITHUB_RUN_NUMBER}](${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID})"
} > devbuild_changelog.md
echo "version_body=version_changelog.md" >> "$GITHUB_OUTPUT"
echo "dev_body=devbuild_changelog.md" >> "$GITHUB_OUTPUT"
- name: Publish Latest Dev Build Release
if: github.ref_name == github.event.repository.default_branch
env:
GH_TOKEN: ${{ github.token }}
shell: bash
run: |
set -euo pipefail
DEV_TAG="${{ steps.meta.outputs.dev_tag }}"
DEV_JAR="${{ steps.meta.outputs.dev_jar }}"
DEV_BODY="${{ steps.changelog.outputs.dev_body }}"
git tag -f "$DEV_TAG" "$GITHUB_SHA"
git push -f origin "refs/tags/${DEV_TAG}"
if gh release view "$DEV_TAG" >/dev/null 2>&1; then
# Delete old assets to prevent accumulating Dev Build jars with different commit counts
OLD_ASSETS=$(gh release view "$DEV_TAG" --json assets --jq '.assets.[].name')
for ASSET in $OLD_ASSETS; do
if [[ "$ASSET" == *.jar ]]; then
gh release delete-asset "$DEV_TAG" "$ASSET" -y || true
fi
done
gh release edit "$DEV_TAG" \
--title "Latest ClientCore Dev Build" \
--notes-file "$DEV_BODY" \
--latest
else
gh release create "$DEV_TAG" \
--title "Latest ClientCore Dev Build" \
--notes-file "$DEV_BODY" \
--latest
fi
gh release upload "$DEV_TAG" "$DEV_JAR" --clobber
- name: Publish Version Release
if: github.ref_name == github.event.repository.default_branch
env:
GH_TOKEN: ${{ github.token }}
shell: bash
run: |
set -euo pipefail
VERSION_TAG="${{ steps.meta.outputs.version_tag }}"
RELEASE_JAR="${{ steps.meta.outputs.release_jar }}"
VERSION_BODY="${{ steps.changelog.outputs.version_body }}"
git tag -f "$VERSION_TAG" "$GITHUB_SHA"
git push -f origin "refs/tags/${VERSION_TAG}"
if gh release view "$VERSION_TAG" >/dev/null 2>&1; then
gh release edit "$VERSION_TAG" \
--title "ClientCore ${{ steps.meta.outputs.version }}" \
--notes-file "$VERSION_BODY" \
--prerelease \
--latest=false
else
gh release create "$VERSION_TAG" \
--title "ClientCore ${{ steps.meta.outputs.version }}" \
--notes-file "$VERSION_BODY" \
--prerelease \
--latest=false
fi
gh release upload "$VERSION_TAG" "$RELEASE_JAR" --clobber
- name: Upload Workflow Artifact
uses: actions/upload-artifact@v4
with:
name: ClientCore-${{ steps.meta.outputs.version }}-${{ steps.meta.outputs.short_sha }}
path: dist/*.jar
retention-days: 14
- name: Trigger DaWeb Catalog Update
if: github.ref_name == github.event.repository.default_branch
uses: peter-evans/repository-dispatch@v3
with:
token: ${{ secrets.PAT }}
repository: VoChiDanh/DaWeb
event-type: update-catalog