-
Notifications
You must be signed in to change notification settings - Fork 0
170 lines (146 loc) Β· 5.41 KB
/
Copy pathrelease.yml
File metadata and controls
170 lines (146 loc) Β· 5.41 KB
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
name: Release CLI
# retrigger
on:
push:
branches:
- main
paths:
- "cli/**"
- ".github/workflows/release.yml"
workflow_dispatch: # dΓ©clenchement manuel possible
permissions:
contents: write # crΓ©er le tag + la GitHub Release
id-token: write # PyPI Trusted Publishing (OIDC β aucun secret requis)
jobs:
# ββ 1. Tests βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
test:
name: Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: actions/setup-python@v6
with:
python-version: "3.14.6"
- name: Install dependencies
run: pip install -r requirements-dev.txt cryptography
- name: Run tests
run: pytest tests/ -v
# ββ 2. Lire la version depuis pyproject.toml βββββββββββββββββββββββββββββββββ
version:
name: Read version
needs: test
runs-on: ubuntu-latest
outputs:
version: ${{ steps.read.outputs.version }}
tag: ${{ steps.read.outputs.tag }}
steps:
- uses: actions/checkout@v6
- name: Read version from pyproject.toml
id: read
run: |
VERSION=$(python3 -c "
import re
with open('cli/pyproject.toml') as f:
content = f.read()
match = re.search(r'^version\s*=\s*\"([^\"]+)\"', content, re.MULTILINE)
print(match.group(1))
")
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "tag=v$VERSION" >> $GITHUB_OUTPUT
- name: Check tag does not already exist
run: |
TAG="v${{ steps.read.outputs.version }}"
if git ls-remote --tags origin | grep -q "refs/tags/${TAG}$"; then
echo "Tag ${TAG} already exists β skipping release."
exit 1
fi
# ββ 3. Build wheel + sdist βββββββββββββββββββββββββββββββββββββββββββββββββββ
build:
name: Build
needs: version
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: actions/setup-python@v6
with:
python-version: "3.14.6"
- name: Build package
run: pip install build && python -m build cli/
- name: Upload dist artifacts
uses: actions/upload-artifact@v7
with:
name: dist
path: cli/dist/
# ββ 4. CrΓ©er le tag Git βββββββββββββββββββββββββββββββββββββββββββββββββββββββ
tag:
name: Create tag
needs: [version, build]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- name: Push tag
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git tag "${{ needs.version.outputs.tag }}"
git push origin "${{ needs.version.outputs.tag }}"
# ββ 5. Publish to PyPI βββββββββββββββββββββββββββββββββββββββββββββββββββββββ
publish-pypi:
name: Publish to PyPI
needs: [version, build, tag]
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/project/ghostbit-cli/
steps:
- name: Download dist artifacts
uses: actions/download-artifact@v8
with:
name: dist
path: cli/dist/
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
packages-dir: cli/dist/
# ββ 6. GitHub Release avec changelog βββββββββββββββββββββββββββββββββββββββββ
github-release:
name: GitHub Release
needs: [version, build, tag]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Download dist artifacts
uses: actions/download-artifact@v8
with:
name: dist
path: cli/dist/
- name: Build changelog
id: changelog
run: |
CURRENT_TAG="${{ needs.version.outputs.tag }}"
PREV_TAG=$(git tag --sort=-version:refname | grep -v "^${CURRENT_TAG}$" | head -1)
if [ -z "$PREV_TAG" ]; then
CHANGELOG=$(git log --pretty=format:"- %s" | head -20)
else
CHANGELOG=$(git log "${PREV_TAG}..HEAD" --pretty=format:"- %s")
fi
echo "changelog<<EOF" >> $GITHUB_OUTPUT
echo "$CHANGELOG" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: Create GitHub Release
uses: softprops/action-gh-release@v3
with:
tag_name: ${{ needs.version.outputs.tag }}
name: "${{ needs.version.outputs.tag }}"
body: |
## What's changed
${{ steps.changelog.outputs.changelog }}
## Install
```bash
pip install ghostbit==${{ needs.version.outputs.version }}
```
files: dist/*
draft: false
prerelease: ${{ contains(needs.version.outputs.version, '-') }}