diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 29934ff37..231b6472d 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -1,38 +1,136 @@ on: push: branches: - - master + - master + tags: + - 'v*' pull_request: + workflow_dispatch: name: ci -permissions: - contents: read +permissions: {} jobs: units: + if: github.event_name != 'push' || !startsWith(github.ref, 'refs/tags/') runs-on: ubuntu-latest + permissions: + contents: read strategy: matrix: java: [8, 11] steps: - - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0 + - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 with: persist-credentials: false - - uses: actions/setup-java@0f62d2ad8407a414cddd4790bed06fd9ebda0f56 # v1.4.5 + - uses: actions/setup-java@0f62d2ad8407a414cddd4790bed06fd9ebda0f56 with: java-version: ${{matrix.java}} - name: Get current date id: date run: echo "date=$(date +'%Y-%m-%d' --utc)" >> "$GITHUB_OUTPUT" - - uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0 + - uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 id: mvn-cache with: path: ~/.m2/repository key: ${{ runner.os }}-maven-unified-${{ steps.date.outputs.date }} - run: java -version - # The http connection settings avoid Maven's HTTP connection reset in GitHub Actions - # https://github.com/actions/virtual-environments/issues/1499#issuecomment-689467080 - run: | ./mvnw -B -e -ntp install \ -Dhttp.keepAlive=false -Dmaven.wagon.http.pool=false \ -Dmaven.wagon.httpconnectionManager.ttlSeconds=120 - run: cd gradle-plugin && ./gradlew build + release-exit-gate: + if: startsWith(github.ref, 'refs/tags/') + runs-on: ubuntu-latest + permissions: + contents: read + id-token: write + steps: + - name: Checkout repository + uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 + with: + persist-credentials: false + - name: Set up JDK 11 + uses: actions/setup-java@c5195efecf7bdfc987ee8bae7a71cb8b11521c00 + with: + java-version: '11' + distribution: 'temurin' + - name: Authenticate to Google Cloud + uses: google-github-actions/auth@7c6bc770dae815cd3e89ee6cdf493a5fab2cc093 # v3.0.0 + with: + workload_identity_provider: 'projects/305452601764/locations/global/workloadIdentityPools/builders/providers/github' + - name: Set up Cloud SDK + uses: google-github-actions/setup-gcloud@aa5489c8933f4cc7a4f7d45035b3b1440c9c10db # v3.0.1 + - name: Clean up previous staging attempt for this version (if any) + run: | + set -euo pipefail + VERSION=$(python3 -c 'import xml.etree.ElementTree as ET; r=ET.parse("boms/pom.xml").getroot(); ns={"m": r.tag.split("}")[0][1:]} if "}" in r.tag else {}; print((r.findtext("m:version", namespaces=ns) if ns else r.findtext("version")).strip())') + while IFS= read -r pkg; do + pkg_name="${pkg##*/}" + [ -n "${pkg_name}" ] || continue + if gcloud artifacts versions describe "${VERSION}" \ + --package="${pkg_name}" \ + --project="oss-exit-gate-prod" \ + --location="us" \ + --repository="cloud-opensource-java--mavencentral" >/dev/null 2>&1; then + gcloud artifacts versions delete "${VERSION}" \ + --package="${pkg_name}" \ + --project="oss-exit-gate-prod" \ + --location="us" \ + --repository="cloud-opensource-java--mavencentral" \ + --quiet + fi + done < <(gcloud artifacts packages list \ + --project="oss-exit-gate-prod" \ + --location="us" \ + --repository="cloud-opensource-java--mavencentral" \ + --format="value(name)" 2>/dev/null || true) + + - name: Stage BOM to OSS Exit Gate Maven Artifact Registry + env: + RUN_ID: ${{ github.run_id }} + RUN_ATTEMPT: ${{ github.run_attempt }} + run: | + set -euo pipefail + ./mvnw -B -f boms/pom.xml deploy -DskipTests \ + -DaltDeploymentRepository="oss-exit-gate::default::artifactregistry://us-maven.pkg.dev/oss-exit-gate-prod/cloud-opensource-java--mavencentral" + VERSION=$(python3 -c 'import xml.etree.ElementTree as ET; r=ET.parse("boms/pom.xml").getroot(); ns={"m": r.tag.split("}")[0][1:]} if "}" in r.tag else {}; print((r.findtext("m:version", namespaces=ns) if ns else r.findtext("version")).strip())') + python3 - "${VERSION}" <<'PY' + import collections, json, os, subprocess, sys + version = os.environ.get("VERSION") or (sys.argv[1] if len(sys.argv) > 1 else "") + if not version: + raise SystemExit("ERROR: missing release version for manifest generation") + repo = "cloud-opensource-java--mavencentral" + pkgs_out = subprocess.check_output([ + "gcloud", "artifacts", "packages", "list", + "--project=oss-exit-gate-prod", "--location=us", + f"--repository={repo}", "--format=value(name)", + ], text=True).splitlines() + groups = collections.defaultdict(list) + for pkg_path in sorted(pkgs_out): + pkg_id = pkg_path.strip().split("/")[-1] + if ":" not in pkg_id: + continue + rc = subprocess.run([ + "gcloud", "artifacts", "versions", "describe", version, + f"--package={pkg_id}", "--project=oss-exit-gate-prod", + "--location=us", f"--repository={repo}", + ], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL).returncode + if rc == 0: + ns, name = pkg_id.split(":", 1) + groups[ns].append({"name": name, "version": version}) + if not groups: + raise SystemExit(f"ERROR: No staged Maven packages found in {repo} for version {version}") + manifest = { + "publish_all": False, + "publishing_groups": [ + {"namespace": ns, "packages": pkgs} + for ns, pkgs in sorted(groups.items()) + ], + } + with open("manifest.json", "w", encoding="utf-8") as fh: + json.dump(manifest, fh, indent=2) + fh.write("\n") + PY + gcloud storage cp manifest.json \ + "gs://oss-exit-gate-prod-projects-bucket/cloud-opensource-java/mavencentral/manifests/manifest-${RUN_ID}-${RUN_ATTEMPT}.json"