-
Notifications
You must be signed in to change notification settings - Fork 0
143 lines (123 loc) · 4.19 KB
/
release.yml
File metadata and controls
143 lines (123 loc) · 4.19 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
name: Build and Release
on:
push:
branches: [ main, master ]
paths:
- 'pyproject.toml'
permissions:
contents: write
id-token: write
packages: write
jobs:
format-lint:
name: "Format and Lint"
uses: ./.github/workflows/_format-lint-action.yml
test:
name: "Run Tests"
needs: format-lint
uses: ./.github/workflows/_run-tests-action.yml
check-version-changed:
name: "Check if version changed"
runs-on: ubuntu-latest
outputs:
version: ${{ steps.version.outputs.version }}
version-changed: ${{ steps.check.outputs.changed }}
is-prerelease: ${{ steps.version.outputs.is-prerelease }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 2
- name: Get current version
id: version
run: |
VERSION=$(grep '^version = ' pyproject.toml | sed 's/version = "\(.*\)"/\1/')
echo "version=$VERSION" >> $GITHUB_OUTPUT
# Check if version contains letters (indicating pre-release)
if echo "$VERSION" | grep -q '[a-zA-Z]'; then
echo "is-prerelease=true" >> $GITHUB_OUTPUT
echo "Detected pre-release version: $VERSION"
else
echo "is-prerelease=false" >> $GITHUB_OUTPUT
echo "Detected stable release version: $VERSION"
fi
- name: Check if version changed
id: check
run: |
if git diff HEAD~1 HEAD --name-only | grep -q pyproject.toml; then
if git diff HEAD~1 HEAD pyproject.toml | grep -q '^+version = '; then
echo "changed=true" >> $GITHUB_OUTPUT
echo "Version changed in pyproject.toml"
else
echo "changed=false" >> $GITHUB_OUTPUT
echo "pyproject.toml changed but version did not change"
fi
else
echo "changed=false" >> $GITHUB_OUTPUT
echo "pyproject.toml was not changed"
fi
build:
name: "Build Docker Image"
needs: [format-lint, test, check-version-changed]
secrets: inherit
uses: ./.github/workflows/_build-docker-action.yml
if: needs.check-version-changed.outputs.version-changed == 'true'
with:
version: ${{ needs.check-version-changed.outputs.version }}
build-package:
name: "Build Python Package"
runs-on: ubuntu-latest
needs: [build, check-version-changed]
if: needs.check-version-changed.outputs.version-changed == 'true'
steps:
- uses: actions/checkout@v4
- name: Install uv
uses: astral-sh/setup-uv@v4
with:
enable-cache: true
- name: Set up Python
run: uv python install 3.10
- name: Build package
run: uv build
- name: Upload build artifacts
uses: actions/upload-artifact@v4
with:
name: dist
path: dist/
publish-pypi:
name: "Publish to PyPI"
runs-on: ubuntu-latest
needs: [build-package, check-version-changed]
if: needs.check-version-changed.outputs.version-changed == 'true'
environment: release
steps:
- name: Download build artifacts
uses: actions/download-artifact@v4
with:
name: dist
path: dist/
- name: Install uv
uses: astral-sh/setup-uv@v4
- name: Publish to PyPI
run: uv publish --token ${{ secrets.PYPI_API_TOKEN }}
working-directory: .
create-release:
name: "Create GitHub Release"
runs-on: ubuntu-latest
needs: [publish-pypi, check-version-changed]
if: needs.check-version-changed.outputs.version-changed == 'true'
steps:
- uses: actions/checkout@v4
- name: Download build artifacts
uses: actions/download-artifact@v4
with:
name: dist
path: dist/
- name: Create Release
uses: softprops/action-gh-release@v2
with:
tag_name: v${{ needs.check-version-changed.outputs.version }}
name: Release v${{ needs.check-version-changed.outputs.version }}
draft: false
prerelease: ${{ needs.check-version-changed.outputs.is-prerelease == 'true' }}
generate_release_notes: true
files: dist/*