11name : Build and Publish
2- # based on official doc
3- # https://packaging.python.org/en/latest/guides/publishing-package-distribution-releases-using-github-actions-ci-cd-workflows/
42
53on :
64 push :
7- tags :
8- - ' v*'
5+ tags : ["v*"]
96 workflow_dispatch :
107
11- jobs :
12- build :
13- name : Build
14- runs-on : ubuntu-22.04
8+ concurrency :
9+ group : publish-${{ github.ref }}
10+ cancel-in-progress : false
1511
16- steps :
12+ jobs :
13+ build :
14+ name : Build
15+ runs-on : ubuntu-22.04
16+ steps :
1717 - uses : actions/checkout@v4
18+ with :
19+ fetch-depth : 0
20+ fetch-tags : true
1821
1922 - name : Set up Python
2023 uses : actions/setup-python@v5
2124 with :
2225 python-version : " 3.x"
2326
24- - name : Install pypa/ build
25- run : python3 -m pip install build --user
27+ - name : Install build backend
28+ run : python -m pip install --upgrade pip build setuptools_scm
2629
27- - name : Build a binary wheel and a source tarball (agentlab)
28- run : python3 -m build . --outdir dist/
30+ - name : Build wheel and sdist
31+ run : python -m build . --outdir dist/
2932
3033 - name : Store the distribution packages
3134 uses : actions/upload-artifact@v4
3235 with :
3336 name : python-package-distributions
3437 path : dist/
3538
36- publish-to-pypi :
37- name : Publish to PyPI
38- needs :
39- - build
40- runs-on : ubuntu-22.04
41- environment : pypi
42- permissions :
43- id-token : write # IMPORTANT: mandatory for trusted publishing
44-
45- steps :
46- - name : Extract tag name
47- run : echo "TAG_NAME=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
48-
49- - name : Validate tag format
50- id : validate_tag
51- run : |
52- if [[ "${{ env.TAG_NAME }}" =~ ^v[0-9]+\.[0-9]+\.[0-9]+(\.dev[0-9]+)?$ ]]; then
53- echo "valid=true" >> $GITHUB_ENV
54- else
55- echo "valid=false" >> $GITHUB_ENV
56- fi
57-
58- - name : Exit if invalid tag
59- if : env.valid == 'false'
60- run : |
61- echo "The tag ${{ env.TAG_NAME }} is not a valid semantic version. Exiting."
62- exit 1
63-
64- - name : Download all the distribution packages
65- uses : actions/download-artifact@v4
66- with :
67- name : python-package-distributions
68- path : dist/
69-
70- - name : Publish all distribution packages to PyPI
71- uses : pypa/gh-action-pypi-publish@release/v1
72-
73- github-release :
74- name : Sign packages with Sigstore and upload them to GitHub Release
75- needs :
76- - publish-to-pypi
77- runs-on : ubuntu-22.04
78-
79- permissions :
80- contents : write # IMPORTANT: mandatory for making GitHub Releases
81- id-token : write # IMPORTANT: mandatory for sigstore
82-
83- steps :
84- - name : Download all the dists
85- uses : actions/download-artifact@v4
39+ publish-to-pypi :
40+ name : Publish to PyPI
41+ # Only run for “clean / stable” tags (no dev/rc/alpha/beta)
42+ if : ${{ !(contains(github.ref_name, 'dev') || contains(github.ref_name, 'rc') || contains(github.ref_name, 'alpha') || contains(github.ref_name, 'beta')) }}
43+ needs : [build]
44+ runs-on : ubuntu-22.04
45+ environment : pypi
46+ permissions :
47+ id-token : write
48+ steps :
49+ - uses : actions/download-artifact@v4
50+ with :
51+ name : python-package-distributions
52+ path : dist/
53+ - uses : pypa/gh-action-pypi-publish@release/v1
54+ with :
55+ skip-existing : true
56+
57+ publish-to-testpypi :
58+ name : Publish to TestPyPI (dev / rc / alpha / beta)
59+ needs : [build]
60+ runs-on : ubuntu-22.04
61+ environment : testpypi
62+ permissions :
63+ id-token : write
64+ contents : read
65+ if : ${{ contains(github.ref_name, 'dev') || contains(github.ref_name, 'rc') || contains(github.ref_name, 'alpha') || contains(github.ref_name, 'beta') }}
66+ steps :
67+ - uses : actions/download-artifact@v4
68+ with :
69+ name : python-package-distributions
70+ path : dist/
71+ - uses : pypa/gh-action-pypi-publish@release/v1
72+ with :
73+ repository-url : https://test.pypi.org/legacy/
74+ skip-existing : true
75+
76+ github-release :
77+ name : Sign & Create GitHub Release
78+ needs : [publish-to-pypi]
79+ if : needs.publish-to-pypi.result == 'success'
80+ runs-on : ubuntu-22.04
81+ permissions :
82+ contents : write
83+ id-token : write
84+ steps :
85+ - uses : actions/download-artifact@v4
8686 with :
8787 name : python-package-distributions
8888 path : dist/
8989
90- - name : Set up Python for Sigstore
91- uses : actions/setup-python@v5
90+ - uses : actions/setup-python@v5
9291 with :
9392 python-version : " 3.x"
9493
95- - name : Install Sigstore and cryptography dependencies
94+ - name : Install Sigstore dependencies
9695 run : |
97- python3 -m pip install --upgrade pip
98- python3 -m pip install cryptography==43.0.3
96+ python -m pip install --upgrade pip
97+ python -m pip install cryptography==43.0.3
9998
100- - name : Sign the dists with Sigstore
99+ - name : Sign dists with Sigstore
101100102101 with :
103- inputs : >-
102+ inputs : |
104103 ./dist/*.tar.gz
105104 ./dist/*.whl
106105
107106 - name : Create GitHub Release
108107 env :
109108 GITHUB_TOKEN : ${{ github.token }}
110- run : >-
111- gh release create
112- '${{ github.ref_name }}'
113- --repo '${{ github.repository }}'
114- --notes ""
115-
116- - name : Upload artifact signatures to GitHub Release
117- env :
118- GITHUB_TOKEN : ${{ github.token }}
119- # Upload to GitHub Release using the `gh` CLI.
120- # `dist/` contains the built packages, and the
121- # sigstore-produced signatures and certificates.
122- run : >-
123- gh release upload
124- '${{ github.ref_name }}' dist/**
125- --repo '${{ github.repository }}'
126-
127- - name : Set GitHub Release as pre-release
128- if : contains(github.ref, '.dev') # only set tags vA.B.C.devD as pre-release
109+ run : |
110+ TAG_NAME="${{ github.ref_name }}"
111+ gh release create "$TAG_NAME" \
112+ --repo "${{ github.repository }}" \
113+ --title "AgentLab $TAG_NAME" \
114+ --generate-notes \
115+ --fail-on-no-commits
116+
117+ - name : Upload artifacts to Release
129118 env :
130119 GITHUB_TOKEN : ${{ github.token }}
131- run : >-
132- gh release edit
133- '${{ github.ref_name }}'
134- --repo '${{ github.repository }}'
135- --prerelease
136-
137- # publish-to-testpypi:
138- # name: Publish to TestPyPI
139- # needs:
140- # - build
141- # runs-on: ubuntu-latest
142- # environment: testpypi
143- # permissions:
144- # id-token: write # IMPORTANT: mandatory for trusted publishing
145-
146- # steps:
147- # - name: Download all the distribution packages
148- # uses: actions/download-artifact@v4
149- # with:
150- # name: python-package-distributions
151- # path: dist/
152-
153- # - name: Publish distribution packages to TestPyPI
154- # uses: pypa/gh-action-pypi-publish@release/v1
155- # with:
156- # repository-url: https://test.pypi.org/legacy/
120+ run : |
121+ gh release upload "${{ github.ref_name }}" dist/** --repo "${{ github.repository }}"
0 commit comments