Compare commits

...
7 Commits
Author SHA1 Message Date
james.maes 5bc3167286 Merge pull request #29 from QRun-IO/develop
fix: release resolved Maven publication POMs
2026-10-20 18:39:47 -05:00
james.maes a2cdd818f6 Merge pull request #28 from QRun-IO/fix/resolved-publication-poms
fix: resolve Maven publication POM coordinates centrally
2026-10-20 18:37:34 -05:00
james.maesandCodex 42e0be02c9 fix: enforce Maven publication gate in orb audit
Co-Authored-By: Codex <noreply@openai.com>
2026-10-20 18:35:53 -05:00
james.maesandCodex b71c9ca4d7 fix: resolve Maven publication POM coordinates centrally
Co-Authored-By: Codex <noreply@openai.com>
2026-10-20 07:50:31 -05:00
james.maes 1a3368e119 Merge pull request #27 from QRun-IO/develop
release: fail closed on GitHub publication errors
2026-10-20 07:39:37 -05:00
james.maes 7dd5f38d35 Merge pull request #26 from QRun-IO/fix/release-failure-reporting
fix: fail CI when GitHub release creation fails
2026-10-20 07:37:25 -05:00
james.maesandCodex 02c14d7237 fix: fail CI when GitHub release creation fails
Co-Authored-By: Codex <noreply@openai.com>
2026-10-20 07:34:43 -05:00
9 changed files with 308 additions and 51 deletions

No files matched your search

