Skip to content
Merged
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
4 changes: 4 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ updates:
development-tooling:
dependency-type: development
patterns: ["*"]
runtime-maintenance:
applies-to: version-updates
dependency-type: production
update-types: [minor, patch]
labels: [dependencies, python]
commit-message:
prefix: deps
Expand Down
45 changes: 34 additions & 11 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ jobs:
timeout-minutes: 5
outputs:
docs_only: ${{ steps.paths.outputs.docs_only }}
skip_macos: ${{ steps.paths.outputs.skip_macos }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
Expand All @@ -30,17 +31,36 @@ jobs:
env:
BASE: ${{ github.event.pull_request.base.sha }}
HEAD: ${{ github.event.pull_request.head.sha }}
BASE_REF: ${{ github.event.pull_request.base.ref }}
HEAD_REF: ${{ github.event.pull_request.head.ref }}
HEAD_REPO: ${{ github.event.pull_request.head.repo.full_name }}
run: |
result=docs_only=false
skip_macos=false
trusted_script="$RUNNER_TEMP/docs_only.py"
if git show "${BASE}:scripts/docs_only.py" > "$trusted_script"; then
if output=$(env -u GITHUB_OUTPUT python "$trusted_script" --base "$BASE" --head "$HEAD"); then
case "$output" in
docs_only=true|docs_only=false) result="$output" ;;
docs_only=true|docs_only=false)
result="$output"
if [ -n "$HEAD_REPO" ] && [ "$HEAD_REPO" = "$GITHUB_REPOSITORY" ]; then
if [ "$result" = docs_only=true ]; then
skip_macos=true
elif [ "$BASE_REF" = main ] && [ "$HEAD_REF" = dev ]; then
# Only exit 1 proves a nonempty delta for this direct promotion.
if git --no-replace-objects diff --quiet --no-ext-diff --no-textconv "$BASE" "$HEAD" --; then
:
elif [ "$?" -eq 1 ]; then
skip_macos=true
fi
fi
fi
;;
esac
fi
fi
echo "$result" >> "$GITHUB_OUTPUT"
echo "skip_macos=$skip_macos" >> "$GITHUB_OUTPUT"

test-python312:
name: >-
Expand Down Expand Up @@ -82,18 +102,21 @@ jobs:
${{ github.event_name != 'pull_request' && format('manual-test-{0}-py{1}', matrix.os, matrix.python) ||
github.event.pull_request.draft && 'draft-deferred-test-matrix' || format('test-{0}-py{1}', matrix.os, matrix.python) }}
if: ${{ !cancelled() && (github.event_name != 'pull_request' || !github.event.pull_request.draft) }}
continue-on-error: ${{ matrix.advisory }}
continue-on-error: ${{ matrix.os == 'macos-latest' }}
env:
UV_PYTHON: ${{ matrix.python }}
strategy:
fail-fast: false
matrix:
include:
- { os: ubuntu-latest, python: "3.13", coverage: false, advisory: false }
- { os: ubuntu-latest, python: "3.14", coverage: true, advisory: false }
- { os: ubuntu-latest, python: "3.15", coverage: false, advisory: false }
- { os: macos-latest, python: "3.12", coverage: false, advisory: true }
- { os: macos-latest, python: "3.14", coverage: false, advisory: true }
os: >-
${{ fromJSON(github.event_name == 'pull_request' && needs.classify.result == 'success' &&
needs.classify.outputs.skip_macos == 'true' && '["ubuntu-latest"]' ||
'["ubuntu-latest","macos-latest"]') }}
python: ["3.12", "3.13", "3.14", "3.15"]
exclude:
- { os: ubuntu-latest, python: "3.12" }
- { os: macos-latest, python: "3.13" }
- { os: macos-latest, python: "3.15" }
runs-on: ${{ matrix.os }}
timeout-minutes: 30
steps:
Expand All @@ -104,7 +127,7 @@ jobs:
persist-credentials: false
- name: Install qualified OCR for native coverage
id: native-ocr
if: ${{ needs.classify.outputs.docs_only != 'true' && matrix.coverage }}
if: ${{ needs.classify.outputs.docs_only != 'true' && matrix.os == 'ubuntu-latest' && matrix.python == '3.14' }}
env:
PR_BASE: ${{ github.event.pull_request.base.sha }}
shell: bash
Expand Down Expand Up @@ -173,10 +196,10 @@ jobs:
- if: needs.classify.outputs.docs_only != 'true'
run: uv sync --locked --python "${{ matrix.python }}"
- name: Test
if: ${{ needs.classify.outputs.docs_only != 'true' && !matrix.coverage }}
if: ${{ needs.classify.outputs.docs_only != 'true' && (matrix.os != 'ubuntu-latest' || matrix.python != '3.14') }}
run: uv run --no-sync pytest -q --ignore=tests/test_installed_policy_e2e.py
- name: Test with boundary coverage gates
if: ${{ needs.classify.outputs.docs_only != 'true' && matrix.coverage }}
if: ${{ needs.classify.outputs.docs_only != 'true' && matrix.os == 'ubuntu-latest' && matrix.python == '3.14' }}
env:
OCR_FEDERATION_QUALIFY_BINARY: ${{ steps.native-ocr.outputs.binary }}
OCR_GITLINK_QUALIFY_BINARY: ${{ steps.native-ocr.outputs.binary }}
Expand Down
125 changes: 55 additions & 70 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
name: Release

