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
2 changes: 1 addition & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ updates:
# Prefix commit message with "chore: "
prefix: "chore"
- package-ecosystem: pip
directory: /
directory: /hatch-prebuilt
schedule:
interval: "weekly"
cooldown:
Expand Down
383 changes: 383 additions & 0 deletions .github/workflows/binary-wheels.yml

Large diffs are not rendered by default.

230 changes: 230 additions & 0 deletions .github/workflows/monitor-upstream.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,230 @@
name: Monitor upstream releases

# Checks whether the upstream project of a cpp-linter wheel repository has a
# release newer than the one in the repository's version file, and opens (or
# updates) a pull request that updates the version file when it does.
#
# With the cpp-linter-publisher GitHub App (the RELEASE_APP_CLIENT_ID variable
# and the RELEASE_APP_PRIVATE_KEY secret, passed with `secrets: inherit`), the
# App opens the pull request, so its CI runs, and turns on auto-merge: once
# the checks that the branch rules require pass, it merges, and
# release-drafter.yml (publish: true) publishes the release, which uploads the
# wheels to PyPI. No one has to do anything. Without the App, the pull request
# says what to do by hand.
#
# A repository whose pyproject.toml configures hatch-prebuilt's
# static-binaries recipe needs no inputs: the defaults follow the static
# binaries' index.json.

on:
workflow_call:
inputs:
name:
description: The upstream project's name, for the pull request, e.g. ccache or LLVM
type: string
required: false
default: LLVM
version-file:
description: >-
The file that holds the packaged version, e.g. ccache_version.txt.
Empty means the one that `python -m hatch_prebuilt info` names.
type: string
required: false
default: ""
latest-command:
description: >-
A command that prints the latest upstream version, e.g.
gh api repos/ccache/ccache/releases/latest --jq .tag_name.
A leading v is dropped. GH_TOKEN is set. Empty means the newest
version of the recipe's first tool in the static binaries' index.json.
type: string
required: false
default: ""
update-command:
description: >-
A command that updates the repository to the new upstream version in
$VERSION. Empty means `python -m hatch_prebuilt update` for a static
binaries recipe, then writing $VERSION to version-file.
type: string
required: false
default: ""
auto-merge:
description: Turn on auto-merge for the pull request, when the App opens it
type: boolean
required: false
default: true
secrets:
RELEASE_APP_PRIVATE_KEY:
description: The private key of the cpp-linter-publisher App
required: false

permissions: {}

