Skip to content

Commit 9c24e8c

Browse files
authored
ci: use nix for workflows (amperser#1416)
1 parent 616e855 commit 9c24e8c

File tree

7 files changed

+525
-88
lines changed

7 files changed

+525
-88
lines changed

.github/workflows/cd-publish.yml

Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
name: "CD: Build & Publish"
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
version:
7+
description: "Version"
8+
required: true
9+
type: string
10+
prerelease:
11+
description: "Mark as prerelease"
12+
required: false
13+
default: false
14+
type: boolean
15+
16+
jobs:
17+
version:
18+
name: Bump Version & Tag
19+
runs-on: ubuntu-latest
20+
permissions:
21+
contents: write
22+
steps:
23+
- name: "[INIT] Checkout"
24+
uses: actions/checkout@v5
25+
with:
26+
fetch-depth: 0
27+
28+
- name: "[INIT] Git Config"
29+
run: |
30+
git config user.name "github-actions[bot]"
31+
git config user.email "github-actions[bot]@users.noreply.github.com"
32+
33+
- name: "[INIT] Install Nix"
34+
uses: cachix/install-nix-action@v31
35+
with:
36+
nix_path: nixpkgs=channel:nixos-unstable
37+
38+
- name: "[INIT] Setup Cachix"
39+
uses: cachix/cachix-action@v15
40+
with:
41+
name: amperser
42+
authToken: ${{ secrets.CACHIX_AUTH_TOKEN }}
43+
44+
45+
- name: "[VERSION] Bump & Commit"
46+
run: |
47+
nix develop --command uv version ${{ github.event.inputs.version }}
48+
nix develop --command git-cliff -c cliff.toml \
49+
--tag v${{ github.event.inputs.version }} \
50+
-o CHANGELOG.md
51+
52+
git commit -am "chore: prepare release v${{ github.event.inputs.version }}" || echo "no changes to commit"
53+
54+
- name: "[GIT] Create tag"
55+
run: |
56+
git tag v${{ github.event.inputs.version }}
57+
git push origin HEAD --tags
58+
59+
build:
60+
name: Build Artifacts
61+
runs-on: ubuntu-latest
62+
needs: [version]
63+
permissions:
64+
contents: read
65+
id-token: write
66+
attestations: write
67+
steps:
68+
- name: "[INIT] Checkout"
69+
uses: actions/checkout@v5
70+
with:
71+
fetch-depth: 0
72+
73+
- name: "[INIT] Install Nix"
74+
uses: cachix/install-nix-action@v31
75+
with:
76+
nix_path: nixpkgs=channel:nixos-unstable
77+
78+
- name: "[INIT] Setup Cachix"
79+
uses: cachix/cachix-action@v15
80+
with:
81+
name: amperser
82+
authToken: ${{ secrets.CACHIX_AUTH_TOKEN }}
83+
84+
- name: "[BUILD] Wheel"
85+
run: |
86+
mkdir -p dist
87+
nix build -L .#wheel
88+
cp result/*.whl dist/
89+
90+
91+
- name: "[BUILD] Source dist"
92+
run: |
93+
nix build -L .#sdist
94+
cp result/*.tar.gz dist/
95+
96+
- name: "[CHANGELOG] Generate release notes"
97+
run: |
98+
nix develop --command git-cliff -c cliff.toml \
99+
--unreleased --verbose \
100+
-o dist/RELEASE_NOTES.md
101+
102+
- name: "[VERIFY] Provenance"
103+
uses: actions/attest-build-provenance@v3
104+
with:
105+
subject-path: 'dist/*'
106+
107+
- name: "[UPLOAD] Artifacts"
108+
uses: actions/upload-artifact@v4
109+
with:
110+
name: dist-artifacts
111+
path: dist/
112+
if-no-files-found: error
113+
114+
github-release:
115+
name: GitHub Release
116+
runs-on: ubuntu-latest
117+
needs: [build]
118+
permissions:
119+
contents: write
120+
steps:
121+
- name: "[INIT] Checkout"
122+
uses: actions/checkout@v5
123+
with:
124+
fetch-depth: 0
125+
126+
- name: "[DOWNLOAD] Artifacts"
127+
uses: actions/download-artifact@v4
128+
with:
129+
name: dist-artifacts
130+
path: dist/
131+
132+
- name: "[INPUT] Get input"
133+
id: input
134+
run: |
135+
echo "tag=v${{ github.event.inputs.version }}" >> $GITHUB_OUTPUT
136+
echo "version=${{ github.event.inputs.version }}" >> $GITHUB_OUTPUT
137+
echo "prerelease=${{ github.event.inputs.prerelease }}" >> $GITHUB_OUTPUT
138+
139+
- name: "[RELEASE] Create GitHub release"
140+
uses: softprops/action-gh-release@v2
141+
with:
142+
name: Release ${{ steps.input.outputs.tag }}
143+
tag_name: ${{ steps.input.outputs.tag }}
144+
prerelease: ${{ steps.input.outputs.prerelease }}
145+
body_path: dist/RELEASE_NOTES.md
146+
files: dist/*
147+
148+
pypi-publish:
149+
name: Publish to PyPI
150+
runs-on: ubuntu-latest
151+
needs: [build]
152+
permissions:
153+
id-token: write
154+
steps:
155+
- name: "[DOWNLOAD] Artifacts"
156+
uses: actions/download-artifact@v4
157+
with:
158+
name: dist-artifacts
159+
path: dist/
160+
161+
- name: "[PUBLISH] PyPI"
162+
uses: pypa/gh-action-pypi-publish@release/v1

.github/workflows/cd-pypi.yml

Lines changed: 0 additions & 24 deletions
This file was deleted.

.github/workflows/ci-lint-test.yml

Lines changed: 51 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,82 @@
11
name: "CI: Lint & Test"
2+
23
on: [push, pull_request]
4+
35
jobs:
46
lint:
57
name: Lint
68
if: "!(contains(github.event.head_commit.message, '[skip_ci]'))"
79
runs-on: ubuntu-latest
8-
defaults:
9-
run:
10-
shell: bash
10+
1111
steps:
1212
- name: "[INIT] Checkout repository"
13-
uses: actions/checkout@v4
14-
- name: "[INIT] Install uv"
15-
uses: astral-sh/setup-uv@v5
13+
uses: actions/checkout@v5
14+
15+
- name: "[INIT] Install Nix"
16+
uses: cachix/install-nix-action@v31
1617
with:
17-
python-version: "3.10"
18-
enable-cache: true
19-
- name: "[INIT] Install dependencies"
20-
run: uv sync --locked --all-extras --dev
18+
nix_path: nixpkgs=channel:nixos-unstable
19+
20+
- name: "[INIT] Setup Cachix"
21+
uses: cachix/cachix-action@v15
22+
with:
23+
name: amperser
24+
authToken: ${{ secrets.CACHIX_AUTH_TOKEN }}
25+
2126
- name: "[EXEC] Lint"
22-
run: uv run poe lint
27+
run: nix develop --command ruff check proselint tests
28+
2329
test-cover:
2430
name: Test & Cover
2531
if: "!(contains(github.event.head_commit.message, '[skip_ci]'))"
2632
runs-on: ${{ matrix.os }}
2733
permissions:
2834
id-token: write
29-
defaults:
30-
run:
31-
shell: bash
3235
strategy:
3336
matrix:
3437
python: ["3.9", "3.10", "3.11", "3.12", "3.13"]
3538
os: [ubuntu-latest, macos-latest, windows-latest]
39+
3640
steps:
3741
- name: "[INIT] Checkout repository"
38-
uses: actions/checkout@v4
39-
- name: "[INIT] Install uv"
40-
uses: astral-sh/setup-uv@v5
42+
uses: actions/checkout@v5
43+
44+
- name: "[INIT] Install Nix (Unix)"
45+
if: runner.os != 'Windows'
46+
uses: cachix/install-nix-action@v31
47+
with:
48+
nix_path: nixpkgs=channel:nixos-unstable
49+
50+
- name: "[INIT] Setup Cachix (Unix)"
51+
if: runner.os != 'Windows'
52+
uses: cachix/cachix-action@v15
53+
with:
54+
name: amperser
55+
authToken: ${{ secrets.CACHIX_AUTH_TOKEN }}
56+
57+
- name: "[INIT] Install uv (Windows)"
58+
if: runner.os == 'Windows'
59+
uses: astral-sh/setup-uv@v6
4160
with:
4261
python-version: ${{ matrix.python }}
4362
enable-cache: true
44-
- name: "[INIT] Install dependencies"
63+
64+
- name: "[INIT] Install dependencies (Windows)"
65+
if: runner.os == 'Windows'
4566
run: uv sync --locked --all-extras --dev --group test
46-
- name: "[EXEC] Test"
67+
68+
- name: "[EXEC] Test & Coverage (Windows)"
69+
if: runner.os == 'Windows'
4770
run: uv run poe test-cover
71+
env:
72+
PYTHON_VERSION: ${{ matrix.python }}
73+
74+
- name: "[EXEC] Test & Coverage (Unix)"
75+
if: runner.os != 'Windows'
76+
run: nix develop --command uv run poe test-cover
77+
env:
78+
PYTHON_VERSION: ${{ matrix.python }}
79+
4880
- name: "[EXEC] Upload coverage to Codecov"
4981
uses: codecov/codecov-action@v5
5082
with:

.gitignore

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,36 @@
1+
# Nix
2+
.direnv/
3+
.envrc
4+
.result/
5+
.pre-commit-config.yaml
6+
7+
# Python
8+
*.egg
19
*.egg-info
210
*.pyc
3-
cached_func_calls/*
4-
profile_output
5-
site/write/*
6-
tests/corpus/newyorker/*
7-
cache/*
8-
proselint/cache/*
9-
build/*
10-
*.egg
11+
*.pstore
1112
*.rdb
13+
__pycache__/
14+
build/
15+
dist/
16+
cache/
17+
proselint/cache/
18+
cached_func_calls/*
19+
20+
# Coverage
1221
.coverage
1322
coverage.lcov
14-
proselint/proselint_develop.sublime-project
15-
proselint/proselint_develop.sublime-workspace
23+
profile_output
24+
25+
# Tests
26+
.hypothesis/
27+
tests/corpus/newyorker/*
28+
29+
# Corpora
1630
corpora/*
1731
!corpora/README.md
18-
dist/
19-
*.pstore
20-
.pre-commit-config.yaml
21-
.hypothesis
22-
.direnv/
23-
.envrc
32+
33+
# Editor
34+
proselint/proselint_develop.sublime-workspace
35+
.proselint/proselint_develop.sublime-project
36+
.site/write/*

0 commit comments

Comments
 (0)