-
Notifications
You must be signed in to change notification settings - Fork 0
144 lines (121 loc) · 3.61 KB
/
workflow.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
name: Deployment
on:
push:
branches:
- main
tags:
- "*"
pull_request:
branches:
- main
jobs:
test:
name: Run tests
strategy:
matrix:
os: [ubuntu-latest, macos-14]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install Nix
uses: cachix/install-nix-action@v30
with:
nix_path: nixpkgs=channel:nixpkgs-24.05-darwin
- name: Generate cache key
run: |
nixpkgs_hash=$(egrep -o 'archive/[0-9a-f]{40}\.tar\.gz' shell.nix | cut -d'/' -f2 | cut -d'.' -f1)
echo "CACHE_KEY=${{ runner.os }}-$nixpkgs_hash" >> $GITHUB_ENV
- name: Cache Nix store
uses: actions/cache@v4
id: nix-cache
with:
key: nix-${{ env.CACHE_KEY }}
path: /tmp/nix-cache
- name: Import Nix store cache
if: steps.nix-cache.outputs.cache-hit == 'true'
run: |
nix-store --import < /tmp/nix-cache
- name: Cache Python venv
uses: actions/cache@v4
with:
key: python-${{ env.CACHE_KEY }}-${{ hashFiles('poetry.lock') }}
path: .venv
- name: Assert tag name matches version
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
run: |
nix-shell --pure --run "poetry version --short > version.txt"
version=$(cat version.txt)
tag_name=${{ github.ref_name }}
if [ "$version" != "$tag_name" ]; then
echo "Tag name mismatch: $version != $tag_name"
exit 1
fi
- name: Run tests
run: |
nix-shell --pure --run "run-tests term"
- name: Build distribution
run: |
nix-shell --pure --run "poetry build"
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: dist-${{ runner.os }}
path: dist/
- name: Export Nix store cache
if: steps.nix-cache.outputs.cache-hit != 'true'
run: |
nix-store --export $(find /nix/store -maxdepth 1 -name '*-*') > /tmp/nix-cache
publish-pypi:
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
name: Publish to PyPI
needs: test
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/p/starlette-compress
permissions:
id-token: write
contents: read
steps:
- name: Download artifacts
uses: actions/download-artifact@v4
with:
name: dist-${{ runner.os }}
path: dist/
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
publish-gh:
name: Publish to GitHub Release
needs: publish-pypi
runs-on: ubuntu-latest
permissions:
id-token: write
contents: write
steps:
- name: Download artifacts
uses: actions/download-artifact@v4
with:
name: dist-${{ runner.os }}
path: dist/
- name: Sign with Sigstore
uses: sigstore/[email protected]
with:
inputs: >-
./dist/*.tar.gz
./dist/*.whl
- name: Create GitHub Release
env:
GITHUB_TOKEN: ${{ github.token }}
run: >-
gh release create
'${{ github.ref_name }}'
--repo '${{ github.repository }}'
--notes ""
- name: Upload signed artifacts
env:
GITHUB_TOKEN: ${{ github.token }}
run: >-
gh release upload
'${{ github.ref_name }}' dist/**
--repo '${{ github.repository }}'