Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
140 changes: 140 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,100 @@ on:
branches: [main]

permissions:
actions: read
contents: read

concurrency:
group: ci-${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
preflight:
name: Preflight
runs-on: ubuntu-latest
timeout-minutes: 5
outputs:
expensive: ${{ steps.changes.outputs.expensive }}
release: ${{ steps.changes.outputs.release }}
steps:
- uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6
with:
fetch-depth: 0
persist-credentials: false
- uses: gradle/actions/wrapper-validation@9c971963bec38e04b3d30dcc455b5382be2fdbfb # v6.3.0
- name: Classify changes
id: changes
shell: bash
env:
BASE_SHA: ${{ github.event.pull_request.base.sha }}
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
PREVIOUS_SHA: ${{ github.event.before }}
run: |
set -euo pipefail
python3 - <<'PY'
import os
import subprocess

event = os.environ["GITHUB_EVENT_NAME"]
revision = None
if event == "pull_request":
revision = f"{os.environ['BASE_SHA']}...{os.environ['HEAD_SHA']}"
elif event == "push" and os.environ["PREVIOUS_SHA"] and os.environ["PREVIOUS_SHA"] != "0" * 40:
revision = f"{os.environ['PREVIOUS_SHA']}..{os.environ['GITHUB_SHA']}"

paths = None
if revision:
changed = subprocess.check_output([
"git", "diff", "--no-renames", "--name-only", "-z", revision
])
paths = [p for p in changed.decode("utf-8", "surrogateescape").split("\0") if p]
subprocess.run(["git", "diff", "--check", revision], check=True)

def trivial(path):
return (
path == "README.md"
or path.startswith("docs/") and path.endswith((".md", ".png", ".jpg", ".jpeg", ".svg", ".webp"))
)

def release_related(path):
return (
path in ("build.gradle.kts", "bounded-origin-cli/build.gradle.kts")
or path.startswith("release-tests/")
or path.startswith("scripts/verify-release-")
or path.startswith(".github/workflows/")
or path in ("scripts/central-portal.sh", "scripts/verify-release-workflow-policy.sh")
)

expensive = not (paths is not None and bool(paths) and all(map(trivial, paths)))
release = expensive and (paths is None or any(map(release_related, paths)))
with open(os.environ["GITHUB_OUTPUT"], "a", encoding="utf-8") as output:
output.write(f"expensive={str(expensive).lower()}\n")
output.write(f"release={str(release).lower()}\n")
PY
- name: Verify required CI approver
shell: bash
env:
GH_TOKEN: ${{ github.token }}
run: |
set -euo pipefail
gh api "repos/${GITHUB_REPOSITORY}/environments/ci-approved" --jq \
'if .can_admins_bypass == false then [.protection_rules[] | select(.type == "required_reviewers" and .prevent_self_review == false and (.reviewers | length) == 1 and .reviewers[0].type == "User" and .reviewers[0].reviewer.id == 22101794)] | length else 0 end' \
| grep -qx '1'

authorize:
name: Approve expensive CI
needs: preflight
if: needs.preflight.outputs.expensive == 'true'
runs-on: ubuntu-latest
environment:
name: ci-approved
deployment: false
steps:
- run: echo "CI approved"

check:
needs: authorize
if: needs.authorize.result == 'success'
strategy:
fail-fast: false
matrix:
Expand Down Expand Up @@ -84,6 +170,8 @@ jobs:
if: runner.os == 'Windows'

reproducibility:
needs: authorize
if: needs.authorize.result == 'success'
runs-on: ubuntu-latest
steps:
- name: Checkout
Expand All @@ -108,6 +196,7 @@ jobs:
docker-smoke:
runs-on: ubuntu-latest
needs: check
if: needs.check.result == 'success'
steps:
- name: Checkout
uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6
Expand All @@ -127,3 +216,54 @@ jobs:

- name: Docker smoke
run: bash ./scripts/docker-smoke.sh

release-verification:
name: Release verification
needs: [preflight, authorize]
if: needs.authorize.result == 'success' && needs.preflight.outputs.release == 'true'
uses: ./.github/workflows/release-verification.yml
with:
approved: true
permissions:
actions: read
contents: read

required:
name: Required checks
if: always()
needs: [preflight, authorize, check, reproducibility, docker-smoke, release-verification]
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- name: Verify required jobs
shell: bash
env:
NEEDS_JSON: ${{ toJSON(needs) }}
run: |
python3 - <<'PY'
import json
import os
import sys

needs = json.loads(os.environ["NEEDS_JSON"])
results = {name: job["result"] for name, job in needs.items()}
if results["preflight"] != "success":
sys.exit("Preflight failed")

expensive = needs["preflight"]["outputs"].get("expensive")
release = needs["preflight"]["outputs"].get("release")
if expensive not in ("true", "false") or release not in ("true", "false"):
sys.exit("Invalid change classification")
if expensive == "false" and release != "false":
sys.exit("Invalid release classification")

expected = "success" if expensive == "true" else "skipped"
for name in ("authorize", "check", "reproducibility", "docker-smoke"):
if results[name] != expected:
sys.exit(f"{name}: expected {expected}, got {results[name]}")

release_expected = "success" if release == "true" else "skipped"
if results["release-verification"] != release_expected:
sys.exit(f"release-verification: expected {release_expected}, got {results['release-verification']}")
print("All applicable checks passed")
PY
55 changes: 43 additions & 12 deletions .github/workflows/release-verification.yml
Original file line number Diff line number Diff line change
@@ -1,30 +1,53 @@
name: Release Verification

on:
workflow_call:
inputs:
approved:
required: true
type: boolean
push:
branches: [release/0.1.0]
pull_request:
branches: [main]
paths:
- build.gradle.kts
- bounded-origin-cli/build.gradle.kts
- release-tests/**
- scripts/verify-release-*.sh
- .github/workflows/release-verification.yml
- .github/workflows/release.yml
- .github/workflows/central-preflight.yml
- scripts/central-portal.sh
- scripts/verify-release-workflow-policy.sh

permissions:
actions: read
contents: read

concurrency:
group: release-verification-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
preflight:
name: Release verification preflight
if: github.event_name == 'push' && !inputs.approved
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- name: Verify required CI approver
shell: bash
env:
GH_TOKEN: ${{ github.token }}
run: |
set -euo pipefail
gh api "repos/${GITHUB_REPOSITORY}/environments/ci-approved" --jq \
'if .can_admins_bypass == false then [.protection_rules[] | select(.type == "required_reviewers" and .prevent_self_review == false and (.reviewers | length) == 1 and .reviewers[0].type == "User" and .reviewers[0].reviewer.id == 22101794)] | length else 0 end' \
| grep -qx '1'

authorize:
name: Approve release verification
if: github.event_name == 'push' && !inputs.approved
needs: preflight
runs-on: ubuntu-latest
environment:
name: ci-approved
deployment: false
steps:
- run: echo "Release verification approved"

central-bundle:
needs: authorize
if: always() && (inputs.approved == true || needs.authorize.result == 'success')
runs-on: ubuntu-latest
steps:
- name: Checkout
Expand Down Expand Up @@ -93,6 +116,8 @@ jobs:
run: bash scripts/verify-release-negative.sh

cli-release:
needs: authorize
if: always() && (inputs.approved == true || needs.authorize.result == 'success')
runs-on: ubuntu-latest
steps:
- name: Checkout
Expand All @@ -115,6 +140,8 @@ jobs:
run: ./gradlew :bounded-origin-cli:cliReleaseArtifacts --stacktrace

external-consumer:
needs: authorize
if: always() && (inputs.approved == true || needs.authorize.result == 'success')
runs-on: ubuntu-latest
steps:
- name: Checkout
Expand All @@ -137,6 +164,8 @@ jobs:
run: ./gradlew verifyExternalMavenConsumer --stacktrace

release-reproducibility:
needs: authorize
if: always() && (inputs.approved == true || needs.authorize.result == 'success')
runs-on: ubuntu-latest
steps:
- name: Checkout
Expand All @@ -160,6 +189,8 @@ jobs:
run: bash scripts/verify-release-reproducible.sh

release-policy:
needs: authorize
if: always() && (inputs.approved == true || needs.authorize.result == 'success')
runs-on: ubuntu-latest
steps:
- name: Checkout
Expand Down
40 changes: 30 additions & 10 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,46 @@ name: Release
on:
push:
tags: ['v*']
pull_request:
branches: [main]
paths:
- .github/workflows/release.yml
- .github/workflows/central-preflight.yml
- build.gradle.kts
- bounded-origin-cli/build.gradle.kts
- release-tests/**
- scripts/central-portal.sh
- scripts/verify-release-workflow-policy.sh

permissions:
actions: read
contents: read

concurrency:
group: release-${{ github.ref }}
cancel-in-progress: false

jobs:
preflight:
name: Release preflight
if: github.event_name == 'push'
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- name: Verify required CI approver
shell: bash
env:
GH_TOKEN: ${{ github.token }}
run: |
set -euo pipefail
gh api "repos/${GITHUB_REPOSITORY}/environments/ci-approved" --jq \
'if .can_admins_bypass == false then [.protection_rules[] | select(.type == "required_reviewers" and .prevent_self_review == false and (.reviewers | length) == 1 and .reviewers[0].type == "User" and .reviewers[0].reviewer.id == 22101794)] | length else 0 end' \
| grep -qx '1'

authorize:
name: Approve release verification
if: github.event_name == 'push'
needs: preflight
runs-on: ubuntu-latest
environment:
name: ci-approved
deployment: false
steps:
- run: echo "Release CI approved"

validate:
needs: authorize
if: github.event_name == 'push' && needs.authorize.result == 'success'
runs-on: ubuntu-latest
steps:
- name: Checkout
Expand Down
Loading