Skip to content

Commit bcca18d

Browse files
committed
[libclang/python][ci] Add release Clang Python Bindings CI workflow
This migrates the CI workflow from https://github.com/trolldbois/python-clang/blob/master/.github/workflows/release.yml and adapts it to work within the structure of the LLVM monorepo. It builds upon the Python packaging files added in llvm#125806, and should be merged after that one. The CI workflow is set up to use two jobs: - the first just builds the package and saves it as an artifact and will work for testing in forks, PRs, and untagged commits - the second checks for release manager permissions and uses trusted publishing to upload the package to PyPI Signed-off-by: Ryan Mast <[email protected]>
1 parent 062d4d2 commit bcca18d

File tree

1 file changed

+112
-0
lines changed

1 file changed

+112
-0
lines changed
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
name: Release Clang Python Bindings
2+
3+
permissions:
4+
contents: read
5+
6+
on:
7+
push:
8+
branches:
9+
- main
10+
- release/*
11+
paths:
12+
- .github/workflows/release-clang-pypi.yml
13+
- 'clang/bindings/python/**'
14+
15+
pull_request:
16+
paths:
17+
- .github/workflows/release-clang-pypi.yml
18+
- 'clang/bindings/python/**'
19+
20+
workflow_dispatch:
21+
inputs:
22+
release-version:
23+
description: 'Release Version'
24+
required: false
25+
type: string
26+
27+
workflow_call:
28+
inputs:
29+
release-version:
30+
description: 'Release Version'
31+
required: true
32+
type: string
33+
secrets:
34+
RELEASE_TASKS_USER_TOKEN:
35+
description: "Secret used to check user permissions."
36+
required: false
37+
38+
jobs:
39+
build-release:
40+
if: github.repository_owner == 'llvm' || github.event_name == 'workflow_dispatch'
41+
runs-on: ubuntu-24.04
42+
steps:
43+
- name: Checkout LLVM (tagged release)
44+
if: inputs.release-version != ''
45+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
46+
with:
47+
ref: "llvmorg-${{ inputs.release-version }}"
48+
fetch-depth: 0
49+
sparse-checkout: clang/bindings/python/
50+
51+
- name: Checkout LLVM (latest commit)
52+
if: inputs.release-version == ''
53+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
54+
with:
55+
fetch-depth: 0
56+
sparse-checkout: clang/bindings/python/
57+
58+
- uses: actions/setup-python@e797f83bcb11b83ae66e0230d6156d7c80228e7c # v6.0.0
59+
with:
60+
python-version: '3.13'
61+
62+
- name: Package Clang Python Bindings
63+
working-directory: clang/bindings/python
64+
run: |
65+
pip install build twine
66+
python -m build
67+
python -m twine check dist/*
68+
69+
- name: Upload Clang Python Bindings package dist artifacts
70+
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
71+
with:
72+
name: python-package-dist
73+
path: clang/bindings/python/dist
74+
75+
pypi-publish:
76+
name: Upload release to PyPI
77+
runs-on: ubuntu-24.04
78+
needs: build-release
79+
# Only run this job in the main llvm repository when a release version is provided.
80+
#if: github.repository_owner == 'llvm' && inputs.release-version != ''
81+
if: inputs.release-version != ''
82+
environment:
83+
name: pypi
84+
url: https://pypi.org/p/clang
85+
permissions:
86+
id-token: write # IMPORTANT: this permission is mandatory for trusted publishing
87+
steps:
88+
- name: Checkout github-upload-release.py for permissions check
89+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
90+
with:
91+
sparse-checkout: llvm/utils/release/github-upload-release.py
92+
93+
- name: Install dependencies for github-upload-release.py
94+
run: |
95+
sudo apt-get update
96+
sudo apt-get install -y python3-github
97+
98+
- name: Check Permissions
99+
env:
100+
GITHUB_TOKEN: ${{ github.token }}
101+
USER_TOKEN: ${{ secrets.RELEASE_TASKS_USER_TOKEN }}
102+
run: |
103+
./llvm/utils/release/github-upload-release.py --token "$GITHUB_TOKEN" --user ${{ github.actor }} --user-token "$USER_TOKEN" check-permissions
104+
105+
- name: Download Python package dist artifacts
106+
uses: actions/download-artifact@018cc2cf5baa6db3ef3c5f8a56943fffe632ef53 # v6.0.0
107+
with:
108+
name: python-package-dist
109+
path: dist
110+
111+
- name: Publish package distributions to PyPI
112+
uses: pypa/gh-action-pypi-publish@ed0c53931b1dc9bd32cbe73a98c7f6766f8a527e # v1.13.0

0 commit comments

Comments
 (0)