|
1 | | -# GitHub Action |
| 1 | +# CI Store Population |
2 | 2 |
|
3 | | -headerkit ships a composite GitHub Action that populates the |
4 | | -`.headerkit/` cache in CI. Use it to keep cache entries up to date |
5 | | -whenever headers change, so downstream builds never need libclang. |
| 3 | +headerkit's PEP 517 build backend populates `.headerkit/` during wheel |
| 4 | +builds. To keep the store up to date across platforms, use a CI workflow |
| 5 | +that builds wheels in a matrix, collects artifacts, and opens a PR if |
| 6 | +anything changed. No custom action needed -- just standard GitHub Actions |
| 7 | +building blocks. |
6 | 8 |
|
7 | | -## What it does |
8 | | - |
9 | | -The action runs three steps: |
10 | | - |
11 | | -1. Sets up Python (via `actions/setup-python`). |
12 | | -2. Installs headerkit from PyPI. |
13 | | -3. Runs `headerkit cache populate` with the arguments you provide. |
| 9 | +## How it works |
14 | 10 |
|
15 | | -Optionally, it commits the updated `.headerkit/` directory back to the |
16 | | -branch. |
| 11 | +The `.headerkit/` directory contains IR (parsed headers) and output |
| 12 | +(generated bindings) so that downstream builds work without libclang |
| 13 | +installed. This directory should be committed to your repository; it is |
| 14 | +not ephemeral cache. |
17 | 15 |
|
18 | | -## Inputs |
| 16 | +The CI pattern has two jobs: |
19 | 17 |
|
20 | | -| Input | Required | Default | Description | |
21 | | -|-------|----------|---------|-------------| |
22 | | -| `headerkit-version` | no | latest | Pin a specific headerkit version (e.g., `0.15.0`) | |
23 | | -| `python-version` | no | `3.12` | Python version for the runner | |
24 | | -| `args` | no | `""` | Arguments passed to `headerkit cache populate` | |
25 | | -| `commit` | no | `false` | Commit populated cache files after generation | |
| 18 | +1. **build** -- runs in a matrix across platforms, builds wheels, and |
| 19 | + uploads the `.headerkit/` directory as an artifact. |
| 20 | +2. **update-store** -- downloads all artifacts into a single `.headerkit/` |
| 21 | + directory and opens a PR if anything changed. |
26 | 22 |
|
27 | | -## Basic usage |
| 23 | +## Example workflow |
28 | 24 |
|
29 | 25 | ```yaml |
30 | | -name: Populate headerkit cache |
| 26 | +name: Update headerkit store |
31 | 27 | on: |
32 | 28 | push: |
| 29 | + branches: [main] |
33 | 30 | paths: |
34 | 31 | - "include/**/*.h" |
| 32 | + - "pyproject.toml" |
| 33 | + schedule: |
| 34 | + - cron: "0 6 * * 1" # weekly on Monday |
35 | 35 |
|
36 | 36 | jobs: |
37 | | - populate: |
38 | | - runs-on: ubuntu-latest |
| 37 | + build: |
| 38 | + strategy: |
| 39 | + matrix: |
| 40 | + os: [ubuntu-latest, macos-latest, windows-latest] |
| 41 | + runs-on: ${{ matrix.os }} |
39 | 42 | steps: |
40 | 43 | - uses: actions/checkout@v4 |
41 | 44 |
|
42 | | - - uses: axiomantic/headerkit@v0 |
| 45 | + - uses: actions/setup-python@v5 |
43 | 46 | with: |
44 | | - args: "include/mylib.h -w cffi --platform linux/amd64" |
45 | | - commit: "true" |
46 | | -``` |
47 | | -
|
48 | | -This installs the latest headerkit, runs `cache populate` for the |
49 | | -specified header and platform, and commits the result. |
| 47 | + python-version: "3.12" |
50 | 48 |
|
51 | | -## Pin a headerkit version |
| 49 | + - name: Build wheel |
| 50 | + run: pip install build && python -m build --wheel |
52 | 51 |
|
53 | | -Lock the version to avoid surprises from new releases: |
54 | | - |
55 | | -```yaml |
56 | | -- uses: axiomantic/headerkit@v0 |
57 | | - with: |
58 | | - headerkit-version: "0.15.0" |
59 | | - args: "include/mylib.h -w cffi --cibuildwheel" |
60 | | -``` |
| 52 | + - uses: actions/upload-artifact@v4 |
| 53 | + with: |
| 54 | + name: headerkit-store-${{ matrix.os }} |
| 55 | + path: .headerkit/ |
61 | 56 |
|
62 | | -## Usage with cibuildwheel |
| 57 | + update-store: |
| 58 | + needs: build |
| 59 | + runs-on: ubuntu-latest |
| 60 | + permissions: |
| 61 | + contents: write |
| 62 | + pull-requests: write |
| 63 | + steps: |
| 64 | + - uses: actions/checkout@v4 |
63 | 65 |
|
64 | | -If your project uses cibuildwheel, pass `--cibuildwheel` to auto-detect |
65 | | -target platforms and Python versions from `[tool.cibuildwheel]` in |
66 | | -`pyproject.toml`: |
| 66 | + - uses: actions/download-artifact@v4 |
| 67 | + with: |
| 68 | + pattern: headerkit-store-* |
| 69 | + path: .headerkit/ |
| 70 | + merge-multiple: true |
67 | 71 |
|
68 | | -```yaml |
69 | | -- uses: axiomantic/headerkit@v0 |
70 | | - with: |
71 | | - args: "--cibuildwheel" |
72 | | - commit: "true" |
| 72 | + - uses: peter-evans/create-pull-request@v8 |
| 73 | + with: |
| 74 | + commit-message: "chore: update headerkit store" |
| 75 | + title: "chore: update headerkit store" |
| 76 | + branch: headerkit/update-store |
| 77 | + body: | |
| 78 | + Automated update of `.headerkit/` store from CI matrix build. |
| 79 | + labels: automated |
73 | 80 | ``` |
74 | 81 |
|
75 | | -This reads the `build` and `skip` selectors to determine which CPython |
76 | | -versions and Linux platforms to target. |
77 | | - |
78 | | -## Usage with multiple platforms |
| 82 | +## Using cibuildwheel |
79 | 83 |
|
80 | | -Generate cache entries for specific platforms using `--platform`: |
| 84 | +If your project uses cibuildwheel, replace the build step: |
81 | 85 |
|
82 | 86 | ```yaml |
83 | | -- uses: axiomantic/headerkit@v0 |
84 | | - with: |
85 | | - args: >- |
86 | | - include/mylib.h -w cffi |
87 | | - --platform linux/amd64 |
88 | | - --platform linux/arm64 |
89 | | - commit: "true" |
90 | | -``` |
91 | | - |
92 | | -For macOS and Windows targets, run the action on the matching runner |
93 | | -OS instead of relying on Docker emulation: |
94 | | - |
95 | | -```yaml |
96 | | -jobs: |
97 | | - populate-linux: |
98 | | - runs-on: ubuntu-latest |
| 87 | + build: |
| 88 | + strategy: |
| 89 | + matrix: |
| 90 | + os: [ubuntu-latest, macos-latest, windows-latest] |
| 91 | + runs-on: ${{ matrix.os }} |
99 | 92 | steps: |
100 | 93 | - uses: actions/checkout@v4 |
101 | | - - uses: axiomantic/headerkit@v0 |
| 94 | + |
| 95 | + - uses: actions/setup-python@v5 |
102 | 96 | with: |
103 | | - args: "include/mylib.h -w cffi --platform linux/amd64 --platform linux/arm64" |
104 | | - commit: "true" |
| 97 | + python-version: "3.12" |
105 | 98 |
|
106 | | - populate-macos: |
107 | | - runs-on: macos-latest |
108 | | - needs: populate-linux |
109 | | - steps: |
110 | | - - uses: actions/checkout@v4 |
111 | | - - uses: axiomantic/headerkit@v0 |
| 99 | + - name: Build wheels |
| 100 | + run: pip install cibuildwheel && cibuildwheel --output-dir dist |
| 101 | + |
| 102 | + - uses: actions/upload-artifact@v4 |
112 | 103 | with: |
113 | | - args: "include/mylib.h -w cffi" |
114 | | - commit: "true" |
| 104 | + name: headerkit-store-${{ matrix.os }} |
| 105 | + path: .headerkit/ |
115 | 106 | ``` |
116 | 107 |
|
117 | | -Note that when `commit: "true"` is used across multiple jobs, each job |
118 | | -must pull the latest commit from the previous job to avoid conflicts. |
119 | | -Use `needs:` to sequence them. |
| 108 | +The build backend populates `.headerkit/` as a side effect of each wheel |
| 109 | +build, so cibuildwheel produces store entries for every platform in the |
| 110 | +matrix automatically. |
120 | 111 |
|
121 | | -## How it works |
| 112 | +## Configuration options |
122 | 113 |
|
123 | | -The action is a [composite action](https://docs.github.com/en/actions/sharing-automations/creating-actions/creating-a-composite-action) |
124 | | -defined in `action.yml` at the repository root. It: |
| 114 | +### Customizing platforms |
125 | 115 |
|
126 | | -1. Calls `actions/setup-python` with the requested Python version. |
127 | | -2. Installs headerkit via pip. If `headerkit-version` is set, it pins |
128 | | - that exact version; otherwise it installs the latest release. |
129 | | -3. Runs `headerkit cache populate` with your `args` value. The args |
130 | | - are passed through to the command as-is, so any flag that |
131 | | - `cache populate` accepts works here. |
132 | | -4. If `commit` is `"true"`, it configures a bot git identity, stages |
133 | | - `.headerkit/`, and commits if there are changes. If the cache is |
134 | | - already up to date, the commit step is a no-op. |
| 116 | +Add or remove entries from `matrix.os` to match your target platforms: |
135 | 117 |
|
136 | | -All input values are passed via environment variables (not shell |
137 | | -interpolation) to prevent injection attacks. |
| 118 | +```yaml |
| 119 | +strategy: |
| 120 | + matrix: |
| 121 | + os: [ubuntu-latest, ubuntu-24.04-arm, macos-latest, windows-latest] |
| 122 | +``` |
138 | 123 |
|
139 | | -## Triggering on header changes |
| 124 | +### Configuring the PR |
140 | 125 |
|
141 | | -Use `paths` filters to run the action only when headers change: |
| 126 | +The `peter-evans/create-pull-request` action accepts many options for |
| 127 | +customizing the resulting pull request: |
142 | 128 |
|
143 | 129 | ```yaml |
144 | | -on: |
145 | | - push: |
146 | | - paths: |
147 | | - - "include/**/*.h" |
148 | | - - "vendor/**/*.h" |
| 130 | +- uses: peter-evans/create-pull-request@v8 |
| 131 | + with: |
| 132 | + commit-message: "chore: update headerkit store" |
| 133 | + title: "chore: update headerkit store" |
| 134 | + branch: headerkit/update-store |
| 135 | + labels: automated, dependencies |
| 136 | + reviewers: your-username |
| 137 | + draft: false |
149 | 138 | ``` |
150 | 139 |
|
151 | | -This avoids unnecessary cache populate runs on unrelated commits. |
| 140 | +See the [create-pull-request documentation](https://github.com/peter-evans/create-pull-request) |
| 141 | +for the full list of inputs. |
| 142 | + |
| 143 | +### Running on schedule vs on push |
| 144 | + |
| 145 | +The example workflow triggers both on push (when headers change) and on a |
| 146 | +weekly schedule. Adjust to fit your project: |
| 147 | + |
| 148 | +- **On push with path filters** -- reacts to header changes immediately. |
| 149 | +- **On schedule** -- catches changes from dependency updates or toolchain |
| 150 | + upgrades that affect generated output. |
| 151 | +- **Manual dispatch** -- add `workflow_dispatch:` to the `on:` block |
| 152 | + to allow manual runs from the Actions tab. |
152 | 153 |
|
153 | 154 | ## See also |
154 | 155 |
|
155 | 156 | - [Cache Strategy Guide](cache.md) for cache layout, bypass flags, and |
156 | 157 | multi-platform population details. |
157 | 158 | - [Build Backend Guide](build-backend.md) for using headerkit as a |
158 | | - PEP 517 build backend with committed cache. |
| 159 | + PEP 517 build backend with committed store. |
0 commit comments