on:
pull_request:
types: [closed]
branches: [main]
workflow_dispatch:
inputs:
pull-request-number:
Expand Down Expand Up @@ -31,39 +28,23 @@ permissions:
contents: read

concurrency:
group: production-release
# Match authorize.if so skipped dispatches cannot replace a pending release.
group: >-
${{
github.event_name == 'workflow_dispatch' &&
github.event.repository.private == false &&
github.ref == 'refs/heads/main' &&
'production-release' || format('release-ignored-{0}', github.run_id)
}}
cancel-in-progress: false

jobs:
classify:
name: classify-release-trigger
runs-on: ubuntu-latest
timeout-minutes: 2
outputs:
release: ${{ steps.classify.outputs.release }}
steps:
- id: classify
env:
EVENT_NAME: ${{ github.event_name }}
PR_MERGED: ${{ github.event.pull_request.merged }}
PR_HEAD_REF: ${{ github.event.pull_request.head.ref }}
run: |
release=false
if [ "${EVENT_NAME}" = workflow_dispatch ]; then
release=true
elif [ "${PR_MERGED}" = true ] && [[ "${PR_HEAD_REF}" == release/v* ]]; then
release=true
fi
echo "release=${release}" >> "${GITHUB_OUTPUT}"

authorize:
name: authorize-release
needs: classify
if: >-
github.event_name == 'workflow_dispatch' &&
github.event.repository.private == false &&
github.ref == 'refs/heads/main' &&
(github.event_name == 'workflow_dispatch' || github.event.pull_request.head.repo.full_name == github.repository) &&
needs.classify.outputs.release == 'true'
github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
timeout-minutes: 5
permissions:
Expand All @@ -83,16 +64,14 @@ jobs:
tree: ${{ steps.authorize.outputs.tree }}
version: ${{ steps.authorize.outputs.version }}
steps:
- name: Load the pinned main history for recovery
if: github.event_name == 'workflow_dispatch'
- name: Load the pinned main history
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: ${{ github.sha }}
path: dispatch-main
fetch-depth: 0
persist-credentials: false
- name: Verify the historical recovery policy reference before checkout
if: github.event_name == 'workflow_dispatch'
- name: Verify the protected release policy reference before checkout
env:
GH_TOKEN: ${{ github.token }}
PR_NUMBER: ${{ inputs['pull-request-number'] }}
Expand All @@ -102,6 +81,10 @@ jobs:
BASE: ${{ inputs['reviewed-base'] }}
shell: bash
run: |
if [[ "${GITHUB_REF}" != refs/heads/main ]]; then
echo "release dispatch must run from refs/heads/main" >&2
exit 1
fi
[[ "${PR_NUMBER}" =~ ^[1-9][0-9]*$ && "${VERSION}" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]
[[ "${MERGE}" =~ ^[0-9a-f]{40}$ && "${HEAD}" =~ ^[0-9a-f]{40}$ && "${BASE}" =~ ^[0-9a-f]{40}$ ]]
[[ "${GITHUB_SHA}" =~ ^[0-9a-f]{40}$ ]]
Expand All @@ -116,55 +99,46 @@ jobs:
curl --fail --silent --show-error --proto '=https' \
--connect-timeout 10 --max-time 30 --max-filesize 1048576 \
--header 'Accept: application/vnd.github+json' \
--header 'X-GitHub-Api-Version: 2026-03-10' \
--header "X-GitHub-Api-Version: $1" \
--oauth2-bearer "${GH_TOKEN}" \
"https://api.github.com/repos/${GITHUB_REPOSITORY}/$1"
"https://api.github.com/repos/${GITHUB_REPOSITORY}/$2"
}
read_github_metadata "pulls/${PR_NUMBER}" |
# Pull request responses in 2026-03-10 omit merge_commit_sha.
if ! read_github_metadata 2022-11-28 "pulls/${PR_NUMBER}" |
jq -e --arg repo "${GITHUB_REPOSITORY}" --argjson number "${PR_NUMBER}" \
--arg version "${VERSION}" --arg head "${HEAD}" --arg merge "${MERGE}" --arg base "${BASE}" '
.number == $number and .merged == true and .merge_commit_sha == $merge and
.base.repo.full_name == $repo and .base.ref == "main" and .base.sha == $base and
.head.repo.full_name == $repo and .head.ref == ("release/v" + $version) and
.head.sha == $head and .title == ("Release v" + $version)
' >/dev/null
read_github_metadata "git/commits/${MERGE}" |
' >/dev/null; then
echo "release pull request does not match the requested identities" >&2
exit 1
fi
if ! read_github_metadata 2026-03-10 "git/commits/${MERGE}" |
jq -e --arg merge "${MERGE}" --arg base "${BASE}" '
.sha == $merge and (.parents | length) == 1 and .parents[0].sha == $base
' >/dev/null
' >/dev/null; then
echo "release merge is not a squash of the requested protected base" >&2
exit 1
fi
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
# Authorization code must come from protected policy that predates the
# release PR. Candidate head and merge commits are inspected only as data.
ref: ${{ github.event.pull_request.base.sha || inputs['reviewed-base'] }}
ref: ${{ inputs['reviewed-base'] }}
persist-credentials: false
- id: authorize
env:
GH_TOKEN: ${{ github.token }}
EVENT_NAME: ${{ github.event_name }}
EVENT_PR_NUMBER: ${{ github.event.pull_request.number }}
EVENT_BASE_SHA: ${{ github.event.pull_request.base.sha }}
INPUT_PR_NUMBER: ${{ inputs['pull-request-number'] }}
INPUT_VERSION: ${{ inputs.version }}
INPUT_COMMIT: ${{ inputs['merge-commit'] }}
INPUT_HEAD: ${{ inputs['reviewed-head'] }}
INPUT_BASE: ${{ inputs['reviewed-base'] }}
PR_NUMBER: ${{ inputs['pull-request-number'] }}
REQUESTED_VERSION: ${{ inputs.version }}
REQUESTED_COMMIT: ${{ inputs['merge-commit'] }}
REQUESTED_HEAD: ${{ inputs['reviewed-head'] }}
REQUESTED_BASE: ${{ inputs['reviewed-base'] }}
REPOSITORY: ${{ github.repository }}
run: |
if [ "${EVENT_NAME}" = workflow_dispatch ]; then
PR_NUMBER=${INPUT_PR_NUMBER}
REQUESTED_VERSION=${INPUT_VERSION}
REQUESTED_COMMIT=${INPUT_COMMIT}
REQUESTED_HEAD=${INPUT_HEAD}
REQUESTED_BASE=${INPUT_BASE}
else
PR_NUMBER=${EVENT_PR_NUMBER}
REQUESTED_VERSION=
REQUESTED_COMMIT=
REQUESTED_HEAD=
REQUESTED_BASE=${EVENT_BASE_SHA}
fi
test "$(scripts/bounded_github_api.sh \
test "$(GITHUB_API_VERSION=2022-11-28 scripts/bounded_github_api.sh \
"repos/${REPOSITORY}/pulls/${PR_NUMBER}" /tmp/release-pr.json)" = 200
HEAD_SHA=$(jq -r .head.sha /tmp/release-pr.json)
MERGE_SHA=$(jq -r .merge_commit_sha /tmp/release-pr.json)
Expand Down Expand Up @@ -340,6 +314,21 @@ jobs:
encoding="utf-8",
)
PY
- name: Verify original source attestations before publication
if: github.sha != needs.authorize.outputs.commit
env:
GH_TOKEN: ${{ github.token }}
EXPECTED_COMMIT: ${{ needs.authorize.outputs.commit }}
shell: bash
run: |
for artifact in dist/* runtime-requirements.txt; do
gh attestation verify "${artifact}" \
--repo "${GITHUB_REPOSITORY}" \
--signer-workflow "${GITHUB_REPOSITORY}/.github/workflows/release.yml" \
--source-digest "${EXPECTED_COMMIT}" \
--source-ref refs/heads/main \
--deny-self-hosted-runners
done
- name: Load protected v0.11.1 PyPI recovery policy
if: github.event_name == 'workflow_dispatch' && inputs.version == '0.11.1'
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
Expand Down Expand Up @@ -408,6 +397,7 @@ jobs:
classify testpypi https://test.pypi.org/simple/open-code-review-toolkit/ /tmp/testpypi-index.json
classify pypi https://pypi.org/simple/open-code-review-toolkit/ /tmp/pypi-index.json
- uses: actions/attest-build-provenance@4d101475d8b20a2381f78447822ac1eab6504dd8 # v4.2.2
if: github.sha == needs.authorize.outputs.commit
with:
subject-path: |
dist/*
Expand All @@ -426,7 +416,7 @@ jobs:
publish-testpypi:
name: publish-testpypi
needs: build
if: needs.build.outputs.testpypi-state == 'publish'
if: github.ref == 'refs/heads/main' && needs.build.outputs.testpypi-state == 'publish'
runs-on: ubuntu-latest
timeout-minutes: 10
environment: testpypi-public-disclosure
Expand Down Expand Up @@ -479,7 +469,7 @@ jobs:
publish-pypi:
name: publish-pypi
needs: [build, verify-testpypi]
if: needs.build.outputs.pypi-state == 'publish'
if: github.ref == 'refs/heads/main' && needs.build.outputs.pypi-state == 'publish'
runs-on: ubuntu-latest
timeout-minutes: 10
environment: pypi-production
Expand Down Expand Up @@ -557,7 +547,7 @@ jobs:
needs: [authorize, build, verify-pypi]
if: >-
always() && needs.authorize.result == 'success' && needs.build.result == 'success' &&
needs.verify-pypi.result == 'success'
needs.verify-pypi.result == 'success' && github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
timeout-minutes: 10
permissions:
Expand Down Expand Up @@ -704,11 +694,6 @@ jobs:
--hashes artifact-hashes.json \
--runtime-requirements runtime-requirements.txt \
--validate-existing release-receipt.json
if [[ "${GITHUB_EVENT_NAME}" == pull_request ]] &&
! jq -e --argjson run "${GITHUB_RUN_ID}" '.workflow.run_id == $run' release-receipt.json >/dev/null; then
echo "This receipt was created by another run. Use the main-branch release recovery dispatch." >&2
exit 1
fi
;;
*) echo "duplicate GitHub Release receipt asset" >&2; exit 1 ;;
esac
Expand Down
17 changes: 5 additions & 12 deletions .github/workflows/site-release-notify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name: Notify toolkit site of stable release
on:
workflow_run:
workflows: [Release]
branches: [main]
types: [completed]

permissions: {}
Expand All @@ -20,8 +21,7 @@ jobs:
github.event.workflow_run.repository.full_name == github.repository &&
github.event.workflow_run.head_repository.full_name == github.repository &&
github.event.workflow_run.conclusion == 'success' &&
((github.event.workflow_run.event == 'pull_request' && startsWith(github.event.workflow_run.head_branch, 'release/v')) ||
(github.event.workflow_run.event == 'workflow_dispatch' && github.event.workflow_run.head_branch == 'main'))
github.event.workflow_run.event == 'workflow_dispatch' && github.event.workflow_run.head_branch == 'main'
runs-on: ubuntu-latest
timeout-minutes: 5
permissions:
Expand Down Expand Up @@ -104,11 +104,8 @@ jobs:
exit 1
}
read -r _ _ _ expected_tag expected_digest receipt_mode <<< "${marker}"
case "${SOURCE_EVENT}" in
pull_request) test "${SOURCE_HEAD_BRANCH}" = "release/${expected_tag}" ;;
workflow_dispatch) test "${SOURCE_HEAD_BRANCH}" = main ;;
*) exit 1 ;;
esac
test "${SOURCE_EVENT}" = workflow_dispatch
test "${SOURCE_HEAD_BRANCH}" = main

gh api -H 'X-GitHub-Api-Version: 2026-03-10' "repos/${GITHUB_REPOSITORY}/releases/latest" \
> "${RUNNER_TEMP}/latest-release.json"
Expand Down Expand Up @@ -137,21 +134,17 @@ jobs:
exit 1
fi
jq -e --arg tag "${expected_tag}" --arg mode "${receipt_mode}" \
--arg event "${SOURCE_EVENT}" --arg head "${SOURCE_HEAD_SHA}" \
--argjson id "${SOURCE_RUN_ID}" --argjson attempt "${SOURCE_RUN_ATTEMPT}" '
def positive_integer: type == "number" and . == floor and . > 0;
.schema_version == "ocr-toolkit.release-receipt/v2" and
.tag == $tag and .version == ($tag | ltrimstr("v")) and
(.reviewed.merge | type == "string" and test("^[0-9a-f]{40}$")) and
.github.annotated_tag_target == .reviewed.merge and
($event != "pull_request" or .reviewed.head == $head) and
(.workflow.run_id | positive_integer) and (.workflow.run_attempt | positive_integer) and
(if $mode == "created" then
.workflow.run_id == $id and .workflow.run_attempt == $attempt
elif .workflow.run_id == $id then
.workflow.run_attempt <= $attempt
else
$event == "workflow_dispatch"
.workflow.run_id != $id or .workflow.run_attempt <= $attempt
end)
' "${RUNNER_TEMP}/release-receipt.json" >/dev/null

Expand Down
1 change: 1 addition & 0 deletions changelog.d/364.maintenance.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Start stable publication on protected main and verify historical rebuilds against the original source attestations before registry upload. Group scheduled minor and patch runtime dependency updates on dev. Skip advisory macOS jobs on internal documentation-only PRs and direct dev-to-main promotions.
Loading
Loading