jobs:
check:
name: Check for a new ${{ inputs.name }} release
runs-on: ubuntu-latest
permissions:
contents: write # push the branch
pull-requests: write # open the pull request
concurrency:
group: monitor-upstream-${{ github.repository }}
cancel-in-progress: true
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
# Update the default branch, also when run by hand from another one.
ref: ${{ github.event.repository.default_branch }}
persist-credentials: false
- uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0
with:
python-version: "3.x"
- name: Read the recipe
id: recipe
env:
VERSION_FILE: ${{ inputs.version-file }}
LATEST_COMMAND: ${{ inputs.latest-command }}
UPDATE_COMMAND: ${{ inputs.update-command }}
run: |
# With version-file and latest-command, a caller needs no recipe:
# without update-command, the update only writes the version file.
if [ -n "$VERSION_FILE" ] && [ -n "$LATEST_COMMAND" ] && [ -z "$UPDATE_COMMAND" ]; then
UPDATE_COMMAND='echo "$VERSION" > "$VERSION_FILE"'
fi
if [ -z "$VERSION_FILE" ] || [ -z "$LATEST_COMMAND" ] || [ -z "$UPDATE_COMMAND" ]; then
python -m pip install --quiet --group build
python -m hatch_prebuilt info > "$RUNNER_TEMP/info.json"
cat "$RUNNER_TEMP/info.json"
if [ -z "$VERSION_FILE" ]; then
VERSION_FILE=$(jq -r '."version-file"' "$RUNNER_TEMP/info.json")
fi
tool=$(jq -r '."static-binaries-tools"[0] // empty' "$RUNNER_TEMP/info.json")
if [ -z "$tool" ] && [ -z "$LATEST_COMMAND" ]; then
echo "::error::Set latest-command: this is not a static binaries recipe"
exit 1
fi
# The commands below read TOOL and VERSION_FILE from the environment.
if [ -z "$LATEST_COMMAND" ]; then
LATEST_COMMAND='curl -fsSL https://cpp-linter.github.io/clang-tools-static-binaries/index.json | jq -r --arg tool "$TOOL" '"'"'[.versions[] | select(.tools[$tool]) | .version] | sort_by(split(".") | map(tonumber)) | last'"'"
fi
if [ -z "$UPDATE_COMMAND" ] && [ -n "$tool" ]; then
UPDATE_COMMAND='python -m hatch_prebuilt update && echo "$VERSION" > "$VERSION_FILE"'
elif [ -z "$UPDATE_COMMAND" ]; then
UPDATE_COMMAND='echo "$VERSION" > "$VERSION_FILE"'
fi
fi
{
echo "version-file=$VERSION_FILE"
echo "tool=${tool:-}"
echo "latest-command<<COMMAND_EOF"
echo "$LATEST_COMMAND"
echo "COMMAND_EOF"
echo "update-command<<COMMAND_EOF"
echo "$UPDATE_COMMAND"
echo "COMMAND_EOF"
} >> "$GITHUB_OUTPUT"
- name: Compare with the latest ${{ inputs.name }} release
id: latest
env:
GH_TOKEN: ${{ github.token }}
NAME: ${{ inputs.name }}
VERSION_FILE: ${{ steps.recipe.outputs.version-file }}
TOOL: ${{ steps.recipe.outputs.tool }}
LATEST_COMMAND: ${{ steps.recipe.outputs.latest-command }}
UPDATE_COMMAND: ${{ steps.recipe.outputs.update-command }}
run: |
export TOOL VERSION_FILE
latest=$(bash -euo pipefail -c "$LATEST_COMMAND")
latest=${latest#v}
if ! [[ "$latest" =~ ^[0-9]+(\.[0-9]+)*$ ]]; then
echo "::error::Unexpected $NAME version '$latest'."
exit 1
fi
# Compare the upstream part of the packaged version: drop a .postN
# suffix and any packaging component beyond the upstream version.
packaged=$(cat "$VERSION_FILE")
packaged=${packaged%%.post*}
parts=$(echo "$latest" | tr -cd . | wc -c)
current=$(echo "$packaged" | cut -d. -f1-$((parts + 1)))
echo "Packaged: $current, latest $NAME release: $latest"
if [ "$(printf '%s\n%s\n' "$current" "$latest" | sort -V | tail -n 1)" = "$current" ]; then
echo "Up to date."
exit 0
fi
VERSION=$latest bash -euo pipefail -c "$UPDATE_COMMAND"
echo "version=$latest" >> "$GITHUB_OUTPUT"
echo "branch=update-$(echo "$NAME" | tr '[:upper:] ' '[:lower:]-')" >> "$GITHUB_OUTPUT"

# The App's token makes GitHub start CI on the pull request, and lets
# auto-merge merge it as the App, which starts the workflows on main.
- name: Get a cpp-linter-publisher token
id: app
if: steps.latest.outputs.version != '' && vars.RELEASE_APP_CLIENT_ID != ''
uses: actions/create-github-app-token@f418cff399f7aef4c2f0ad47e25ca7a6abbdd6fc # v3.4.0
with:
client-id: ${{ vars.RELEASE_APP_CLIENT_ID }}
private-key: ${{ secrets.RELEASE_APP_PRIVATE_KEY }}
permission-contents: write # push the branch, merge
permission-pull-requests: write # open the pull request, turn on auto-merge

- name: Write the pull request body
if: steps.latest.outputs.version != ''
env:
NAME: ${{ inputs.name }}
VERSION: ${{ steps.latest.outputs.version }}
VERSION_FILE: ${{ steps.recipe.outputs.version-file }}
APP: ${{ steps.app.outputs.token != '' }}
AUTO_MERGE: ${{ inputs.auto-merge }}
RELEASES: ${{ github.server_url }}/${{ github.repository }}/releases
run: |
{
echo "$NAME $VERSION is out. This updates \`$VERSION_FILE\` to it."
echo
if [ "$APP" = true ]; then
echo "The CI builds and tests the wheels of the new version. Merging this pull request publishes the v$VERSION release, which uploads the wheels to PyPI."
echo
if [ "$AUTO_MERGE" = true ]; then
echo "If the default branch requires status checks, this pull request merges itself when they pass. If not, the update workflow warns and a person merges it."
else
echo "Auto-merge is off for this repository: merge it when the checks pass."
fi
else
echo "1. Close and reopen this pull request: GitHub does not start CI on a pull request that a workflow opened. The CI builds and tests the wheels of the new version."
echo "2. Merge it. The release draft becomes v$VERSION."
echo "3. Publish the [draft release]($RELEASES) to upload the wheels to PyPI."
fi
} > "$RUNNER_TEMP/body.md"

- name: Open or update the pull request
id: pr
if: steps.latest.outputs.version != ''
uses: peter-evans/create-pull-request@3ffccacd46053766916f087ce41d627c0b8cf2d1 # v8.1.3
with:
token: ${{ steps.app.outputs.token || github.token }}
sign-commits: true
base: ${{ github.event.repository.default_branch }}
branch: ${{ steps.latest.outputs.branch }}
delete-branch: true
commit-message: "feat: update ${{ inputs.name }} to ${{ steps.latest.outputs.version }}"
title: "feat: update ${{ inputs.name }} to ${{ steps.latest.outputs.version }}"
body-path: ${{ runner.temp }}/body.md

# Auto-merge waits for the checks that the branch rules require. Without
# a required check it would merge before the CI has run, so it stays off.
- name: Turn on auto-merge
if: >-
inputs.auto-merge && steps.app.outputs.token != '' &&
steps.pr.outputs.pull-request-number != ''
env:
GH_TOKEN: ${{ steps.app.outputs.token }}
GH_REPO: ${{ github.repository }}
BRANCH: ${{ github.event.repository.default_branch }}
PR: ${{ steps.pr.outputs.pull-request-number }}
run: |
checks=$(gh api "repos/$GH_REPO/rules/branches/$BRANCH" \
--jq '[.[] | select(.type == "required_status_checks")] | length')
if [ "$checks" = 0 ]; then
echo "::warning::$BRANCH has no required status checks, so auto-merge stays off: merge #$PR by hand, or add the checks in a ruleset (see runbooks/one-time-setup.md in cpp-linter/wheels)."
exit 0
fi
gh pr merge "$PR" --auto --squash
11 changes: 6 additions & 5 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
name: Upload Python Package

# Publishing a GitHub release uploads the package to PyPI. Running this
# workflow by hand on main uploads it to TestPyPI. Both use PyPI trusted
# publishing (OIDC), so no API token is stored in this repository; the
# publish jobs run in the "pypi" / "testpypi" environments.
# Publishing a GitHub release uploads hatch-prebuilt, the only package in this
# repository, to PyPI. Running this workflow by hand on main uploads it to
# TestPyPI. Both use PyPI trusted publishing (OIDC), so no API token is stored
# in this repository; the publish jobs run in the "pypi" / "testpypi"
# environments.

on:
release:
Expand All @@ -30,7 +31,7 @@ jobs:
with:
enable-cache: false
- name: Build the sdist and the wheel
run: uv build
run: uv build hatch-prebuilt --out-dir dist
- name: Check the distributions
run: uvx twine check --strict dist/*
- name: Attest build provenance
Expand Down
52 changes: 51 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ permissions: {}

jobs:
test:
name: hatch-prebuilt (${{ matrix.os }}, ${{ matrix.python }})
strategy:
fail-fast: false
matrix:
Expand All @@ -32,4 +33,53 @@ jobs:
shell: bash # PowerShell would not expand $PYTHON
env:
PYTHON: ${{ matrix.python }}
run: uv run --python "$PYTHON" --group test pytest -v
run: uv run --directory hatch-prebuilt --python "$PYTHON" --group test pytest -v

# Write a wheel repository with the runbook's script, build one of its
# wheels with hatch-prebuilt from this commit, and run its smoke test: the
# plugin, the templates and the script have to keep working together.
new-wheel:
name: A new wheel repository (${{ matrix.tool }})
strategy:
fail-fast: false
matrix:
include:
- tool: clang-query
options: ""
# A tool with clang's builtin headers, in a package of another name.
- tool: clang-tidy
options: --headers --project clang-tidy-bin --package clang_tidy_bin
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 0
persist-credentials: false
- uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0
with:
python-version: "3.x"
- name: Install hatch-prebuilt from this commit
run: python -m pip install ./hatch-prebuilt build hatchling
- name: Write the repository
env:
TOOL: ${{ matrix.tool }}
OPTIONS: ${{ matrix.options }}
run: |
# shellcheck disable=SC2086 # OPTIONS holds several options
python runbooks/new-wheel.py "$TOOL" --summary "a test" $OPTIONS --out "$RUNNER_TEMP/repo"
cd "$RUNNER_TEMP/repo"
cat pyproject.toml
python -m hatch_prebuilt info
- name: Build a wheel
working-directory: ${{ runner.temp }}/repo
# Without build isolation, to build with hatch-prebuilt from this
# commit rather than the one on PyPI.
run: python -m build --wheel --no-isolation --skip-dependency-check
- name: Install it and run the smoke test
working-directory: ${{ runner.temp }}/repo
run: |
python -m venv .venv
.venv/bin/python -m pip install dist/*.whl
PATH="$PWD/.venv/bin:$PATH" .venv/bin/python tests/smoke_test.py --version "$(cat llvm_version.txt)"
Loading
Loading