-
Notifications
You must be signed in to change notification settings - Fork 0
197 lines (165 loc) · 6.51 KB
/
release.yml
File metadata and controls
197 lines (165 loc) · 6.51 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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
name: Create Release
on:
push:
branches:
- main
- Dev
permissions:
contents: write
jobs:
create-release:
runs-on: ubuntu-latest
outputs:
python_changed: ${{ steps.check-python-changes.outputs.python_changed }}
effective_version: ${{ steps.effective-version.outputs.effective_version }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0 # Required for GitVersion to work correctly
- name: Install GitVersion
uses: GitTools/actions/gitversion/setup@v0
with:
versionSpec: '5.x'
- name: Determine Version
id: gitversion
uses: GitTools/actions/gitversion/execute@v0
- name: Extract Release Notes from Changelog
id: extract-changelog
uses: release-flow/keep-a-changelog-action@v3.0.0
with:
command: query
version: unreleased
- name: Check for Python file changes
id: check-python-changes
run: |
git fetch origin main
CHANGED_FILES=$(git diff --name-only HEAD^ HEAD)
echo "Changed files: $CHANGED_FILES"
if echo "$CHANGED_FILES" | grep -E '\.py$'; then
echo "python_changed=true" >> $GITHUB_ENV
echo "::set-output name=python_changed::true"
else
echo "python_changed=false" >> $GITHUB_ENV
echo "::set-output name=python_changed::false"
fi
- name: Set Version Bump Type from GitVersion
id: version-bump
if: github.ref == 'refs/heads/main'
run: |
VERSION_INCREMENT="${{ steps.gitversion.outputs.MajorMinorPatch }}"
TAG="${{ steps.gitversion.outputs.PreReleaseLabel }}"
BUMP_TYPE="patch"
if [[ "${{ env.python_changed }}" == "true" ]]; then
if [[ "$VERSION_INCREMENT" =~ ^[1-9][0-9]*\.0\.0$ ]]; then
BUMP_TYPE="major"
elif [[ "$VERSION_INCREMENT" =~ ^[0-9]+\.[1-9][0-9]*\.0$ ]]; then
BUMP_TYPE="minor"
elif [[ "$VERSION_INCREMENT" =~ ^[0-9]+\.[0-9]+\.[1-9][0-9]*$ ]]; then
BUMP_TYPE="patch"
fi
if [[ -n "$TAG" ]]; then
BUMP_TYPE="pre${BUMP_TYPE}"
fi
else
echo "No Python files changed → forcing patch bump."
fi
echo "Version bump detected: $BUMP_TYPE"
echo "bump_type=$BUMP_TYPE" >> $GITHUB_ENV
- name: Determine Effective Version
id: effective-version
run: |
if [[ "${{ env.python_changed }}" == "true" ]]; then
EFFECTIVE_VERSION="${{ steps.gitversion.outputs.semVer }}"
else
PREV_TAG=$(git describe --tags --abbrev=0)
echo "Previous tag: $PREV_TAG"
MAJOR=$(echo $PREV_TAG | cut -d. -f1)
MINOR=$(echo $PREV_TAG | cut -d. -f2)
PATCH=$(echo $PREV_TAG | cut -d. -f3)
NEW_PATCH=$((PATCH + 1))
EFFECTIVE_VERSION="$MAJOR.$MINOR.$NEW_PATCH"
echo "Forcing patch bump: $EFFECTIVE_VERSION"
fi
echo "effective_version=$EFFECTIVE_VERSION" >> $GITHUB_ENV
echo "::set-output name=effective_version::$EFFECTIVE_VERSION"
- name: Update CHANGELOG.md
if: github.ref == 'refs/heads/main'
uses: release-flow/keep-a-changelog-action@v3.0.0
with:
command: bump
version: ${{ env.bump_type }}
- name: Commit Updated CHANGELOG.md
if: github.ref == 'refs/heads/main'
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: "Update CHANGELOG for release ${{ steps.effective-version.outputs.effective_version }}"
file_pattern: "CHANGELOG.md"
- uses: actions/setup-python@v5
with:
python-version: "3.x"
- name: Install Required Python Packages
run: pip install build tomlkit
- name: Update Version in pyproject.toml
run: |
python - <<EOF
import tomlkit
pyproject_file = "pyproject.toml"
with open(pyproject_file, "r", encoding="utf-8") as f:
data = tomlkit.load(f)
data["project"]["version"] = "${{ steps.effective-version.outputs.effective_version }}"
data["tool"]["poetry"]["version"] = "${{ steps.effective-version.outputs.effective_version }}"
with open(pyproject_file, "w", encoding="utf-8") as f:
tomlkit.dump(data, f)
EOF
- name: Commit Updated pyproject.toml
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: "Update pyproject.toml for release ${{ steps.effective-version.outputs.effective_version }}"
file_pattern: "pyproject.toml"
- name: Build release distributions
if: env.python_changed == 'true'
run: |
python -m pip install build
python -m build
- name: Create Git Tag
run: |
git tag ${{ steps.effective-version.outputs.effective_version }}
git push origin ${{ steps.effective-version.outputs.effective_version }}
- name: Create GitHub Release
if: env.python_changed == 'true'
uses: softprops/action-gh-release@v1
with:
tag_name: v${{ steps.effective-version.outputs.effective_version }}
name: Release v${{ steps.effective-version.outputs.effective_version }}
body: "${{ steps.extract-changelog.outputs.release-notes }}"
draft: false
prerelease: ${{ github.ref == 'refs/heads/Dev' }}
files: |
dist/*.whl
dist/*.tar.gz
- name: Upload distributions
if: env.python_changed == 'true'
uses: actions/upload-artifact@v4
with:
name: release-dists
path: dist/
pypi-publish:
runs-on: ubuntu-latest
needs:
- create-release
if: github.ref == 'refs/heads/main' && needs.create-release.outputs.python_changed == 'true'
permissions:
id-token: write
environment:
name: pypi
steps:
- name: Retrieve release distributions
uses: actions/download-artifact@v4
with:
name: release-dists
path: dist/
- name: Publish release distributions to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
packages-dir: dist/