Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
e18f13a
Add workflow to release and sign wheels
agriyakhetarpal Apr 27, 2024
cf9845e
Move condition to PyPI publishing step
agriyakhetarpal Apr 27, 2024
918e372
Merge branch 'main' into add-pypi-workflow
agriyakhetarpal Oct 1, 2024
2deb188
Permanent GHA Attestations, update dependencies
agriyakhetarpal Oct 3, 2024
cd48f0c
Add a comment about the `twine` optional dep
agriyakhetarpal Oct 3, 2024
fb443f3
Rename from `cd.yaml` to `cd.yml`
agriyakhetarpal Oct 3, 2024
debaeea
Add a section on build provenance and verifying it
agriyakhetarpal Oct 3, 2024
f5424ee
Make the `push_to_pypi:` input explicit
agriyakhetarpal Oct 3, 2024
55bdcc9
Move condition for PyPI trigger to the job
agriyakhetarpal Oct 3, 2024
b808dfa
Merge branch 'main' into add-pypi-workflow
agriyakhetarpal Oct 4, 2024
e6cde54
Add GitHub job summary for inspecting built wheels
agriyakhetarpal Oct 4, 2024
57118e8
Temporarily trigger on pull requests
agriyakhetarpal Oct 4, 2024
3018f12
Raise an error if no artifacts to upload
agriyakhetarpal Oct 4, 2024
cdfa62f
Temporarily allow triggering manually via fork
agriyakhetarpal Oct 4, 2024
cad440f
Temporarily disable commands
agriyakhetarpal Oct 4, 2024
1bbd3d2
Fix `pdm` invocation
agriyakhetarpal Oct 4, 2024
8340fa1
`pdm` is a build-time dependency, not a run-time one
agriyakhetarpal Oct 4, 2024
68b5352
Fix summary printing
agriyakhetarpal Oct 4, 2024
5f8a524
Clean up changes and add a sanity check
agriyakhetarpal Oct 4, 2024
aeb4bd6
Merge main
agriyakhetarpal Sep 12, 2025
843ca7c
Add new architectures
agriyakhetarpal Sep 12, 2025
6f65deb
Update descriptions
agriyakhetarpal Sep 12, 2025
75620c3
Fix permissions hierarchy
agriyakhetarpal Sep 12, 2025
6e0884a
Use uv to run script
agriyakhetarpal Sep 12, 2025
1e0e6ac
Guard against shell injection
agriyakhetarpal Sep 12, 2025
c4d4df1
Bump GitHub Actions dependencies
agriyakhetarpal Sep 12, 2025
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
123 changes: 123 additions & 0 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
name: CD

on:
workflow_dispatch:
inputs:
version:
description: "The version to build Zig wheels for, use 'latest' for latest release, 'master' for nightly builds"
required: true
default: "latest"
suffix:
description: >
Suffix to append to the version in the wheel filename, i.e., for dev versions and version specifiers
required: false
default: ""
platforms:
description: >
Comma-separated values of platforms to build wheels for
required: false
default: "x86_64-windows,aarch64-windows,x86-windows,x86_64-macos,aarch64-macos,i386-linux,x86-linux,x86_64-linux,aarch64-linux,armv7a-linux,arm-linux,powerpc64le-linux,s390x-linux,riscv64-linux"
push_to_pypi:
description: >
Whether to push the built wheels to PyPI. Can be 'true' or 'false', defaults to 'false'.
required: true
default: "false"

permissions: {}

jobs:
build_wheels:
name: Build wheels
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
with:
persist-credentials: false
- uses: actions/setup-python@e797f83bcb11b83ae66e0230d6156d7c80228e7c # v6.0.0
with:
python-version: "3.x"

- uses: astral-sh/setup-uv@557e51de59eb14aaaba2ed9621916900a91d50c6 # v6.6.1

