Skip to content

Commit 6b12cd3

Browse files
authored
Merge pull request #75 from AllenNeuralDynamics:fix-cicd
Ensure CICD releases tag the correct commit
2 parents 8997665 + e160124 commit 6b12cd3

File tree

1 file changed

+113
-15
lines changed

1 file changed

+113
-15
lines changed

.github/workflows/contraqctor.yml

Lines changed: 113 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,18 @@ name: contraqctor test suite
22

33
on:
44
workflow_dispatch:
5+
inputs:
6+
bump_type:
7+
description: "Version bump type"
8+
required: false
9+
default: "rc"
10+
type: choice
11+
options:
12+
- rc
13+
- patch
14+
- minor
15+
- major
16+
- stable
517
pull_request:
618
push:
719
branches:
@@ -102,9 +114,8 @@ jobs:
102114
103115
- name: Get version
104116
id: get_version
105-
shell: bash # interop with win/linux for if statement
106117
run: |
107-
version=$(uv version --output-format json | jq -r '.version')
118+
version=$(uv run uv version --short)
108119
echo "version=$version" >> $GITHUB_OUTPUT
109120
110121
- name: Create GitHub Release
@@ -128,13 +139,15 @@ jobs:
128139
# │ │
129140
# ╚─────────────────────────────────────────────────────────────────╝
130141

131-
github-public-release:
142+
prepare-public-release:
132143
runs-on: ubuntu-latest
133-
name: Create GitHub public release
144+
name: Prepare files for public release
134145
needs: tests
135-
if: github.event_name == 'release' &&
136-
github.event.action == 'published' &&
137-
!github.event.release.prerelease
146+
if: github.event_name == 'workflow_dispatch'
147+
outputs:
148+
version: ${{ steps.get_version.outputs.version }}
149+
is_prerelease: ${{ steps.check_prerelease.outputs.prerelease }}
150+
138151
steps:
139152
- uses: actions/checkout@v5
140153
with:
@@ -145,28 +158,113 @@ jobs:
145158
with:
146159
enable-cache: true
147160

148-
- name: Get release version from tag
161+
- name: Get target version
149162
id: get_version
150-
run: echo "version=${{ github.event.release.tag_name }}" >> $GITHUB_OUTPUT
163+
run: |
164+
# Use bump type from input (defaults to rc)
165+
bump_type="${{ github.event.inputs.bump_type || 'rc' }}"
166+
echo "Bumping version with type: $bump_type"
167+
168+
# Handle version bumping based on type
169+
if [[ "$bump_type" == "rc" ]]; then
170+
# Handle rc bumping logic (same as in github-rc-release)
171+
if uv version --bump rc --dry-run; then
172+
uv version --bump rc
173+
else
174+
uv version --bump rc --bump patch
175+
fi
176+
else
177+
# Handle patch, minor, major, stable
178+
uv version --bump $bump_type
179+
fi
151180
152-
- name: Validate version tag format
181+
release_version=$(uv run uv version --short)
182+
echo "version=$release_version" >> $GITHUB_OUTPUT
183+
echo "Release version will be: $release_version"
184+
185+
- name: Validate version format
153186
run: uv version ${{ steps.get_version.outputs.version }} --dry-run
154187

155188
- name: Update package version
156189
run: uv version ${{ steps.get_version.outputs.version }}
157190

158-
- name: Commit version
191+
- name: Commit version and create tag
159192
run: |
160193
git config --global user.name "github-actions[bot]"
161194
git config --global user.email "github-actions[bot]@users.noreply.github.com"
162195
git add .
163-
git commit -m "Set version [skip ci]" || echo "No changes to commit"
196+
git commit -m "Release v${{ steps.get_version.outputs.version }} [skip ci]"
197+
git tag -a "v${{ steps.get_version.outputs.version }}" -m "Release v${{ steps.get_version.outputs.version }}"
164198
git push origin main
199+
git push origin "v${{ steps.get_version.outputs.version }}"
200+
201+
- name: Determine if prerelease
202+
id: check_prerelease
203+
shell: bash
204+
run: |
205+
version="${{ steps.get_version.outputs.version }}"
206+
if [[ "$version" == *"rc"* ]]; then
207+
echo "prerelease=true" >> $GITHUB_OUTPUT
208+
else
209+
echo "prerelease=false" >> $GITHUB_OUTPUT
210+
fi
211+
212+
- name: Create GitHub Release
213+
uses: softprops/action-gh-release@v2
214+
env:
215+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
216+
with:
217+
tag_name: v${{ steps.get_version.outputs.version }}
218+
name: Release v${{ steps.get_version.outputs.version }}
219+
generate_release_notes: true
220+
prerelease: ${{ steps.check_prerelease.outputs.prerelease }}
221+
body: |
222+
Release v${{ steps.get_version.outputs.version }}
223+
224+
This release was manually triggered.
225+
226+
publish-to-pypi:
227+
runs-on: ubuntu-latest
228+
name: Publish to PyPI
229+
needs: [tests, prepare-public-release]
230+
if: |
231+
(github.event_name == 'workflow_dispatch') ||
232+
(github.event_name == 'release' &&
233+
github.event.action == 'published' &&
234+
!github.event.release.prerelease &&
235+
startsWith(github.ref, 'refs/tags/v'))
236+
steps:
237+
- uses: actions/checkout@v5
238+
with:
239+
fetch-depth: 0
240+
ref: ${{ github.event_name == 'workflow_dispatch' && 'main' || github.ref_name }}
241+
242+
- uses: astral-sh/setup-uv@v6
243+
with:
244+
enable-cache: true
245+
246+
- name: Verify version consistency (for automatic releases)
247+
if: github.event_name == 'release'
248+
shell: bash
249+
run: |
250+
tag_version=$(echo "${{ github.ref_name }}" | sed 's/^v//')
251+
package_version=$(uv run uv version --short)
252+
if [[ "$tag_version" != "$package_version" ]]; then
253+
echo "ERROR: Tag version ($tag_version) doesn't match package version ($package_version)"
254+
exit 1
255+
fi
256+
echo "✅ Version consistency verified: $tag_version"
257+
258+
- name: Get current version (for manual releases)
259+
if: github.event_name == 'workflow_dispatch'
260+
run: |
261+
package_version=$(uv run uv version --short)
262+
echo "📦 Publishing version: $package_version"
165263
166264
- name: Build
167265
run: uv build
168266

169-
- name: Publish
267+
- name: Publish to PyPI
170268
run: uv publish --token ${{ secrets.AIND_PYPI_TOKEN }}
171269

172270
# ╔─────────────────────────╗
@@ -180,8 +278,8 @@ jobs:
180278
build-docs:
181279
name: Build and deploy documentation to GitHub Pages
182280
runs-on: ubuntu-latest
183-
needs: github-public-release
184-
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
281+
needs: publish-to-pypi
282+
if: github.event_name == 'release' && !github.event.release.prerelease
185283
steps:
186284
- name: Checkout
187285
uses: actions/checkout@v5

0 commit comments

Comments
 (0)