Skip to content

Commit 6bc82cd

Browse files
Merge pull request #333 from nasa/feature/issue-311-pypi-on-release-publishing
Feature/issue 311 pypi on release publishing
2 parents 00c0eb4 + 0ac61a2 commit 6bc82cd

7 files changed

Lines changed: 149 additions & 120 deletions

File tree

.github/workflows/publish.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: Publish on Release
2+
3+
on:
4+
release:
5+
types: [published] # This ensures the workflow runs only after a release is finalized
6+
7+
env:
8+
PYTHON_VERSION: "3.11"
9+
10+
jobs:
11+
build-and-publish:
12+
environment: pypi
13+
permissions:
14+
id-token: write
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: Checkout code
18+
uses: actions/checkout@v6
19+
with:
20+
fetch-depth: 0 # Fetch all history for accurate versioning/changelogs
21+
22+
- name: Set up Python
23+
uses: actions/setup-python@v6
24+
with:
25+
python-version: ${{ env.PYTHON_VERSION }}
26+
27+
- name: Set up uv
28+
uses: astral-sh/setup-uv@v7
29+
with:
30+
enable-cache: true
31+
32+
- name: Verify version matches git tag
33+
run: scripts/verify_tag.sh
34+
35+
- name: Install dependencies
36+
run: uv sync --no-dev --frozen
37+
38+
- name: Build package
39+
run: uv build
40+
41+
- name: Publish to PyPI
42+
run: uv publish

.github/workflows/run_tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ on:
2020

2121
jobs:
2222
build_and_test:
23-
runs-on: ubuntu-22.04
23+
runs-on: ubuntu-latest
2424
strategy:
2525
matrix:
2626
python-version: [ '3.11', '3.12', '3.13', '3.14' ]

.github/workflows/version-and-build.yml

Lines changed: 16 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: Version and Build
22

33
on:
44
push:
5-
branches: [develop, main, 'release/**', 'hotfix/**', 'feature/**', 'issue/**', 'issues/**', 'docs/**']
5+
branches: [develop, main, 'release/**', 'hotfix/**', 'feature/**', 'issue/**', 'docs/**']
66
workflow_dispatch:
77

88
env:
@@ -20,10 +20,10 @@ jobs:
2020
# Main build job
2121
build:
2222
needs: run_tests
23-
runs-on: ubuntu-22.04
23+
runs-on: ubuntu-latest
2424
permissions:
2525
contents: write
26-
packages: write
26+
id-token: write
2727

