Compare commits
11
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
75dbed243c
|
||
|
|
6ca2e04ba8 | ||
|
|
ef327d208c | ||
|
|
1ddba883c9 | ||
|
|
da8044d6f2 | ||
|
|
67ba48da1f | ||
|
|
5196609974 | ||
|
|
49e09a6776 | ||
|
|
748016f105 | ||
|
|
6514aaa688 | ||
|
|
3ac47adc21 |
No files matched your search
+18
-51
@@ -1,58 +1,25 @@
|
||||
version: 2.1
|
||||
setup: true
|
||||
parameters:
|
||||
run_rc_finalize_sweep:
|
||||
type: boolean
|
||||
default: false
|
||||
orbs:
|
||||
orb-tools: circleci/orb-tools@12.3
|
||||
shellcheck: circleci/shellcheck@3.2
|
||||
|
||||
filters: &filters
|
||||
tags:
|
||||
only: /.*/
|
||||
|
||||
jobs:
|
||||
rc-finalize-sweep:
|
||||
central-status:
|
||||
docker:
|
||||
- image: cimg/python:3.12
|
||||
- image: cimg/python:3.12
|
||||
resource_class: small
|
||||
environment:
|
||||
QQQ_CENTRAL_DEPLOYMENT_ID: 5440c24f-9945-4b7f-a295-9d79e695cf3c
|
||||
steps:
|
||||
- checkout
|
||||
- run:
|
||||
name: Reconcile pending QBit releases
|
||||
command: |
|
||||
RC_REPOSITORIES_JSON="$(cat tools/rc-repositories.json)" \
|
||||
python3 src/scripts/rc_finalize_sweep.py
|
||||
|
||||
- checkout
|
||||
- run:
|
||||
name: Read existing Sonatype deployment state
|
||||
command: python3 tools/central_status.py
|
||||
no_output_timeout: 2m
|
||||
workflows:
|
||||
lint-pack:
|
||||
when:
|
||||
not: << pipeline.parameters.run_rc_finalize_sweep >>
|
||||
diagnose-existing-deployment:
|
||||
jobs:
|
||||
- orb-tools/lint:
|
||||
filters: *filters
|
||||
- orb-tools/pack:
|
||||
filters: *filters
|
||||
- orb-tools/review:
|
||||
orb_name: qqq-orb
|
||||
filters: *filters
|
||||
- shellcheck/check:
|
||||
filters: *filters
|
||||
# Triggers the next workflow in the Orb Development Kit.
|
||||
- orb-tools/continue:
|
||||
pipeline_number: << pipeline.number >>
|
||||
vcs_type: << pipeline.project.type >>
|
||||
orb_name: qqq-orb
|
||||
requires: [orb-tools/lint, orb-tools/pack, orb-tools/review, shellcheck/check]
|
||||
filters: *filters
|
||||
reconcile-releases:
|
||||
when: << pipeline.parameters.run_rc_finalize_sweep >>
|
||||
jobs:
|
||||
- rc-finalize-sweep:
|
||||
context: qqq-maven-registry-credentials
|
||||
filters:
|
||||
branches:
|
||||
only: main
|
||||
tags:
|
||||
ignore: /.*/
|
||||
- central-status:
|
||||
context:
|
||||
- qqq-maven-registry-credentials
|
||||
filters:
|
||||
branches:
|
||||
only: diagnostic/central-status
|
||||
tags:
|
||||
ignore: /.*/
|
||||
@@ -61,7 +61,6 @@ jobs:
|
||||
bash tests/test_all_artifact.sh
|
||||
python3 tests/test_maven_ci_rc_completion.py
|
||||
bash tests/test_maven_ci_push.sh
|
||||
bash tests/test_create_github_release.sh
|
||||
bash tests/test_maven_ci_cache.sh
|
||||
bash tests/test_maven_ci_install.sh
|
||||
bash tests/test_snapshot_refresh.sh
|
||||
|
||||
@@ -79,7 +79,6 @@ test-pipelines: pack
|
||||
bash tests/test_all_artifact.sh
|
||||
python3 tests/test_maven_ci_rc_completion.py
|
||||
bash tests/test_maven_ci_push.sh
|
||||
bash tests/test_create_github_release.sh
|
||||
bash tests/test_maven_ci_cache.sh
|
||||
bash tests/test_maven_ci_install.sh
|
||||
bash tests/test_snapshot_refresh.sh
|
||||
|
||||
@@ -208,73 +208,50 @@ REQUEST_BODY=$(jq -n \
|
||||
generate_release_notes: true
|
||||
}')
|
||||
|
||||
# Keep response bodies private: errors can contain repository details or echoed input.
|
||||
request_release() {
|
||||
local method="$1" url="$2"
|
||||
local args=(-s --connect-timeout 10 --max-time 60 -w "\n%{http_code}" -X "$method"
|
||||
-H "Accept: application/vnd.github.v3+json"
|
||||
-H "Authorization: token $GITHUB_TOKEN")
|
||||
if [[ "$method" == POST ]]; then
|
||||
args+=(-H "Content-Type: application/json" -d "$REQUEST_BODY")
|
||||
fi
|
||||
if ! HTTP_RESPONSE=$(curl "${args[@]}" "$url"); then
|
||||
echo "ERROR: GitHub release request failed at the transport layer"
|
||||
return 1
|
||||
fi
|
||||
HTTP_BODY=$(printf '%s\n' "$HTTP_RESPONSE" | sed '$d')
|
||||
HTTP_CODE=$(printf '%s\n' "$HTTP_RESPONSE" | tail -n1)
|
||||
if [[ ! "$HTTP_CODE" =~ ^[0-9]{3}$ ]]; then
|
||||
echo "ERROR: GitHub release request returned an invalid HTTP status"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
# Create the release with retry logic
|
||||
MAX_RETRIES=2
|
||||
RETRY_COUNT=0
|
||||
|
||||
same_published_tag() {
|
||||
jq -e --arg tag "$TAG_NAME" '.tag_name == $tag and .draft == false' \
|
||||
<<< "$HTTP_BODY" >/dev/null 2>&1
|
||||
}
|
||||
while [[ $RETRY_COUNT -lt $MAX_RETRIES ]]; do
|
||||
HTTP_RESPONSE=$(curl -s -w "\n%{http_code}" -X POST \
|
||||
-H "Accept: application/vnd.github.v3+json" \
|
||||
-H "Authorization: token $GITHUB_TOKEN" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "$REQUEST_BODY" \
|
||||
"$API_URL")
|
||||
|
||||
MAX_ATTEMPTS=2
|
||||
for ((attempt=1; attempt<=MAX_ATTEMPTS; attempt++)); do
|
||||
request_release POST "$API_URL"
|
||||
case "$HTTP_CODE" in
|
||||
2??)
|
||||
if ! same_published_tag; then
|
||||
echo "ERROR: GitHub release response did not confirm the requested published tag"
|
||||
exit 1
|
||||
fi
|
||||
echo "GitHub release created successfully for $TAG_NAME"
|
||||
HTTP_BODY=$(echo "$HTTP_RESPONSE" | sed '$d')
|
||||
HTTP_CODE=$(echo "$HTTP_RESPONSE" | tail -n1)
|
||||
|
||||
if [[ "$HTTP_CODE" -ge 200 ]] && [[ "$HTTP_CODE" -lt 300 ]]; then
|
||||
RELEASE_URL=$(echo "$HTTP_BODY" | jq -r '.html_url')
|
||||
echo "GitHub release created successfully: $RELEASE_URL"
|
||||
exit 0
|
||||
elif [[ "$HTTP_CODE" -ge 500 ]]; then
|
||||
echo "Server error (HTTP $HTTP_CODE), retrying..."
|
||||
RETRY_COUNT=$((RETRY_COUNT + 1))
|
||||
sleep 2
|
||||
elif [[ "$HTTP_CODE" == "422" ]]; then
|
||||
# Check if release already exists
|
||||
if echo "$HTTP_BODY" | grep -q "already_exists"; then
|
||||
echo "Release for $TAG_NAME already exists, skipping"
|
||||
exit 0
|
||||
;;
|
||||
5??)
|
||||
if [[ "$attempt" -lt "$MAX_ATTEMPTS" ]]; then
|
||||
echo "GitHub server error (HTTP $HTTP_CODE); retrying release creation"
|
||||
sleep 2
|
||||
else
|
||||
echo "ERROR: GitHub release creation failed after $MAX_ATTEMPTS attempts (HTTP $HTTP_CODE)"
|
||||
exit 1
|
||||
fi
|
||||
;;
|
||||
422)
|
||||
# A validation failure is not proof that this release already exists.
|
||||
if ! jq -e 'any(.errors[]?; .resource == "Release" and .field == "tag_name" and .code == "already_exists")' \
|
||||
<<< "$HTTP_BODY" >/dev/null 2>&1; then
|
||||
echo "ERROR: GitHub release creation rejected (HTTP 422)"
|
||||
exit 1
|
||||
fi
|
||||
ENCODED_TAG=$(jq -nr --arg tag "$TAG_NAME" '$tag | @uri')
|
||||
request_release GET "$API_URL/tags/$ENCODED_TAG"
|
||||
if [[ "$HTTP_CODE" != 200 ]] || ! same_published_tag; then
|
||||
echo "ERROR: Existing GitHub release could not be verified for the requested published tag (HTTP $HTTP_CODE)"
|
||||
exit 1
|
||||
fi
|
||||
echo "Published GitHub release for $TAG_NAME already exists; verified"
|
||||
else
|
||||
echo "ERROR: GitHub API returned HTTP $HTTP_CODE"
|
||||
echo "$HTTP_BODY"
|
||||
# Don't fail the build - artifacts are already published
|
||||
echo "WARNING: GitHub release creation failed, but artifacts are published"
|
||||
exit 0
|
||||
;;
|
||||
*)
|
||||
echo "ERROR: GitHub release creation failed (HTTP $HTTP_CODE)"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
else
|
||||
echo "ERROR: GitHub API returned HTTP $HTTP_CODE"
|
||||
echo "$HTTP_BODY"
|
||||
# Don't fail the build - artifacts are already published
|
||||
echo "WARNING: GitHub release creation failed, but artifacts are published"
|
||||
exit 0
|
||||
fi
|
||||
done
|
||||
exit 1
|
||||
|
||||
echo "WARNING: GitHub release creation failed after $MAX_RETRIES retries"
|
||||
echo "Artifacts are published, continuing..."
|
||||
exit 0
|
||||
@@ -1,100 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
# Execute the real release script with offline curl/git fixtures.
|
||||
set -euo pipefail
|
||||
root=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)
|
||||
scratch=$(mktemp -d)
|
||||
trap 'rm -rf "$scratch"' EXIT
|
||||
mkdir -p "$scratch/bin" "$scratch/work"
|
||||
cat > "$scratch/work/pom.xml" <<'EOF'
|
||||
<project>
|
||||
<groupId>example.fixture</groupId>
|
||||
<artifactId>release-test</artifactId>
|
||||
<revision>1.2.3</revision>
|
||||
</project>
|
||||
EOF
|
||||
cat > "$scratch/bin/git" <<'EOF'
|
||||
#!/usr/bin/env bash
|
||||
[[ "$*" == "tag --list" ]] || exit 92
|
||||
printf 'v1.2.3\n'
|
||||
EOF
|
||||
cat > "$scratch/bin/sleep" <<'EOF'
|
||||
#!/usr/bin/env bash
|
||||
exit 0
|
||||
EOF
|
||||
cat > "$scratch/bin/curl" <<'EOF'
|
||||
#!/usr/bin/env bash
|
||||
set -eu
|
||||
count=$(cat "$MOCK_COUNT")
|
||||
count=$((count + 1))
|
||||
printf '%s' "$count" > "$MOCK_COUNT"
|
||||
method=POST
|
||||
while (($#)); do
|
||||
if [[ "$1" == "-X" ]]; then method=$2; shift; fi
|
||||
shift
|
||||
done
|
||||
existing='{"errors":[{"resource":"Release","field":"tag_name","code":"already_exists"}]}'
|
||||
valid='{"tag_name":"v1.2.3","draft":false,"html_url":"https://github.com/example/fixture/releases/tag/v1.2.3"}'
|
||||
case "$MOCK_CASE" in
|
||||
created) printf '%s\n201' "$valid" ;;
|
||||
unauthorized) printf '{"message":"BODY_MUST_NOT_LEAK"}\n401' ;;
|
||||
forbidden) printf '{"message":"BODY_MUST_NOT_LEAK"}\n403' ;;
|
||||
invalid) printf '{"message":"BODY_MUST_NOT_LEAK","errors":[{"code":"invalid"}]}\n422' ;;
|
||||
misleading) printf '{"message":"already_exists BODY_MUST_NOT_LEAK"}\n422' ;;
|
||||
server) printf '{"message":"BODY_MUST_NOT_LEAK"}\n503' ;;
|
||||
recover)
|
||||
if [[ "$count" == 1 ]]; then printf '{}\n503'; else printf '%s\n201' "$valid"; fi ;;
|
||||
transport) exit 7 ;;
|
||||
malformed) printf 'BODY_MUST_NOT_LEAK\nnot-http' ;;
|
||||
existing|wrong-tag|draft|lookup-unauthorized)
|
||||
if [[ "$method" == POST ]]; then
|
||||
printf '%s\n422' "$existing"
|
||||
elif [[ "$MOCK_CASE" == wrong-tag ]]; then
|
||||
printf '{"tag_name":"v9.9.9","draft":false}\n200'
|
||||
elif [[ "$MOCK_CASE" == draft ]]; then
|
||||
printf '{"tag_name":"v1.2.3","draft":true}\n200'
|
||||
elif [[ "$MOCK_CASE" == lookup-unauthorized ]]; then
|
||||
printf '{"message":"BODY_MUST_NOT_LEAK"}\n401'
|
||||
else
|
||||
printf '%s\n200' "$valid"
|
||||
fi ;;
|
||||
*) exit 93 ;;
|
||||
esac
|
||||
EOF
|
||||
chmod +x "$scratch/bin/"*
|
||||
export PATH="$scratch/bin:$PATH" PROJECT_TYPE=maven
|
||||
export GITHUB_TOKEN=fixture-token-must-not-leak
|
||||
export CIRCLE_PROJECT_USERNAME=example CIRCLE_PROJECT_REPONAME=fixture
|
||||
export MOCK_COUNT="$scratch/count"
|
||||
cd "$scratch/work"
|
||||
check() {
|
||||
export MOCK_CASE=$1
|
||||
local expected=$2 calls=$3 status=0
|
||||
printf 0 > "$MOCK_COUNT"
|
||||
bash "$root/src/scripts/create_github_release.sh" > "$scratch/output" 2>&1 || status=$?
|
||||
if [[ "$expected" == pass && "$status" != 0 ]] || [[ "$expected" == fail && "$status" == 0 ]]; then
|
||||
printf 'FAIL: %s returned %s (expected %s)\n' "$MOCK_CASE" "$status" "$expected" >&2
|
||||
exit 1
|
||||
fi
|
||||
[[ "$(cat "$MOCK_COUNT")" == "$calls" ]]
|
||||
if grep -Eq 'BODY_MUST_NOT_LEAK|fixture-token-must-not-leak|artifacts are published|Artifacts are published' "$scratch/output"; then
|
||||
printf 'FAIL: unsafe or unverified output in %s\n' "$MOCK_CASE" >&2
|
||||
exit 1
|
||||
fi
|
||||
printf 'PASS: %s\n' "$MOCK_CASE"
|
||||
}
|
||||
# First assertion reproduces the hosted HTTP401 false success before the fix.
|
||||
check unauthorized fail 1
|
||||
check forbidden fail 1
|
||||
check invalid fail 1
|
||||
check misleading fail 1
|
||||
check server fail 2
|
||||
check transport fail 1
|
||||
check malformed fail 1
|
||||
check created pass 1
|
||||
check recover pass 2
|
||||
check existing pass 2
|
||||
check wrong-tag fail 2
|
||||
check draft fail 2
|
||||
check lookup-unauthorized fail 2
|
||||
export DRY_RUN=true
|
||||
check created pass 0
|
||||
@@ -0,0 +1,105 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Read one Sonatype deployment status without retrying or publishing anything."""
|
||||
import base64
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
import urllib.error
|
||||
import urllib.request
|
||||
|
||||
ENDPOINT = "https://central.sonatype.com/api/v1/publisher/status"
|
||||
STATES = {"PENDING", "VALIDATING", "VALIDATED", "PUBLISHING", "PUBLISHED", "FAILED"}
|
||||
UUID = re.compile(r"[0-9a-fA-F]{8}(?:-[0-9a-fA-F]{4}){3}-[0-9a-fA-F]{12}")
|
||||
|
||||
|
||||
class NoRedirects(urllib.request.HTTPRedirectHandler):
|
||||
def redirect_request(self, req, fp, code, msg, headers, newurl):
|
||||
return None
|
||||
|
||||
|
||||
def error_categories(errors):
|
||||
"""Emit only fixed labels, never server-supplied keys or descriptions."""
|
||||
text = json.dumps(errors).lower()
|
||||
categories = [name for name in (
|
||||
"signature", "checksum", "namespace", "javadoc", "sources", "license", "pom"
|
||||
) if name in text]
|
||||
return categories or ["validation"]
|
||||
|
||||
|
||||
def validation_details(errors, environment):
|
||||
# Only validation errors, never the full response or request/headers.
|
||||
secrets = [str(v) for k, v in environment.items()
|
||||
if v and any(part in k.upper() for part in ("TOKEN", "PASSWORD", "PASSPHRASE", "SECRET", "PRIVATE_KEY"))]
|
||||
pair = environment.get("CENTRAL_USERNAME", "") + ":" + environment.get("CENTRAL_PASSWORD", "")
|
||||
secrets.extend([pair, base64.b64encode(pair.encode()).decode()])
|
||||
details = json.dumps(errors, ensure_ascii=True)
|
||||
for secret in sorted(secrets, key=len, reverse=True):
|
||||
details = details.replace(secret, "<REDACTED>")
|
||||
details = re.sub(r"(?i)(?:bearer|basic)\s+[A-Za-z0-9+/=._-]+", "<REDACTED>", details)
|
||||
return details[:12000]
|
||||
|
||||
|
||||
def read_status(environment, open_request=None):
|
||||
deployment = environment.get("QQQ_CENTRAL_DEPLOYMENT_ID", "")
|
||||
result = {"error_categories": []}
|
||||
|
||||
def fail(category):
|
||||
result["error_categories"] = [category]
|
||||
return 1, result
|
||||
|
||||
if not UUID.fullmatch(deployment):
|
||||
return fail("invalid_deployment_id")
|
||||
deployment = deployment.lower()
|
||||
result["deploymentId"] = deployment
|
||||
username = environment.get("CENTRAL_USERNAME", "")
|
||||
password = environment.get("CENTRAL_PASSWORD", "")
|
||||
if not username or not password:
|
||||
return fail("missing_credentials")
|
||||
token = base64.b64encode(f"{username}:{password}".encode("utf-8")).decode("ascii")
|
||||
request = urllib.request.Request(
|
||||
ENDPOINT + "?id=" + deployment, data=b"", method="POST",
|
||||
headers={"Authorization": "Bearer " + token, "Accept": "application/json"},
|
||||
)
|
||||
if open_request is None:
|
||||
open_request = urllib.request.build_opener(NoRedirects()).open
|
||||
try:
|
||||
with open_request(request, timeout=30) as response:
|
||||
raw = response.read(1024 * 1024 + 1)
|
||||
if len(raw) > 1024 * 1024:
|
||||
return fail("invalid_response")
|
||||
data = json.loads(raw)
|
||||
except urllib.error.HTTPError as error:
|
||||
category = ("authentication" if error.code == 401 else
|
||||
"authorization" if error.code == 403 else
|
||||
"redirect_rejected" if 300 <= error.code < 400 else "http_error")
|
||||
error.close()
|
||||
return fail(category)
|
||||
except (urllib.error.URLError, TimeoutError, OSError):
|
||||
return fail("transport")
|
||||
except (ValueError, UnicodeError):
|
||||
return fail("invalid_response")
|
||||
if not isinstance(data, dict):
|
||||
return fail("invalid_response")
|
||||
returned_id = data.get("deploymentId")
|
||||
if not isinstance(returned_id, str) or returned_id.lower() != deployment:
|
||||
return fail("deployment_id_mismatch")
|
||||
state = data.get("deploymentState")
|
||||
if not isinstance(state, str) or state not in STATES:
|
||||
return fail("invalid_state")
|
||||
result["deploymentState"] = state
|
||||
if state == "FAILED":
|
||||
result["error_categories"] = error_categories(data.get("errors"))
|
||||
result["validation_details"] = validation_details(data.get("errors"), environment)
|
||||
return 1, result
|
||||
return (0 if state == "PUBLISHED" else 2), result
|
||||
|
||||
|
||||
def main():
|
||||
code, result = read_status(os.environ)
|
||||
print(json.dumps(result, sort_keys=True))
|
||||
return code
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
Reference in new issue
Block a user