- name: Build wheels for all requested platforms
shell: bash
env:
GITHUB_EVENT_INPUTS_PLATFORMS: ${{ github.event.inputs.platforms }}
GITHUB_EVENT_INPUTS_VERSION: ${{ github.event.inputs.version }}
GITHUB_EVENT_INPUTS_SUFFIX: ${{ github.event.inputs.suffix }}
run: |
platforms=${GITHUB_EVENT_INPUTS_PLATFORMS}
IFS=',' read -r -a platform_array <<< "$platforms"
for platform in "${platform_array[@]}"; do
uv run make_wheels.py \
--outdir dist/ \
--version ${GITHUB_EVENT_INPUTS_VERSION} \
--suffix ${GITHUB_EVENT_INPUTS_SUFFIX} \
--platform "$platform"
done

- name: Upload wheel artifacts
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
with:
name: zig_wheels
path: dist/*.whl
if-no-files-found: error

deploy_wheels:
name: Deploy wheels
needs: [build_wheels]
if: >-
github.event.inputs.push_to_pypi == 'true' &&
github.repository == 'ziglang/zig-pypi'
environment: pypi
runs-on: ubuntu-latest
permissions:
id-token: write # for OIDC trusted publishing
attestations: write # for the GitHub Actions Attestations feature
contents: read
steps:
- name: Download all wheel artifacts
uses: actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0 # v5.0.0
with:
path: dist/
merge-multiple: true

- name: Sanity check wheel artifacts
run: ls -R dist/

- name: Generate artifact attestations
uses: actions/attest-build-provenance@977bb373ede98d70efdf65b84cb5f73e068dcc2a # v3.0.0
with:
subject-path: dist/*

# This will publish the list of wheels inputted to the action to PyPI (set to
# off, by default).
# The workflow may be triggered multiple times with the `push_to_pypi` input
# set to 'true' to publish the wheels for any configurable version (non-dev).
- name: Publish wheels to PyPI
uses: pypa/gh-action-pypi-publish@ed0c53931b1dc9bd32cbe73a98c7f6766f8a527e # v1.13.0
with:
packages-dir: dist/

inspect_wheels:
name: Inspect wheels
needs: [build_wheels]
runs-on: ubuntu-latest
steps:
- name: Download all built wheel artifacts
uses: actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0 # v5.0.0
with:
path: dist/
merge-multiple: true

- name: Inspect wheel artifacts
shell: bash
run: |
echo -e '## A list of built wheels and their SHA-256 checksums \n' >> $GITHUB_STEP_SUMMARY
echo -e '```\n' >> $GITHUB_STEP_SUMMARY
for wheel in dist/*.whl; do
shasum --algorithm 256 "$wheel" >> $GITHUB_STEP_SUMMARY
done
echo -e '```\n' >> $GITHUB_STEP_SUMMARY
25 changes: 18 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,27 @@ The process of converting release archives to binary wheels is deterministic, an

[pypidl]: https://pypi.org/project/ziglang/#files

Uploading wheels
----------------
Uploading wheels to PyPI
------------------------

Run the publishing utility:
Trigger the publishing workflow from this repository manually (requires authorization)
with the necessary inputs as mentioned in the [workflow file](.github/workflows/cd.yml)
or in the GitHub Actions UI. The wheels are checked with `twine` before they are uploaded.

```shell
pdm run twine dist/*
```
The workflow will upload the wheels to PyPI to make them available for installation. It
is possible to trigger it multiple times to upload wheels for different versions or
platforms.

Verifying the provenance of wheels uploaded to PyPI
---------------------------------------------------

To establish build provenance, the workflow generates attestations for the uploaded wheels
using the [GitHub Actions Attestations feature](https://docs.github.com/en/actions/security-for-github-actions/using-artifact-attestations/using-artifact-attestations-to-establish-provenance-for-builds)
when it is run. Please navigate to the [Attestations interface](https://github.com/ziglang/zig-pypi/attestations)
to view the attestations for the uploaded wheels.

This command will upload the binary wheels built in the previous step to PyPI.
The attestations may be verified via the [GitHub (`gh`) CLI](https://cli.github.com/manual/gh_attestation_verify)
or via the [GitHub API](https://docs.github.com/en/rest/users/attestations).

License
-------
Expand Down