forked from web-push-libs/webpush-java
-
Notifications
You must be signed in to change notification settings - Fork 0
166 lines (149 loc) · 5.75 KB
/
Copy pathrelease.yml
File metadata and controls
166 lines (149 loc) · 5.75 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
name: Build release artifacts
on:
release:
types: [published]
push:
branches: [master]
paths:
- '.github/release-version'
workflow_dispatch:
inputs:
tag:
description: Existing tag to build (for example 5.1.4 or v5.1.4)
required: true
type: string
permissions:
contents: write
jobs:
release:
name: Build and validate Maven artifacts
runs-on: ubuntu-latest
env:
EVENT_RELEASE_TAG: ${{ github.event.release.tag_name || inputs.tag }}
JITPACK_GROUP: com.github.p4535992
JITPACK_ARTIFACT: webpush-java
steps:
- name: Checkout requested revision
uses: actions/checkout@v6
with:
ref: ${{ github.event_name == 'push' && github.sha || github.event.release.tag_name || inputs.tag }}
- name: Set up JDK 11
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: '11'
- name: Set up Gradle
uses: gradle/actions/setup-gradle@v4
- name: Resolve release version
shell: bash
run: |
set -euo pipefail
if [[ "$GITHUB_EVENT_NAME" == "push" ]]; then
tag="$(tr -d '[:space:]' < .github/release-version)"
else
tag="$EVENT_RELEASE_TAG"
fi
version="${tag#v}"
if [[ ! "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+([.-][0-9A-Za-z.-]+)?$ ]]; then
echo "::error::Unsupported release tag '$tag'. Expected 1.2.3 or v1.2.3."
exit 1
fi
echo "RELEASE_TAG=$tag" >> "$GITHUB_ENV"
echo "RELEASE_VERSION=$version" >> "$GITHUB_ENV"
echo "Building version $version from $tag"
- name: Build and simulate JitPack publication
shell: bash
run: |
GROUP="$JITPACK_GROUP" \
ARTIFACT="$JITPACK_ARTIFACT" \
VERSION="$RELEASE_VERSION" \
./gradlew clean build publishToMavenLocal
- name: Verify release JARs
shell: bash
run: |
set -euo pipefail
for file in \
"build/libs/web-push-${RELEASE_VERSION}.jar" \
"build/libs/web-push-${RELEASE_VERSION}-sources.jar" \
"build/libs/web-push-${RELEASE_VERSION}-javadoc.jar"; do
test -f "$file" || { echo "::error::Expected artifact not found: $file"; exit 1; }
done
- name: Verify JitPack Maven publication
shell: bash
run: |
set -euo pipefail
base="$HOME/.m2/repository/com/github/p4535992/webpush-java/$RELEASE_VERSION"
for file in \
"$base/webpush-java-${RELEASE_VERSION}.pom" \
"$base/webpush-java-${RELEASE_VERSION}.jar" \
"$base/webpush-java-${RELEASE_VERSION}-sources.jar" \
"$base/webpush-java-${RELEASE_VERSION}-javadoc.jar"; do
test -f "$file" || { echo "::error::JitPack-compatible Maven artifact not found: $file"; exit 1; }
done
echo "Validated com.github.p4535992:webpush-java:$RELEASE_VERSION"
- name: Store workflow artifacts
uses: actions/upload-artifact@v4
with:
name: web-push-${{ env.RELEASE_TAG }}
path: build/libs/*.jar
if-no-files-found: error
- name: Ensure GitHub Release exists
if: github.event_name == 'push'
env:
GH_TOKEN: ${{ github.token }}
shell: bash
run: |
set -euo pipefail
if gh release view "$RELEASE_TAG" >/dev/null 2>&1; then
echo "Release $RELEASE_TAG already exists; reusing it."
else
gh release create "$RELEASE_TAG" \
--target "$GITHUB_SHA" \
--title "web-push $RELEASE_VERSION" \
--generate-notes
fi
- name: Attach JARs to GitHub Release
env:
GH_TOKEN: ${{ github.token }}
shell: bash
run: |
set -euo pipefail
if gh release view "$RELEASE_TAG" >/dev/null 2>&1; then
gh release upload "$RELEASE_TAG" \
"build/libs/web-push-${RELEASE_VERSION}.jar" \
"build/libs/web-push-${RELEASE_VERSION}-sources.jar" \
"build/libs/web-push-${RELEASE_VERSION}-javadoc.jar" \
--clobber
else
echo "No GitHub Release exists for $RELEASE_TAG; skipping release attachments."
fi
- name: Verify artifact from JitPack
shell: bash
run: |
set -euo pipefail
url="https://jitpack.io/com/github/p4535992/webpush-java/${RELEASE_VERSION}/webpush-java-${RELEASE_VERSION}.pom"
log="https://jitpack.io/com/github/p4535992/webpush-java/${RELEASE_VERSION}/build.log"
echo "Requesting $url"
status=""
for attempt in 1 2 3 4 5 6; do
status="$(curl --location --silent --show-error \
--connect-timeout 20 --max-time 180 \
--output /tmp/webpush-java.pom \
--write-out '%{http_code}' \
"$url" || true)"
if [[ "$status" == "200" ]]; then
break
fi
echo "Attempt $attempt returned HTTP $status; waiting before retry."
sleep 20
done
if [[ "$status" != "200" ]]; then
echo "::error::JitPack did not return the POM (last HTTP status: $status)."
echo "--- JitPack build log ---"
curl --location --silent --show-error "$log" || true
exit 1
fi
grep -q '<groupId>com.github.p4535992</groupId>' /tmp/webpush-java.pom
grep -q '<artifactId>webpush-java</artifactId>' /tmp/webpush-java.pom
grep -q "<version>${RELEASE_VERSION}</version>" /tmp/webpush-java.pom
echo "JitPack artifact com.github.p4535992:webpush-java:${RELEASE_VERSION} is available."