Skip to content

Commit a7ea060

Browse files
committed
Add GitHub Actions workflow
1 parent fe14ba1 commit a7ea060

File tree

1 file changed

+170
-0
lines changed

1 file changed

+170
-0
lines changed
Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
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: Test
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 d2
30+
run: curl -fsSL https://d2lang.com/install.sh | sh -s --
31+
- name: Install package for testing
32+
run: uv sync --all-extras
33+
- name: Run tests
34+
run: uv run pytest
35+
36+
typecheck:
37+
name: Type check
38+
runs-on: ubuntu-latest
39+
40+
steps:
41+
- uses: actions/checkout@v4
42+
- name: Set up uv
43+
uses: astral-sh/setup-uv@v3
44+
with:
45+
version: "0.4.x"
46+
enable-cache: true
47+
- name: Install package for typechecking
48+
run: uv sync --all-extras
49+
- name: Run type checker
50+
run: uv run mypy src/ tests/
51+
52+
# Adapted from:
53+
# https://packaging.python.org/en/latest/guides/publishing-package-distribution-releases-using-github-actions-ci-cd-workflows/
54+
build:
55+
name: Build distribution
56+
runs-on: ubuntu-latest
57+
58+
steps:
59+
- uses: actions/checkout@v4
60+
- name: Set up Python
61+
uses: actions/setup-python@v5
62+
with:
63+
python-version: "3.x"
64+
- name: Install pypa/build
65+
run: >-
66+
python3 -m
67+
pip install
68+
build
69+
--user
70+
- name: Build a binary wheel and a source tarball
71+
run: python3 -m build
72+
- name: Store the distribution packages
73+
uses: actions/upload-artifact@v4
74+
with:
75+
name: python-package-distributions
76+
path: dist/
77+
78+
publish-to-testpypi:
79+
name: Publish Python distribution to TestPyPI
80+
needs:
81+
- build
82+
- test
83+
- typecheck
84+
runs-on: ubuntu-latest
85+
86+
environment:
87+
name: testpypi
88+
url: https://test.pypi.org/p/tlaplus-state-graph-utils
89+
90+
permissions:
91+
id-token: write # required for trusted publishing
92+
93+
steps:
94+
- name: Download all the dists
95+
uses: actions/download-artifact@v4
96+
with:
97+
name: python-package-distributions
98+
path: dist/
99+
- name: Publish distribution 📦 to TestPyPI
100+
uses: pypa/gh-action-pypi-publish@release/v1
101+
with:
102+
repository-url: https://test.pypi.org/legacy/
103+
104+
publish-to-pypi:
105+
name: >-
106+
Publish Python distribution to PyPI
107+
# only publish to PyPI on tag pushes
108+
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
109+
needs:
110+
- build
111+
- test
112+
- typecheck
113+
runs-on: ubuntu-latest
114+
environment:
115+
name: pypi
116+
url: https://pypi.org/p/tlaplus-state-graph-utils
117+
permissions:
118+
id-token: write # required for trusted publishing
119+
120+
steps:
121+
- name: Download all the dists
122+
uses: actions/download-artifact@v4
123+
with:
124+
name: python-package-distributions
125+
path: dist/
126+
- name: Publish distribution to PyPI
127+
uses: pypa/gh-action-pypi-publish@release/v1
128+
129+
github-release:
130+
name: >-
131+
Sign the Python distribution with Sigstore
132+
and upload them to GitHub Release
133+
needs:
134+
- publish-to-pypi
135+
runs-on: ubuntu-latest
136+
137+
permissions:
138+
contents: write # required for making GitHub Releases
139+
id-token: write # required for sigstore
140+
141+
steps:
142+
- name: Download all the dists
143+
uses: actions/download-artifact@v4
144+
with:
145+
name: python-package-distributions
146+
path: dist/
147+
- name: Sign the dists with Sigstore
148+
uses: sigstore/gh-action-sigstore-python@v2.1.1
149+
with:
150+
inputs: >-
151+
./dist/*.tar.gz
152+
./dist/*.whl
153+
- name: Create GitHub Release
154+
env:
155+
GITHUB_TOKEN: ${{ github.token }}
156+
run: >-
157+
gh release create
158+
'${{ github.ref_name }}'
159+
--repo '${{ github.repository }}'
160+
--notes ""
161+
- name: Upload artifact signatures to GitHub Release
162+
env:
163+
GITHUB_TOKEN: ${{ github.token }}
164+
# Upload to GitHub Release using the `gh` CLI.
165+
# `dist/` contains the built packages, and the
166+
# sigstore-produced signatures and certificates.
167+
run: >-
168+
gh release upload
169+
'${{ github.ref_name }}' dist/**
170+
--repo '${{ github.repository }}'

0 commit comments

Comments
 (0)