Keep PBX at v0 and simplify Jenkins quality gate
Intrepid/Prometeu/Runtime/pipeline/pr-master There was a failure building this commit
Intrepid/Prometeu/Runtime/pipeline/pr-master There was a failure building this commit
This commit is contained in:
@@ -7,7 +7,7 @@ fail() {
|
||||
exit 1
|
||||
}
|
||||
|
||||
for command in rustup cargo rustc python3 jq rg git make pkg-config; do
|
||||
for command in rustup cargo rustc python3 jq git make pkg-config; do
|
||||
command -v "$command" >/dev/null || fail "$command"
|
||||
done
|
||||
|
||||
|
||||
@@ -150,10 +150,10 @@ if [[ ${SHOW_PATHS} -eq 1 ]]; then
|
||||
fi
|
||||
|
||||
if [[ ${SHOW_TRACKED_FILES} -eq 1 ]]; then
|
||||
echo "Tracked files present in repository:"
|
||||
echo "Repository files (including untracked, excluding ignored):"
|
||||
(
|
||||
cd "${ROOT}"
|
||||
rg --files crates
|
||||
git ls-files --cached --others --exclude-standard -- crates
|
||||
) | jq -Rr --arg domain "${DOMAIN}" --slurpfile config "${CONFIG_PATH}" '
|
||||
$config[0].domains[$domain] as $mapping
|
||||
| . as $name
|
||||
|
||||
@@ -9,9 +9,9 @@ if [[ "$(uname -s)" == Linux ]]; then
|
||||
"${admin[@]}" apt-get install -y --no-install-recommends \
|
||||
build-essential pkg-config libasound2-dev libudev-dev libxkbcommon-dev \
|
||||
libwayland-dev libx11-dev libxrandr-dev libxi-dev \
|
||||
python3 jq ripgrep git curl ca-certificates
|
||||
python3 jq git curl ca-certificates
|
||||
fi
|
||||
for command in rustup cargo python3 jq rg git make pkg-config; do
|
||||
for command in rustup cargo python3 jq git make pkg-config; do
|
||||
command -v "$command" >/dev/null || { echo "Missing quality-gate prerequisite: $command" >&2; exit 1; }
|
||||
done
|
||||
rustup component add rustfmt clippy llvm-tools-preview
|
||||
|
||||
@@ -1,101 +0,0 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Run Makefile-owned gate steps serially and retain evidence on failure."""
|
||||
import hashlib
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
import platform
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
from datetime import datetime, timezone
|
||||
|
||||
|
||||
def capture(*command):
|
||||
try:
|
||||
result = subprocess.run(command, text=True, stdout=subprocess.PIPE,
|
||||
stderr=subprocess.STDOUT, check=False)
|
||||
return {"exit_code": result.returncode, "output": result.stdout.strip()}
|
||||
except OSError as error:
|
||||
return {"exit_code": 127, "output": str(error)}
|
||||
|
||||
|
||||
def sha(path):
|
||||
return hashlib.sha256(path.read_bytes()).hexdigest()
|
||||
|
||||
|
||||
def main():
|
||||
root = Path(__file__).resolve().parent.parent
|
||||
os.chdir(root)
|
||||
output = root / "target/quality-gate"
|
||||
# These two directories contain generated reports only. Never archive a
|
||||
# previous run's coverage as evidence for an early lint/test failure.
|
||||
for directory in (output, root / "target/llvm-cov"):
|
||||
if directory.exists():
|
||||
shutil.rmtree(directory)
|
||||
output.mkdir(parents=True)
|
||||
inputs = [Path("Makefile"), Path("Cargo.lock"), Path(".github/workflows/ci.yml"),
|
||||
Path("files/config/Jenkinsfile"), Path("files/config/runtime-edge-coverage-domains.json")]
|
||||
inputs.extend(sorted(Path("scripts").rglob("*.py")))
|
||||
inputs.extend(sorted(Path("scripts").glob("*.sh")))
|
||||
fingerprints = {str(path): sha(path) for path in inputs if path.is_file()}
|
||||
sources = "".join(f"{path}\0{sha(path)}\n" for path in sorted(Path("crates").rglob("*.rs")))
|
||||
evidence = {
|
||||
"started_utc": datetime.now(timezone.utc).isoformat(),
|
||||
"host": platform.platform(), "revision": capture("git", "rev-parse", "HEAD"),
|
||||
"working_tree": capture("git", "status", "--porcelain"),
|
||||
"rustc": capture("rustc", "-vV"), "cargo_llvm_cov": capture("cargo", "llvm-cov", "--version"),
|
||||
"config_sha256": fingerprints,
|
||||
"rust_source_sha256": hashlib.sha256(sources.encode()).hexdigest(),
|
||||
"source_hash_algorithm": "SHA-256 of sorted path + NUL + file SHA-256 hex + newline records",
|
||||
"steps": [], "status": "running",
|
||||
}
|
||||
metadata = output / "metadata.json"
|
||||
|
||||
def persist():
|
||||
metadata.write_text(json.dumps(evidence, indent=2) + "\n")
|
||||
|
||||
persist()
|
||||
exit_code = 0
|
||||
try:
|
||||
if not sys.argv[1:]:
|
||||
raise ValueError("Makefile must supply the required gate steps")
|
||||
for target in sys.argv[1:]:
|
||||
if not target.replace("-", "").isalnum():
|
||||
raise ValueError(f"invalid make target: {target!r}")
|
||||
command = ["make", "--no-print-directory", "-j1", target]
|
||||
log = output / f"{target}.log"
|
||||
print(f"Quality gate: {target}", flush=True)
|
||||
with log.open("w") as stream:
|
||||
process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
|
||||
text=True, errors="replace")
|
||||
for line in process.stdout:
|
||||
stream.write(line)
|
||||
print(line, end="", flush=True)
|
||||
result = process.wait()
|
||||
exit_code = result if result >= 0 else 128 - result
|
||||
evidence["steps"].append({"target": target, "command": command,
|
||||
"exit_code": exit_code, "log_sha256": sha(log)})
|
||||
persist()
|
||||
if exit_code:
|
||||
break
|
||||
except KeyboardInterrupt:
|
||||
evidence["error"] = "Interrupted"
|
||||
exit_code = 130
|
||||
except Exception as error:
|
||||
evidence["error"] = str(error)
|
||||
exit_code = 1
|
||||
finally:
|
||||
evidence["status"] = "passed" if exit_code == 0 else "failed"
|
||||
evidence["exit_code"] = exit_code
|
||||
evidence["finished_utc"] = datetime.now(timezone.utc).isoformat()
|
||||
evidence["reports_sha256"] = {
|
||||
str(path.relative_to(root)): sha(path)
|
||||
for path in sorted((root / "target/llvm-cov").rglob("*")) if path.is_file()
|
||||
}
|
||||
persist()
|
||||
return exit_code
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
@@ -1,55 +0,0 @@
|
||||
"""Exercise real make failures without running Cargo or modifying the repository."""
|
||||
import json
|
||||
from pathlib import Path
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
|
||||
class QualityGateTests(unittest.TestCase):
|
||||
def run_gate(self, makefile, targets):
|
||||
temporary = tempfile.TemporaryDirectory()
|
||||
self.addCleanup(temporary.cleanup)
|
||||
root = Path(temporary.name)
|
||||
(root / "scripts").mkdir()
|
||||
shutil.copy(Path(__file__).resolve().parents[1] / "run-quality-gate.py", root / "scripts")
|
||||
(root / "Makefile").write_text(makefile)
|
||||
(root / "target/llvm-cov").mkdir(parents=True)
|
||||
(root / "target/llvm-cov/stale.json").write_text("old evidence")
|
||||
result = subprocess.run([sys.executable, str(root / "scripts/run-quality-gate.py"), *targets],
|
||||
capture_output=True, text=True)
|
||||
evidence = json.loads((root / "target/quality-gate/metadata.json").read_text())
|
||||
self.assertFalse((root / "target/llvm-cov/stale.json").exists())
|
||||
return root, result, evidence
|
||||
|
||||
def test_failure_preserves_logs_identity_exit_and_stops_later_steps(self):
|
||||
root, result, evidence = self.run_gate(
|
||||
'fail:\n\t@echo diagnostic\n\t@exit 7\nlater:\n\t@touch should-not-exist\n',
|
||||
['fail', 'later'])
|
||||
self.assertNotEqual(result.returncode, 0)
|
||||
self.assertEqual(evidence['exit_code'], result.returncode)
|
||||
self.assertEqual(evidence['status'], 'failed')
|
||||
self.assertEqual([step['target'] for step in evidence['steps']], ['fail'])
|
||||
self.assertIn('diagnostic', (root / 'target/quality-gate/fail.log').read_text())
|
||||
self.assertIn('Makefile', evidence['config_sha256'])
|
||||
self.assertIn('revision', evidence)
|
||||
self.assertEqual(evidence['reports_sha256'], {})
|
||||
self.assertFalse((root / 'should-not-exist').exists())
|
||||
|
||||
def test_success_fingerprints_only_current_reports(self):
|
||||
_, result, evidence = self.run_gate(
|
||||
'report:\n\t@mkdir -p target/llvm-cov\n\t@echo fresh > target/llvm-cov/report.json\n',
|
||||
['report'])
|
||||
self.assertEqual(result.returncode, 0, result.stdout + result.stderr)
|
||||
self.assertEqual(evidence['status'], 'passed')
|
||||
self.assertEqual(list(evidence['reports_sha256']), ['target/llvm-cov/report.json'])
|
||||
|
||||
def test_partial_report_is_retained_when_a_later_gate_fails(self):
|
||||
_, result, evidence = self.run_gate(
|
||||
'report:\n\t@mkdir -p target/llvm-cov\n\t@echo fresh > target/llvm-cov/report.json\nfail:\n\t@exit 1\n',
|
||||
['report', 'fail'])
|
||||
self.assertNotEqual(result.returncode, 0)
|
||||
self.assertEqual(evidence['status'], 'failed')
|
||||
self.assertIn('target/llvm-cov/report.json', evidence['reports_sha256'])
|
||||
Reference in New Issue
Block a user