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: 3 additions & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ updates:
# Prefix commit message with "chore: "
prefix: "chore"
- package-ecosystem: pip
directory: /hatch-prebuilt
directories:
- /
- /packages/*
schedule:
interval: "weekly"
cooldown:
Expand Down
154 changes: 154 additions & 0 deletions .github/workflows/automation.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
name: Automation

# The bot of this repository, as the cpp-linter-publisher GitHub App
# (RELEASE_APP_CLIENT_ID variable, RELEASE_APP_PRIVATE_KEY secret):
#
# push to main release every wheel package whose version file has a new
# version (scripts/release.py): the release starts
# publish.yml, which uploads the wheels to PyPI
# every day for each upstream project (LLVM, ccache, ...), one pull
# request that updates all its packages to the latest
# release (scripts/update.py); it merges itself once
# "All wheels pass"
#
# Without the App, releases stay drafts and update pull requests get no CI
# until a person closes and reopens them; see CONTRIBUTING.md.

on:
push:
branches: [main]
schedule:
- cron: "0 8 * * *"
workflow_dispatch:

permissions: {}

jobs:
release:
name: Release new versions
if: github.event_name == 'push' && github.repository_owner == 'cpp-linter'
runs-on: ubuntu-latest
permissions:
contents: write # create the releases (without the App)
concurrency:
group: release
cancel-in-progress: false
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
fetch-depth: 0 # the previous release tags, for the notes
- uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0
with:
python-version: "3.x"
- run: python -m pip install ./packages/hatch-prebuilt
# A release published with the workflow's own token would not start
# publish.yml, so the App publishes it.
- name: Get a cpp-linter-publisher token
id: app
if: 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 # publish the releases
- name: Release
env:
GH_TOKEN: ${{ steps.app.outputs.token || github.token }}
DRAFT: ${{ steps.app.outputs.token == '' && '--draft' || '' }}
run: python scripts/release.py $DRAFT

upstreams:
name: List the upstream projects
if: >-
(github.event_name == 'schedule' || github.event_name == 'workflow_dispatch') &&
github.repository_owner == 'cpp-linter'
runs-on: ubuntu-latest
permissions:
contents: read
outputs:
upstreams: ${{ steps.plan.outputs.upstreams }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0
with:
python-version: "3.x"
- id: plan
run: python scripts/plan.py --upstreams

update:
name: Update ${{ matrix.upstream }}
needs: upstreams
strategy:
fail-fast: false
matrix:
upstream: ${{ fromJSON(needs.upstreams.outputs.upstreams) }}
runs-on: ubuntu-latest
permissions:
contents: write # push the branch (without the App)
pull-requests: write # open the pull request (without the App)
concurrency:
group: update-${{ matrix.upstream }}
cancel-in-progress: true
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: ${{ github.event.repository.default_branch }}
persist-credentials: false
fetch-depth: 0 # hatch-prebuilt takes its version from the tags
- uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0
with:
python-version: "3.x"
- run: python -m pip install ./packages/hatch-prebuilt
- name: Update to the latest ${{ matrix.upstream }} release
id: update
env:
GH_TOKEN: ${{ github.token }}
UPSTREAM: ${{ matrix.upstream }}
run: python scripts/update.py "$UPSTREAM"

# The App's token makes GitHub start CI on the pull request, and lets
# auto-merge merge it as the App, which starts automation.yml on main.
- name: Get a cpp-linter-publisher token
id: app
if: steps.update.outputs.updated == 'true' && 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: Open or update the pull request
id: pr
if: steps.update.outputs.updated == 'true'
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.update.outputs.branch }}
delete-branch: true
commit-message: ${{ steps.update.outputs.title }}
title: ${{ steps.update.outputs.title }}
body: ${{ steps.update.outputs.body }}

# 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: 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 require \"All wheels pass\" in a ruleset (see CONTRIBUTING.md)."
exit 0
fi
gh pr merge "$PR" --auto --squash
80 changes: 62 additions & 18 deletions .github/workflows/binary-wheels.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
name: Build and test binary wheels

# Builds the Python wheels of a repository that repackages prebuilt binaries
# (ccache-wheel, llvm-cov-wheel, clangd-wheel), then installs and tests them on
# every supported platform with pip and uv. Each repository's own test.yml
# calls this workflow, and its publish.yml calls that test.yml before it
# uploads anything. The upload to PyPI stays in each repository's publish.yml,
# because PyPI trusted publishing does not work from inside a reusable
# workflow.
# Builds the Python wheels of one package that repackages prebuilt binaries,
# then installs and tests them on every supported platform with pip and uv.
# In this repository, ci.yml and publish.yml call it for each package under
# packages/ (`directory`), with the inputs that scripts/plan.py reads from the
# package's [tool.wheels]. The wheel repositories that have not moved here yet
# call it with the defaults, from their test.yml. The upload to PyPI stays in
# the caller, because PyPI trusted publishing does not work from inside a
# reusable workflow.
#
# What the calling repository provides:
# What the package (or the calling repository) provides:
# - a hatch-prebuilt recipe, configured in pyproject.toml or written in
# hatch_build.py: `python -m hatch_prebuilt platforms` (or, before
# hatch-prebuilt 0.3, `python hatch_build.py platforms`) prints the
Expand Down Expand Up @@ -36,6 +37,26 @@ name: Build and test binary wheels
on:
workflow_call:
inputs:
directory:
description: The package's directory, e.g. packages/clangd-bin (by default, the repository)
type: string
required: false
default: "."
artifact-suffix:
description: >-
Added to the names of the artifacts, e.g. -clangd-bin for wheels-clangd-bin,
so that one workflow run can build several packages.
type: string
required: false
default: ""
hatch-prebuilt:
description: >-
The directory of hatch-prebuilt in this repository, e.g.
packages/hatch-prebuilt: build with it instead of the release on PyPI.
Empty means the one that the package's build dependencies name.
type: string
required: false
default: ""
package:
description: The PyPI name of the package, e.g. ccache-bin (by default, project.name in pyproject.toml)
type: string
Expand Down Expand Up @@ -145,6 +166,9 @@ jobs:
runs-on: ubuntu-latest
permissions:
contents: read
defaults:
run:
working-directory: ${{ inputs.directory }}
outputs:
versions: ${{ steps.versions.outputs.versions }}
first: ${{ steps.versions.outputs.first }}
Expand All @@ -153,16 +177,23 @@ jobs:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
# hatch-prebuilt takes its version from the tags (0 = all history).
fetch-depth: ${{ inputs.hatch-prebuilt == '' && 1 || 0 }}
- uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0
with:
python-version: "3.x"
- run: python -m pip install --group build
- name: Install hatch-prebuilt from this commit
if: inputs.hatch-prebuilt
env:
HATCH_PREBUILT: ${{ github.workspace }}/${{ inputs.hatch-prebuilt }}
run: python -m pip install "$HATCH_PREBUILT"
- name: Download the binaries built by the calling workflow
if: inputs.binaries-artifacts
uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
pattern: ${{ inputs.binaries-artifacts }}
path: binaries
path: ${{ inputs.directory }}/binaries
# The inputs win; the recipe (hatch-prebuilt 0.3 or later) fills in the rest.
- name: Read the recipe
id: recipe
Expand Down Expand Up @@ -227,7 +258,14 @@ jobs:
VERSION_VARIABLE: ${{ steps.recipe.outputs.version-variable }}
PLATFORM_VARIABLE: ${{ steps.recipe.outputs.platform-variable }}
RECIPE: ${{ steps.recipe.outputs.command }}
# With hatch-prebuilt from this commit, build in this environment,
# where it is installed, instead of an isolated one from PyPI.
NO_ISOLATION: ${{ inputs.hatch-prebuilt != '' }}
run: |
options=()
if [ "$NO_ISOLATION" = true ]; then
options=(--no-isolation --skip-dependency-check)
fi
for version in $VERSIONS; do
# Ask for the platforms with the version set, in case a version
# has fewer of them.
Expand All @@ -237,7 +275,7 @@ jobs:
for platform in $platforms; do
env "$PLATFORM_VARIABLE=$platform" \
${VERSION_VARIABLE:+"$VERSION_VARIABLE=$version"} \
python -m build --wheel --outdir dist
python -m build --wheel --outdir dist "${options[@]}"
done
done
- name: Save the files for the GitHub release
Expand Down Expand Up @@ -269,14 +307,14 @@ jobs:
done
- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: wheels
path: dist/
name: wheels${{ inputs.artifact-suffix }}
path: ${{ inputs.directory }}/dist/
if-no-files-found: error
- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
if: inputs.release-files-command
with:
name: release-files
path: release/
name: release-files${{ inputs.artifact-suffix }}
path: ${{ inputs.directory }}/release/
if-no-files-found: error

test:
Expand All @@ -289,6 +327,9 @@ jobs:
fail-fast: false
matrix:
include: ${{ fromJSON(inputs.runners) }}
defaults:
run:
working-directory: ${{ inputs.directory }}
env:
PACKAGE: ${{ needs.build.outputs.package }}
VERSION: ${{ needs.build.outputs.first }}
Expand All @@ -302,8 +343,8 @@ jobs:
- uses: astral-sh/setup-uv@07a047e608db84b3d8c06cd9a7c7dcc9c355c18e # v10.3.2
- uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
name: wheels
path: dist
name: wheels${{ inputs.artifact-suffix }}
path: ${{ inputs.directory }}/dist
- name: Set up MSVC
if: inputs.msvc && runner.os == 'Windows'
uses: TheMrMilchmann/setup-msvc-dev@368ef7d1ee4d1171b31d4a7f67f4d954f903f5a9 # v4.1.0
Expand Down Expand Up @@ -350,14 +391,17 @@ jobs:
fail-fast: false
matrix:
include: ${{ fromJSON(inputs.containers) }}
defaults:
run:
working-directory: ${{ inputs.directory }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
name: wheels
path: dist
name: wheels${{ inputs.artifact-suffix }}
path: ${{ inputs.directory }}/dist
- name: Set up QEMU
if: matrix.qemu
uses: docker/setup-qemu-action@06116385d9baf250c9f4dcb4858b16962ea869c3 # v4.1.0
Expand Down
Loading
Loading