Skip to content

Commit 7232a15

Browse files
authored
Adding service factory facility (#9)
* service factory impl * fix upload script --------- Signed-off-by: Peter Kirschner <peter@klib.io>
1 parent 2545754 commit 7232a15

37 files changed

Lines changed: 1375 additions & 225 deletions

.github/scripts/sonatype-status.sh

Lines changed: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
1+
#!/usr/bin/env bash
2+
# -------------------------------------------------------------------------
3+
# sonatype-status.sh – Check Sonatype Central Portal deployment status
4+
# and optionally clean up the local release directory.
5+
#
6+
# For release deployments: queries the Sonatype status API using the
7+
# deployment ID stored by sonatype-upload.sh.
8+
#
9+
# For snapshot deployments: verifies that ALL jar files from the
10+
# snapshot deployment folder are accessible via the Sonatype snapshot
11+
# repository URL.
12+
#
13+
# Usage:
14+
# SONATYPE_BEARER=<token> ./.github/scripts/sonatype-status.sh [options] <release-dir>
15+
#
16+
# Options:
17+
# --snapshot Check snapshot deployment
18+
# --status-url <url> Status API URL (release only)
19+
# --snapshot-url <url> Snapshot repository URL
20+
# --clean Remove release-dir after successful check
21+
#
22+
# Environment:
23+
# SONATYPE_BEARER – Bearer token for authentication (required)
24+
#
25+
# -------------------------------------------------------------------------
26+
set -euo pipefail
27+
28+
# ---- defaults -----------------------------------------------------------
29+
STATUS_URL="https://central.sonatype.com/api/v1/publisher/status"
30+
SNAPSHOT_URL="https://central.sonatype.com/repository/maven-snapshots/"
31+
SNAPSHOT=false
32+
CLEAN=false
33+
RELEASE_DIR=""
34+
# -------------------------------------------------------------------------
35+
36+
usage() {
37+
cat <<-EOF
38+
Usage: $(basename "$0") [options] <release-dir>
39+
40+
Check Sonatype deployment status and optionally clean up.
41+
42+
Options:
43+
--snapshot Check snapshot deployment
44+
--status-url <url> Status API URL (default: Sonatype Central Portal)
45+
--snapshot-url <url> Snapshot repository URL
46+
--clean Remove release-dir after successful verification
47+
-h, --help Show this help message
48+
49+
Environment:
50+
SONATYPE_BEARER Bearer token for authentication (required)
51+
EOF
52+
exit "${1:-0}"
53+
}
54+
55+
# ---- parse arguments ----------------------------------------------------
56+
while [[ $# -gt 0 ]]; do
57+
case "$1" in
58+
--snapshot) SNAPSHOT=true; shift ;;
59+
--status-url) STATUS_URL="$2"; shift 2 ;;
60+
--snapshot-url) SNAPSHOT_URL="$2"; shift 2 ;;
61+
--clean) CLEAN=true; shift ;;
62+
-h|--help) usage 0 ;;
63+
-*) echo "Unknown option: $1" >&2; usage 1 ;;
64+
*) RELEASE_DIR="$1"; shift ;;
65+
esac
66+
done
67+
68+
if [[ -z "${RELEASE_DIR}" ]]; then
69+
echo "Error: release directory argument is required" >&2
70+
usage 1
71+
fi
72+
73+
: "${SONATYPE_BEARER:?Error: SONATYPE_BEARER environment variable is not set}"
74+
75+
# ---- snapshot status check ----------------------------------------------
76+
if [[ "${SNAPSHOT}" == "true" ]]; then
77+
echo "Checking snapshot deployment status ..."
78+
79+
SNAPSHOT_BASE="${SNAPSHOT_URL%/}/"
80+
81+
# Find all jar files in the snapshot deployment folder
82+
JARS=$(find "${RELEASE_DIR}" -name '*.jar' -type f)
83+
84+
if [[ -z "${JARS}" ]]; then
85+
echo "Error: No jar files found in ${RELEASE_DIR} to verify" >&2
86+
exit 1
87+
fi
88+
89+
TOTAL=0
90+
AVAILABLE=0
91+
MISSING=0
92+
93+
while IFS= read -r jar_file; do
94+
# Convert to relative path
95+
REL_PATH="${jar_file#"${RELEASE_DIR}"}"
96+
REL_PATH="${REL_PATH#/}"
97+
98+
CHECK_URL="${SNAPSHOT_BASE}${REL_PATH}"
99+
((TOTAL++)) || true
100+
101+
HTTP_CODE=$(curl -sS -o /dev/null -w '%{http_code}' \
102+
-H "Authorization: Bearer ${SONATYPE_BEARER}" \
103+
"${CHECK_URL}") || true
104+
105+
if [[ "${HTTP_CODE}" -eq 200 ]]; then
106+
echo " OK ${REL_PATH}"
107+
((AVAILABLE++)) || true
108+
else
109+
echo " MISS ${REL_PATH} (HTTP ${HTTP_CODE})"
110+
((MISSING++)) || true
111+
fi
112+
done <<< "${JARS}"
113+
114+
echo "Snapshot verification: ${AVAILABLE}/${TOTAL} artifacts available, ${MISSING} missing."
115+
116+
if [[ "${MISSING}" -gt 0 ]]; then
117+
echo "Error: Not all snapshot artifacts are available yet." >&2
118+
exit 1
119+
fi
120+
121+
echo "All snapshot artifacts are available."
122+
if [[ "${CLEAN}" == "true" ]]; then
123+
echo "Cleaning up release directory: ${RELEASE_DIR}"
124+
rm -rf "${RELEASE_DIR}"
125+
echo "Release directory removed."
126+
fi
127+
exit 0
128+
fi
129+
130+
# ---- release status check -----------------------------------------------
131+
DEPLOYMENTID_FILE="${RELEASE_DIR%/}_DEPLOYMENTID.txt"
132+
133+
if [[ ! -f "${DEPLOYMENTID_FILE}" ]]; then
134+
echo "Error: Deployment ID file not found: ${DEPLOYMENTID_FILE}" >&2
135+
echo "Run sonatype-upload.sh first to create a deployment." >&2
136+
exit 1
137+
fi
138+
139+
DEPLOYMENT_ID=$(cat "${DEPLOYMENTID_FILE}")
140+
141+
if [[ -z "${DEPLOYMENT_ID}" ]]; then
142+
echo "Error: Deployment ID file is empty: ${DEPLOYMENTID_FILE}" >&2
143+
exit 1
144+
fi
145+
146+
echo "Checking release deployment status ..."
147+
echo " Deployment ID: ${DEPLOYMENT_ID}"
148+
echo " Status URL: ${STATUS_URL}"
149+
150+
STATUS_RESPONSE=$(curl -sS \
151+
-H "Authorization: Bearer ${SONATYPE_BEARER}" \
152+
"${STATUS_URL}?id=${DEPLOYMENT_ID}" 2>&1) || true
153+
154+
# Extract deploymentState from JSON response (portable, no grep -P)
155+
STATE=$(echo "${STATUS_RESPONSE}" | sed -n 's/.*"deploymentState"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/p')
156+
157+
echo "Deployment state: ${STATE:-UNKNOWN}"
158+
159+
case "${STATE}" in
160+
PUBLISHED)
161+
echo "Deployment successfully published."
162+
if [[ "${CLEAN}" == "true" ]]; then
163+
echo "Cleaning up release directory: ${RELEASE_DIR}"
164+
rm -rf "${RELEASE_DIR}"
165+
rm -f "${DEPLOYMENTID_FILE}"
166+
echo "Release directory and deployment ID file removed."
167+
fi
168+
exit 0
169+
;;
170+
VALIDATED)
171+
echo "Deployment validated (awaiting manual publishing)."
172+
exit 0
173+
;;
174+
PENDING|VALIDATING|PUBLISHING)
175+
echo "Deployment is still in progress (${STATE})."
176+
exit 2
177+
;;
178+
FAILED)
179+
echo "Error: Deployment failed." >&2
180+
echo "${STATUS_RESPONSE}" >&2
181+
exit 1
182+
;;
183+
*)
184+
echo "Unknown deployment state: ${STATE:-UNKNOWN}" >&2
185+
echo "${STATUS_RESPONSE}" >&2
186+
exit 1
187+
;;
188+
esac

0 commit comments

Comments
 (0)