+14 -2
View File
@@ -22,6 +22,15 @@ main-filters: &main-filters
only: [main]
jobs:
maven-publication-contract:
resource_class: small
docker:
- image: cimg/openjdk:21.0
steps:
- checkout
- run:
name: Verify resolved multi-module publication POMs
command: python3 tests/test_maven_publication_poms.py
pipeline-contract-test:
resource_class: small
docker:
@@ -61,6 +70,7 @@ 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
@@ -147,13 +157,15 @@ workflows:
filters: *filters
- pipeline-contract-test:
filters: *filters
- maven-publication-contract:
filters: *filters
# Auto-publish dev snapshot on develop
- publish-dev-snapshot:
context: orb-publishing
filters: *develop-filters
requires: [command-test, pipeline-contract-test]
requires: [command-test, pipeline-contract-test, maven-publication-contract]
# Auto-publish production release on main
- publish-production:
context: orb-publishing
filters: *main-filters
requires: [command-test, pipeline-contract-test]
requires: [command-test, pipeline-contract-test, maven-publication-contract]
+7
View File
@@ -79,6 +79,7 @@ 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
@@ -207,3 +208,9 @@ publish-release: check-clean check-branch lint clean dev test-all
echo "Pushing tag to remote..."; \
git push origin "$$version"; \
echo "✅ Production release $$version published successfully!"
.PHONY: test-publication-poms
# Explicit integration gate: requires Java/Maven and public plugin downloads into
# an isolated temporary repository. Never publishes or uses signing credentials.
test-publication-poms:
python3 tests/test_maven_publication_poms.py
+68 -45
View File
@@ -208,50 +208,73 @@ REQUEST_BODY=$(jq -n \
generate_release_notes: true
}')
# Create the release with retry logic
MAX_RETRIES=2
RETRY_COUNT=0
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")
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
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
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
# 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
done
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
}
echo "WARNING: GitHub release creation failed after $MAX_RETRIES retries"
echo "Artifacts are published, continuing..."
exit 0
same_published_tag() {
jq -e --arg tag "$TAG_NAME" '.tag_name == $tag and .draft == false' \
<<< "$HTTP_BODY" >/dev/null 2>&1
}
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"
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"
exit 0
;;
*)
echo "ERROR: GitHub release creation failed (HTTP $HTTP_CODE)"
exit 1
;;
esac
done
exit 1
+6 -1
View File
@@ -25,4 +25,9 @@ set -e
##############################################
## Deploy signed artifacts to Maven Central ##
##############################################
mvn -s /tmp/circleci/mvn-settings.xml -P release -B -DskipTests -Dgpg.keyname="$GPG_KEYNAME" -Dgpg.passphrase="$GPG_PASSPHRASE" deploy
# Resolve CI-friendly coordinates without stripping parent/BOM configuration.
# Flatten must share this Maven process so deploy uses the resolved project POMs.
mvn -s /tmp/circleci/mvn-settings.xml -P release -B -DskipTests \
-Dgpg.keyname="$GPG_KEYNAME" -Dgpg.passphrase="$GPG_PASSPHRASE" \
-Dflatten.mode=resolveCiFriendliesOnly -DupdatePomFile=true \
org.codehaus.mojo:flatten-maven-plugin:1.7.3:flatten deploy
+1 -1
View File
@@ -177,7 +177,7 @@ class AuditTests(unittest.TestCase):
self.assertEqual('unknown', report['status'])
self.assertNotIn('missing_manifest', [f['code'] for f in report['findings']])
for path, old, new in [('.circleci/config.yml', 'orb-tools/pack', 'disabled-pack'),
('.circleci/test-deploy.yml', 'requires: [command-test, pipeline-contract-test]', 'requires: []'),
('.circleci/test-deploy.yml', 'requires: [command-test, pipeline-contract-test, maven-publication-contract]', 'requires: [command-test, pipeline-contract-test]'),
('.circleci/test-deploy.yml', 'circleci orb validate ', 'echo skipped ')]:
self.assertIn(old, files[path])
changed = dict(files, **{path: files[path].replace(old, new)})
+100
View File
@@ -0,0 +1,100 @@
#!/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
+107
View File
@@ -0,0 +1,107 @@
#!/usr/bin/env python3
"""Real Maven publication contract. Requires Java/Maven; no remote deploy or secrets.
Run explicitly with make test-publication-poms. Public plugins are downloaded to
an isolated temporary local repository; nothing is installed to the user's m2.
"""
import hashlib
from pathlib import Path
import shutil
import subprocess
import tempfile
import xml.etree.ElementTree as ET
ROOT = Path(__file__).resolve().parents[1]
GOAL = 'org.codehaus.mojo:flatten-maven-plugin:1.7.3:flatten'
FLAGS = ['-Dflatten.mode=resolveCiFriendliesOnly', '-DupdatePomFile=true']
NS = {'m': 'http://maven.apache.org/POM/4.0.0'}
def pom(body):
return '<project xmlns="http://maven.apache.org/POM/4.0.0"><modelVersion>4.0.0</modelVersion>' + body + '</project>'
def run_case(base, repository, lifecycle):
project = base / ('bound' if lifecycle else 'plain')
project.mkdir()
group = 'example.bound' if lifecycle else 'example.plain'
flatten = ("<plugin><groupId>org.codehaus.mojo</groupId><artifactId>flatten-maven-plugin</artifactId>"
"<version>1.7.3</version><configuration><updatePomFile>true</updatePomFile>"
"<flattenMode>resolveCiFriendliesOnly</flattenMode></configuration><executions>"
"<execution><id>flatten</id><phase>process-resources</phase><goals><goal>flatten</goal>"
"</goals></execution></executions></plugin>") if lifecycle else ''
(project / 'pom.xml').write_text(pom(f"""
<groupId>{group}</groupId><artifactId>parent</artifactId><version>${{revision}}</version><packaging>pom</packaging>
<name>Publication fixture</name><description>Inherited release metadata</description><url>https://example.invalid/fixture</url>
<licenses><license><name>Fixture license</name><url>https://example.invalid/license</url></license></licenses>
<properties><revision>1.2.3</revision><maven.compiler.release>17</maven.compiler.release></properties>
<modules><module>library</module><module>application</module></modules>
<dependencyManagement><dependencies><dependency><groupId>{group}</groupId><artifactId>library</artifactId>
<version>${{revision}}</version></dependency></dependencies></dependencyManagement>
<build><pluginManagement><plugins><plugin><groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId><version>3.13.0</version><configuration><release>17</release></configuration>
</plugin></plugins></pluginManagement><plugins>{flatten}</plugins></build>
"""), encoding='utf-8')
for artifact in ('library', 'application'):
child = project / artifact
child.mkdir()
dependencies = (f'<dependencies><dependency><groupId>{group}</groupId><artifactId>library</artifactId></dependency></dependencies>'
if artifact == 'application' else '')
(child / 'pom.xml').write_text(pom(f'<parent><groupId>{group}</groupId><artifactId>parent</artifactId>'
'<version>${revision}</version></parent>' + f'<artifactId>{artifact}</artifactId>' + dependencies), encoding='utf-8')
sources = {path: hashlib.sha256(path.read_bytes()).hexdigest() for path in project.rglob('pom.xml')}
settings = base / 'settings.xml'
settings.write_text('<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"/>', encoding='utf-8')
maven = shutil.which('mvn') or shutil.which('mvn.cmd')
if not maven:
raise RuntimeError('Maven is required for this explicit integration gate')
command = [maven, '-B', '-ntp', '-s', str(settings), '-gs', str(settings), '-Dmaven.repo.local=' + str(repository)]
def execute(directory, goals):
subprocess.run(command + goals, cwd=directory, check=True, timeout=600)
execute(project, FLAGS + [GOAL, 'install'])
for path, digest in sources.items():
assert hashlib.sha256(path.read_bytes()).hexdigest() == digest, 'Source POM was rewritten'
installed = repository / group.replace('.', '/')
for artifact in ('parent', 'library', 'application'):
tree = ET.parse(installed / artifact / '1.2.3' / (artifact + '-1.2.3.pom'))
for node in tree.findall('m:version', NS) + tree.findall('m:parent/m:version', NS):
assert node.text == '1.2.3', 'Unresolved deployed coordinate: ' + artifact
parent = ET.parse(installed / 'parent/1.2.3/parent-1.2.3.pom')
assert parent.findtext('m:licenses/m:license/m:name', namespaces=NS) == 'Fixture license'
assert parent.find('m:dependencyManagement', NS) is not None
assert parent.find('m:build/m:pluginManagement', NS) is not None, 'Parent build contract was stripped'
# Remove reactor availability: cold consumer can use only installed artifacts.
hidden = project.with_name(project.name + '-unavailable')
project.rename(hidden)
consumer = base / ('consumer-bound' if lifecycle else 'consumer-plain')
consumer.mkdir()
(consumer / 'pom.xml').write_text(pom(f'<parent><groupId>{group}</groupId><artifactId>parent</artifactId>'
'<version>1.2.3</version><relativePath/></parent><artifactId>cold-consumer</artifactId>'
f'<dependencies><dependency><groupId>{group}</groupId><artifactId>application</artifactId>'
'<version>1.2.3</version></dependency></dependencies>'), encoding='utf-8')
execute(consumer, ['validate', 'org.apache.maven.plugins:maven-help-plugin:3.5.1:effective-pom', '-Doutput=effective.xml',
'org.apache.maven.plugins:maven-dependency-plugin:3.7.1:build-classpath', '-Dmdep.outputFile=classpath.txt'])
effective = ET.parse(consumer / 'effective.xml')
assert effective.findtext('m:licenses/m:license/m:name', namespaces=NS) == 'Fixture license'
managed = effective.find('m:dependencyManagement/m:dependencies/m:dependency', NS)
assert managed.findtext('m:version', namespaces=NS) == '1.2.3'
plugins = effective.findall('m:build/m:pluginManagement/m:plugins/m:plugin', NS)
compiler = next(p for p in plugins if p.findtext('m:artifactId', namespaces=NS) == 'maven-compiler-plugin')
assert compiler.findtext('m:configuration/m:release', namespaces=NS) == '17'
classpath = (consumer / 'classpath.txt').read_text()
assert 'application-1.2.3.jar' in classpath and 'library-1.2.3.jar' in classpath
print('PASS real resolved publication + cold consumer: ' + ('lifecycle-bound' if lifecycle else 'no-existing-flatten'))
def main():
deployment = (ROOT / 'src/scripts/mvn_jar_deploy.sh').read_text()
for flag in FLAGS:
assert flag in deployment, 'Deployment missing tested flatten configuration'
assert GOAL + ' deploy' in deployment, 'Flatten and deploy must share a Maven process'
with tempfile.TemporaryDirectory(prefix='qqq-publication-') as directory:
base = Path(directory)
for lifecycle in (False, True):
run_case(base, base / 'repository', lifecycle)
if __name__ == '__main__': main()
+3
View File
@@ -49,6 +49,9 @@ release
-DskipTests
-Dgpg.keyname=test-key
-Dgpg.passphrase=test-passphrase
-Dflatten.mode=resolveCiFriendliesOnly
-DupdatePomFile=true
org.codehaus.mojo:flatten-maven-plugin:1.7.3:flatten
deploy
EOF
diff -u "$test_dir/expected-args" "$test_dir/mvn-args"
+2 -2
View File
@@ -138,7 +138,7 @@ def owner_gate_errors(snapshot):
if not gates.issubset(set(lint.get('orb-tools/continue', {}).get('requires', []))):
errors.append('continuation must depend on every lint/pack/review/shellcheck gate')
tests = invocations(deploy, 'test-deploy')
required = {'command-test', 'pipeline-contract-test'}
required = {'command-test', 'pipeline-contract-test', 'maven-publication-contract'}
for test in required:
definition = deploy.get('jobs', {}).get(test, {})
if test not in tests or not definition.get('steps') or not any(isinstance(step, dict) and 'run' in step for step in definition['steps']):
@@ -146,7 +146,7 @@ def owner_gate_errors(snapshot):
for name, branch in [('publish-dev-snapshot', 'develop'), ('publish-production', 'main')]:
invocation = tests.get(name, {})
if not required.issubset(set(invocation.get('requires', []))):
errors.append(name + ' must require both test gates')
errors.append(name + ' must require all test gates')
if invocation.get('filters', {}).get('branches', {}).get('only') != [branch]:
errors.append(name + ' branch filter')
commands = []