-
Notifications
You must be signed in to change notification settings - Fork 10
188 lines (159 loc) · 5.59 KB
/
Copy pathversion-and-build.yml
File metadata and controls
188 lines (159 loc) · 5.59 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
name: Version and Build
on:
push:
branches: [develop, main, 'release/**', 'hotfix/**', 'feature/**', 'issue/**', 'issues/**', 'docs/**']
workflow_dispatch:
env:
PYTHON_VERSION: "3.10"
jobs:
# First run tests
run_tests:
uses: ./.github/workflows/run_tests.yml
secrets:
codecov_token: ${{ secrets.CODECOV_TOKEN }}
# Main build job
build:
needs: run_tests
runs-on: ubuntu-latest
permissions:
contents: write
packages: write
steps:
- name: Checkout
uses: actions/checkout@v5
with:
fetch-depth: 0 # Need history for auto-bump script
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Set up uv
uses: astral-sh/setup-uv@v5
with:
enable-cache: true
- name: Install bump-my-version
run: uv pip install --system bump-my-version
- name: Configure git
run: |
git config user.name "ncompare-bot"
git config user.email "ncompare@noreply.github.com"
- name: Bump version
id: version
run: |
BRANCH="${GITHUB_REF#refs/heads/}"
echo "Processing branch: $BRANCH"
case "$BRANCH" in
develop)
echo "📦 Bumping develop alpha"
bump-my-version bump pre_number
VENUE=sit
PUBLISH=true
;;
release/*)
echo "🎯 Bumping release"
CURRENT=$(bump-my-version show current_version)
if [[ "$CURRENT" == *"a"* ]]; then
echo " First release push: Alpha → RC1"
bump-my-version bump pre_label
# Auto-bump develop to next minor
echo ""
RELEASE_VERSION="${BRANCH#release/}"
bash scripts/bump_develop_after_release.sh "$RELEASE_VERSION"
echo ""
# Return to release branch
git checkout "$BRANCH"
else
echo " Incrementing RC"
bump-my-version bump pre_number
fi
VENUE=uat
PUBLISH=true
;;
main)
echo "🎉 Stripping to final release"
bump-my-version bump pre_label
VENUE=ops
PUBLISH=true
TAG=true
;;
hotfix/*)
echo "🔧 Bumping hotfix patch"
CURRENT=$(bump-my-version show current_version)
if [[ "$CURRENT" == *"rc"* ]] || [[ "$CURRENT" == *"a"* ]]; then
echo " Stripping pre-release label first"
bump-my-version bump pre_label
fi
bump-my-version bump patch
VENUE=ops
PUBLISH=true
;;
feature/*|issue/*|issues/*|docs/*)
echo "🌟 Feature branch: adding local identifier"
CURRENT=$(bump-my-version show current_version)
LOCAL_ID="+$(git rev-parse --short ${GITHUB_SHA})"
VERSION="${CURRENT}${LOCAL_ID}"
VENUE=dev
PUBLISH=false
;;
*)
echo "⏭️ Unknown branch, no version bump"
CURRENT=$(bump-my-version show current_version)
VERSION="$CURRENT"
VENUE=dev
PUBLISH=false
;;
esac
# Set VERSION if not already set (for feature branches)
if [ -z "$VERSION" ]; then
VERSION=$(bump-my-version show current_version)
fi
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "venue=$VENUE" >> $GITHUB_OUTPUT
echo "publish=$PUBLISH" >> $GITHUB_OUTPUT
echo "tag=${TAG:-false}" >> $GITHUB_OUTPUT
echo ""
echo "📌 Version: $VERSION"
echo "🎯 Venue: $VENUE"
- name: Commit version bump
if: |
github.ref == 'refs/heads/develop' ||
github.ref == 'refs/heads/main' ||
startsWith(github.ref, 'refs/heads/release/') ||
startsWith(github.ref, 'refs/heads/hotfix/')
run: |
if [[ -n $(git status -s) ]]; then
git commit -am "Bump version to ${{ steps.version.outputs.version }} [skip ci]"
git push
echo "✅ Version bumped and committed"
else
echo "ℹ️ No version changes to commit"
fi
- name: Create Git tag
if: |
github.ref == 'refs/heads/develop' ||
github.ref == 'refs/heads/main' ||
startsWith(github.ref, 'refs/heads/release/')
run: |
VERSION="${{ steps.version.outputs.version }}"
git tag -a "$VERSION" -m "Version $VERSION"
git push origin "$VERSION"
echo "✅ Tagged $VERSION"
- name: Install dependencies
run: uv sync --extra dev --frozen
- name: Build package
run: uv build
- name: Upload Python artifact
uses: actions/upload-artifact@v5
with:
name: python-artifact
path: dist/*
- name: Publish to Test PyPI
if: steps.version.outputs.publish == 'true' && steps.version.outputs.venue == 'uat'
env:
UV_PUBLISH_TOKEN: ${{ secrets.PYPI_TOKEN_TESTPYPI }}
run: uv publish --publish-url https://test.pypi.org/legacy/
- name: Publish to PyPI
if: steps.version.outputs.publish == 'true' && steps.version.outputs.venue == 'ops'
env:
UV_PUBLISH_TOKEN: ${{ secrets.PYPI_TOKEN_PYPI }}
run: uv publish