Skip to content

Commit 7e0b1dd

Browse files
committed
Add GitHub Actions workflow
1 parent fe14ba1 commit 7e0b1dd

File tree

1 file changed

+150
-0
lines changed

1 file changed

+150
-0
lines changed
Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
name: Test, build, and release
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
tags:
8+
- 'v[0-9]*'
9+
pull_request:
10+
11+
concurrency:
12+
group: >
13+
${{ github.workflow }} @
14+
${{ github.event.pull_request.head.label || github.head_ref || github.ref }}
15+
cancel-in-progress: true
16+
17+
jobs:
18+
test:
19+
name: Run tests & typechecking
20+
runs-on: ubuntu-latest
21+
22+
steps:
23+
- uses: actions/checkout@v4
24+
- name: Set up uv
25+
uses: astral-sh/setup-uv@v3
26+
with:
27+
version: "0.4.x"
28+
enable-cache: true
29+
- name: Install package for testing
30+
run: uv sync
31+
- name: Run type checking
32+
run: uv run mypy src/ tests/
33+
- name: Run tests
34+
run: uv run pytest
35+
36+
# Adapted from:
37+
# https://packaging.python.org/en/latest/guides/publishing-package-distribution-releases-using-github-actions-ci-cd-workflows/
38+
build:
39+
name: Build distribution
40+
runs-on: ubuntu-latest
41+
42+
steps:
43+
- uses: actions/checkout@v4
44+
- name: Set up Python
45+
uses: actions/setup-python@v5
46+
with:
47+
python-version: "3.x"
48+
- name: Install pypa/build
49+
run: >-
50+
python3 -m
51+
pip install
52+
build
53+
--user
54+
- name: Build a binary wheel and a source tarball
55+
run: python3 -m build
56+
- name: Store the distribution packages
57+
uses: actions/upload-artifact@v4
58+
with:
59+
name: python-package-distributions
60+
path: dist/
61+
62+
github-release:
63+
name: >-
64+
Sign the Python distribution with Sigstore
65+
and upload them to GitHub Release
66+
needs:
67+
- publish-to-pypi
68+
runs-on: ubuntu-latest
69+
70+
permissions:
71+
contents: write # required for making GitHub Releases
72+
id-token: write # required for sigstore
73+
74+
steps:
75+
- name: Download all the dists
76+
uses: actions/download-artifact@v4
77+
with:
78+
name: python-package-distributions
79+
path: dist/
80+
- name: Sign the dists with Sigstore
81+
uses: sigstore/gh-action-sigstore-python@v2.1.1
82+
with:
83+
inputs: >-
84+
./dist/*.tar.gz
85+
./dist/*.whl
86+
- name: Create GitHub Release
87+
env:
88+
GITHUB_TOKEN: ${{ github.token }}
89+
run: >-
90+
gh release create
91+
'${{ github.ref_name }}'
92+
--repo '${{ github.repository }}'
93+
--notes ""
94+
- name: Upload artifact signatures to GitHub Release
95+
env:
96+
GITHUB_TOKEN: ${{ github.token }}
97+
# Upload to GitHub Release using the `gh` CLI.
98+
# `dist/` contains the built packages, and the
99+
# sigstore-produced signatures and certificates.
100+
run: >-
101+
gh release upload
102+
'${{ github.ref_name }}' dist/**
103+
--repo '${{ github.repository }}'
104+
105+
publish-to-testpypi:
106+
name: Publish Python distribution to TestPyPI
107+
needs:
108+
- build
109+
runs-on: ubuntu-latest
110+
111+
environment:
112+
name: testpypi
113+
url: https://test.pypi.org/p/tlaplus-state-graph-utils
114+
115+
permissions:
116+
id-token: write # required for trusted publishing
117+
118+
steps:
119+
- name: Download all the dists
120+
uses: actions/download-artifact@v4
121+
with:
122+
name: python-package-distributions
123+
path: dist/
124+
- name: Publish distribution 📦 to TestPyPI
125+
uses: pypa/gh-action-pypi-publish@release/v1
126+
with:
127+
repository-url: https://test.pypi.org/legacy/
128+
129+
publish-to-pypi:
130+
name: >-
131+
Publish Python distribution to PyPI
132+
# only publish to PyPI on tag pushes
133+
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
134+
needs:
135+
- build
136+
runs-on: ubuntu-latest
137+
environment:
138+
name: pypi
139+
url: https://pypi.org/p/tlaplus-state-graph-utils
140+
permissions:
141+
id-token: write # required for trusted publishing
142+
143+
steps:
144+
- name: Download all the dists
145+
uses: actions/download-artifact@v4
146+
with:
147+
name: python-package-distributions
148+
path: dist/
149+
- name: Publish distribution to PyPI
150+
uses: pypa/gh-action-pypi-publish@release/v1

0 commit comments

Comments
 (0)