2828
steps:
2929
- name: Checkout
@@ -53,120 +53,30 @@ jobs:
5353
id: version
5454
run: |
5555
BRANCH="${GITHUB_REF#refs/heads/}"
56-
echo "Processing branch: $BRANCH"
57-
58-
case "$BRANCH" in
59-
develop)
60-
echo "📦 Bumping develop alpha"
61-
bump-my-version bump pre_number
62-
VENUE=sit
63-
PUBLISH=true
64-
;;
65-
66-
release/*)
67-
echo "🎯 Bumping release"
68-
CURRENT=$(bump-my-version show current_version)
69-
70-
if [[ "$CURRENT" == *"a"* ]]; then
71-
echo " First release push: Alpha → RC1"
72-
bump-my-version bump pre_label
73-
74-
# Commit the release branch bump before switching branches
75-
git commit -am "Bump to RC1 [skip ci]"
76-
git push
77-
78-
# Auto-bump develop to next minor
79-
echo ""
80-
RELEASE_VERSION="${BRANCH#release/}"
81-
bash scripts/bump_develop_after_release.sh "$RELEASE_VERSION"
82-
echo ""
83-
84-
# Return to release branch
85-
git checkout "$BRANCH"
86-
else
87-
echo " Incrementing RC"
88-
bump-my-version bump pre_number
89-
fi
90-
91-
VENUE=uat
92-
PUBLISH=true
93-
;;
94-
95-
main)
96-
echo "🎉 Stripping to final release"
97-
bump-my-version bump pre_label
98-
VENUE=ops
99-
PUBLISH=true
100-
TAG=true
101-
;;
102-
103-
hotfix/*)
104-
echo "🔧 Bumping hotfix patch"
105-
CURRENT=$(bump-my-version show current_version)
106-
if [[ "$CURRENT" == *"rc"* ]] || [[ "$CURRENT" == *"a"* ]]; then
107-
echo " Stripping pre-release label first"
108-
bump-my-version bump pre_label
109-
fi
110-
bump-my-version bump patch
111-
VENUE=ops
112-
PUBLISH=true
113-
;;
114-
115-
feature/*|issue/*|issues/*|docs/*)
116-
echo "🌟 Feature branch: adding local identifier"
117-
CURRENT=$(bump-my-version show current_version)
118-
LOCAL_ID="+$(git rev-parse --short ${GITHUB_SHA})"
119-
VERSION="${CURRENT}${LOCAL_ID}"
120-
VENUE=dev
121-
PUBLISH=false
122-
;;
123-
124-
*)
125-
echo "⏭️ Unknown branch, no version bump"
126-
CURRENT=$(bump-my-version show current_version)
127-
VERSION="$CURRENT"
128-
VENUE=dev
129-
PUBLISH=false
130-
;;
131-
esac
132-
133-
# Set VERSION if not already set (for feature branches)
134-
if [ -z "$VERSION" ]; then
135-
VERSION=$(bump-my-version show current_version)
136-
fi
137-
echo "version=$VERSION" >> $GITHUB_OUTPUT
138-
echo "venue=$VENUE" >> $GITHUB_OUTPUT
139-
echo "publish=$PUBLISH" >> $GITHUB_OUTPUT
140-
echo "tag=${TAG:-false}" >> $GITHUB_OUTPUT
141-
142-
echo ""
143-
echo "📌 Version: $VERSION"
144-
echo "🎯 Venue: $VENUE"
56+
bash scripts/version_bump.sh "$BRANCH"
14557
14658
- name: Commit version bump
14759
if: |
148-
github.ref == 'refs/heads/develop' ||
149-
github.ref == 'refs/heads/main' ||
150-
startsWith(github.ref, 'refs/heads/release/') ||
151-
startsWith(github.ref, 'refs/heads/hotfix/')
60+
steps.version.outputs.already_committed == 'false' && (
61+
github.ref == 'refs/heads/develop' ||
62+
github.ref == 'refs/heads/main' ||
63+
startsWith(github.ref, 'refs/heads/release/') ||
64+
startsWith(github.ref, 'refs/heads/hotfix/')
65+
)
15266
run: |
153-
# Check if there are uncommitted changes
15467
if [[ -n $(git status -s) ]]; then
15568
git commit -am "Bump version to ${{ steps.version.outputs.version }} [skip ci]"
69+
git push || {
70+
echo "❌ Failed to push to remote"
71+
exit 1
72+
}
15673
echo "✅ Version bumped and committed"
15774
else
15875
echo "ℹ️ No version changes to commit"
15976
fi
160-
161-
# Push (whether we just committed or committed earlier)
162-
git push
163-
echo "✅ Pushed to remote"
16477
16578
- name: Create Git tag
166-
if: |
167-
github.ref == 'refs/heads/develop' ||
168-
github.ref == 'refs/heads/main' ||
169-
startsWith(github.ref, 'refs/heads/release/')
79+
if: github.ref == 'refs/heads/main'
17080
run: |
17181
VERSION="${{ steps.version.outputs.version }}"
17282
git tag -a "$VERSION" -m "Version $VERSION"
@@ -186,13 +96,5 @@ jobs:
18696
path: dist/*
18797

18898
- name: Publish to Test PyPI
189-
if: steps.version.outputs.publish == 'true' && steps.version.outputs.venue == 'uat'
190-
env:
191-
UV_PUBLISH_TOKEN: ${{ secrets.PYPI_TOKEN_TESTPYPI }}
99+
if: steps.version.outputs.publish == 'true'
192100
run: uv publish --publish-url https://test.pypi.org/legacy/
193-
194-
- name: Publish to PyPI
195-
if: steps.version.outputs.publish == 'true' && steps.version.outputs.venue == 'ops'
196-
env:
197-
UV_PUBLISH_TOKEN: ${{ secrets.PYPI_TOKEN_PYPI }}
198-
run: uv publish

CHANGELOG.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## [1.14.0] - 2025-12-30
88

9+
_Updates base Python version from 3.9 to 3.11._
10+
911
### Changed
1012

11-
- update the default python version from 3.9 to 3.10 ([#323](https://github.com/nasa/stitchee/pull/323))([**@danielfromearth**](https://github.com/danielfromearth))
12-
- Implement uv dependency management and versioning with bump-my-version ([#325](https://github.com/nasa/stitchee/issues/325))([**@danielfromearth**](https://github.com/danielfromearth))
13-
- Download ICESat-2 ATL06 granules for integration testing instead of using git lfs ([#327](https://github.com/nasa/stitchee/pull/327))([**@danielfromearth**](https://github.com/danielfromearth))
14-
- Fix python version in matrixed GitHub Actions tests ([#329](https://github.com/nasa/stitchee/pull/329))([**@danielfromearth**](https://github.com/danielfromearth))
13+
- Implement uv dependency management and versioning with bump-my-version ([#325](https://github.com/nasa/ncompare/issues/325))([**@danielfromearth**](https://github.com/danielfromearth))
14+
- Download ICESat-2 ATL06 granules for integration testing instead of using git lfs (Updates Python version from 3.10 to 3.11) ([#327](https://github.com/nasa/ncompare/pull/327))([**@danielfromearth**](https://github.com/danielfromearth))
15+
- Refactor CI/CD workflows for releasing on publish, improve maintainability ([#333](https://github.com/nasa/ncompare/pull/33))([**@danielfromearth**](https://github.com/danielfromearth))
16+
- Update the default python version from 3.9 to 3.10 ([#323](https://github.com/nasa/ncompare/pull/323))([**@danielfromearth**](https://github.com/danielfromearth))
17+
18+
### Fixed
19+
- Fix python version in matrixed GitHub Actions tests ([#329](https://github.com/nasa/ncompare/pull/329))([**@danielfromearth**](https://github.com/danielfromearth))
1520

1621
## [1.13.1] - 2025-01-08
1722

scripts/verify_tag.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
5+
git_tag=$(git describe --tags --abbrev=0)
6+
current_version=v$(grep -m 1 version pyproject.toml | cut -d'"' -f 2)
7+
8+
echo "${git_tag} ${current_version}"
9+
10+
if [ "$current_version" == "$git_tag" ]; then
11+
echo "Version does match git tag"
12+
else
13+
echo "Version does not match git tag! pyproject.toml: ${current_version} vs Tag: ${git_tag} "
14+
exit 1
15+
fi

scripts/version_bump.sh

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
4+
BRANCH="${1}"
5+
echo "Processing branch: $BRANCH"
6+
7+
ALREADY_COMMITTED=false
8+
PUBLISH=false # Default: most branches don't publish
9+
10+
case "$BRANCH" in
11+
develop)
12+
echo "📦 Bumping develop alpha"
13+
bump-my-version bump pre_number
14+
;;
15+
16+
release/*)
17+
echo "🎯 Bumping release"
18+
CURRENT=$(bump-my-version show current_version)
19+
20+
if [[ "$CURRENT" == *"a"* ]]; then
21+
echo " Alpha → RC1"
22+
bump-my-version bump pre_label
23+
git commit -am "Bump to RC1 [skip ci]" && git push
24+
ALREADY_COMMITTED=true
25+
26+
# Auto-bump develop
27+
RELEASE_VERSION="${BRANCH#release/}"
28+
if [ -f "scripts/bump_develop_after_release.sh" ]; then
29+
bash scripts/bump_develop_after_release.sh "$RELEASE_VERSION" || exit 1
30+
fi
31+
git checkout "$BRANCH"
32+
else
33+
echo " Incrementing RC"
34+
bump-my-version bump pre_number
35+
fi
36+
PUBLISH=true
37+
;;
38+
39+
main)
40+
echo "🎉 Stripping to final release"
41+
bump-my-version bump pre_label
42+
;;
43+
44+
hotfix/*)
45+
echo "🔧 Bumping hotfix patch"
46+
CURRENT=$(bump-my-version show current_version)
47+
[[ "$CURRENT" =~ (rc|a) ]] && bump-my-version bump pre_label
48+
bump-my-version bump patch
49+
;;
50+
51+
feature/*|issue/*|docs/*|*)
52+
echo "🌟 Branch: no version bump"
53+
;;
54+
esac
55+
56+
VERSION=$(bump-my-version show current_version)
57+
58+
# Output for GitHub Actions
59+
{
60+
echo "version=$VERSION"
61+
echo "publish=$PUBLISH"
62+
echo "already_committed=$ALREADY_COMMITTED"
63+
} >> "$GITHUB_OUTPUT"
64+
65+
echo "📌 Version: $VERSION | 📤 Publish: $PUBLISH"

uv.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)