Skip to content

Commit c85d980

Browse files
authored
[infra] publish rc to pypi as part of release process (#1449)
## Which issue does this PR close? <!-- We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. For example `Closes #123` indicates that this PR will close issue #123. --> - Closes #1409. ## What changes are included in this PR? Changes - Trigger `publish` workflow only by matching specific tag names (`v<major>.<minor>.<patch>` or `v<major>.<minor>.<patch>-rc.<release_candidate>`) instead of all tags - Add a step in `pypi` workflow to again validate the tag name - Edit `pypi` workflow to override the Cargo version for RC. This allows us to upload to pypi as pre-release <!-- Provide a summary of the modifications in this PR. List the main changes such as new features, bug fixes, refactoring, or any other updates. --> ## Are these changes tested? <!-- Specify what test covers (unit test, integration test, etc.). If tests are not included in your PR, please explain why (for example, are they covered by existing tests)? --> Yes, tested against personal fork. Tested - push invalid tag, i.e. `should-not-trigger`. ✅ does not trigger the `publish` job - push RC tag, i.e. `v0.6.0-rc.1`. ✅ triggers [`publish` job](https://github.com/kevinjqliu/iceberg-rust/actions/runs/15815922351) and [`pypi` job](https://github.com/kevinjqliu/iceberg-rust/actions/runs/15815944806) - push release tag, i.e. `v0.6.0`. ✅ triggers [`publish` job](https://github.com/kevinjqliu/iceberg-rust/actions/runs/15815922462) and [`pypi` job](https://github.com/kevinjqliu/iceberg-rust/actions/runs/15815944240) For both `v0.6.0-rc.1` and `v0.6.0`, verified the generated artifacts (`wheels-sdist` and `wheels-ubuntu-latest-armv7l`) locally for the correctly set python version number.
1 parent 772ae1a commit c85d980

File tree

2 files changed

+70
-7
lines changed

2 files changed

+70
-7
lines changed

.github/workflows/publish.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@ name: Publish
2020
on:
2121
push:
2222
tags:
23-
- "*"
23+
# Trigger this workflow when tag follows the versioning format: v<major>.<minor>.<patch> OR v<major>.<minor>.<patch>-rc.<release_candidate>
24+
# Example valid tags: v0.4.0, v0.4.0-rc.1
25+
- "v[0-9]+.[0-9]+.[0-9]+"
26+
- "v[0-9]+.[0-9]+.[0-9]+-rc.[0-9]+"
2427
workflow_dispatch:
2528

2629
env:

.github/workflows/release_python.yml

Lines changed: 66 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ env:
2828
rust_msrv: "1.85"
2929

3030
concurrency:
31-
group: ${{ github.workflow }}-${{ github.ref }}-${{ github.event_name }}
31+
group: ${{ github.workflow }}-${{ github.event.workflow_run.head_branch }}-${{ github.event_name }}
3232
cancel-in-progress: true
3333

3434
permissions:
@@ -42,11 +42,62 @@ jobs:
4242
steps:
4343
- run: echo 'The Publish workflow passed or was manually triggered'
4444

45-
sdist:
45+
validate-release-tag:
4646
runs-on: ubuntu-latest
4747
needs: [check-cargo-publish]
48+
outputs:
49+
cargo-version: ${{ steps.validate.outputs.cargo-version }}
50+
is-rc: ${{ steps.validate.outputs.is-rc }}
51+
steps:
52+
- name: Validate release tag format
53+
id: validate
54+
# Note, `workflow_run.head_branch` does not contain `refs/tags/` prefix, just the tag name, i.e. `v0.4.0` or `v0.4.0-rc.1`
55+
# Valid formats: v<major>.<minor>.<patch> OR v<major>.<minor>.<patch>-rc.<release_candidate>
56+
run: |
57+
RELEASE_TAG="${{ github.event.workflow_run.head_branch }}"
58+
echo "Validating release tag: $RELEASE_TAG"
59+
if [[ ! "$RELEASE_TAG" =~ ^v[0-9]+\.[0-9]+\.[0-9]+(-rc\.[0-9]+)?$ ]]; then
60+
echo "❌ Invalid release tag format: $RELEASE_TAG"
61+
echo "Expected format: v<major>.<minor>.<patch> OR v<major>.<minor>.<patch>-rc.<release_candidate>"
62+
echo "Examples: v0.4.0, v1.2.3-rc.1"
63+
exit 1
64+
fi
65+
echo "✅ Release tag format is valid: $RELEASE_TAG"
66+
67+
# Strip 'v' prefix for cargo version
68+
CARGO_VERSION="${RELEASE_TAG#v}"
69+
echo "Cargo version (without v prefix): $CARGO_VERSION"
70+
71+
# Check if this is a release candidate
72+
if [[ "$RELEASE_TAG" =~ -rc\.[0-9]+$ ]]; then
73+
IS_RC="true"
74+
echo "This is a release candidate"
75+
else
76+
IS_RC="false"
77+
echo "This is a stable release"
78+
fi
79+
80+
# Set outputs for other jobs to use
81+
echo "cargo-version=$CARGO_VERSION" >> $GITHUB_OUTPUT
82+
echo "is-rc=$IS_RC" >> $GITHUB_OUTPUT
83+
84+
sdist:
85+
runs-on: ubuntu-latest
86+
needs: [validate-release-tag]
4887
steps:
4988
- uses: actions/checkout@v4
89+
90+
- name: Install cargo-edit
91+
if: ${{ needs.validate-release-tag.outputs.is-rc == 'true' }}
92+
run: cargo install cargo-edit
93+
94+
- name: Set cargo version for RC
95+
if: ${{ needs.validate-release-tag.outputs.is-rc == 'true' }}
96+
working-directory: "bindings/python"
97+
run: |
98+
echo "Setting cargo version to: ${{ needs.validate-release-tag.outputs.cargo-version }}"
99+
cargo set-version ${{ needs.validate-release-tag.outputs.cargo-version }}
100+
50101
- uses: PyO3/maturin-action@v1
51102
with:
52103
working-directory: "bindings/python"
@@ -60,7 +111,7 @@ jobs:
60111

61112
wheels:
62113
runs-on: "${{ matrix.os }}"
63-
needs: [check-cargo-publish]
114+
needs: [validate-release-tag]
64115
strategy:
65116
matrix:
66117
include:
@@ -75,6 +126,18 @@ jobs:
75126
- { os: ubuntu-latest, target: "armv7l" }
76127
steps:
77128
- uses: actions/checkout@v4
129+
130+
- name: Install cargo-edit
131+
if: ${{ needs.validate-release-tag.outputs.is-rc == 'true' }}
132+
run: cargo install cargo-edit
133+
134+
- name: Set cargo version for RC
135+
if: ${{ needs.validate-release-tag.outputs.is-rc == 'true' }}
136+
working-directory: "bindings/python"
137+
run: |
138+
echo "Setting cargo version to: ${{ needs.validate-release-tag.outputs.cargo-version }}"
139+
cargo set-version ${{ needs.validate-release-tag.outputs.cargo-version }}
140+
78141
- uses: actions/setup-python@v5
79142
with:
80143
python-version: 3.9
@@ -99,9 +162,6 @@ jobs:
99162
name: Publish Python 🐍 distribution 📦 to Pypi
100163
needs: [sdist, wheels]
101164
runs-on: ubuntu-latest
102-
# Only publish to PyPi if the tag is not a pre-release OR if manually triggered
103-
# Note, `workflow_run.head_branch` does not contain `refs/tags/` prefix, just the tag name, i.e. `v0.4.0` or `v0.4.0-rc.1`
104-
if: ${{ !contains(github.event.workflow_run.head_branch, '-') || github.event_name == 'workflow_dispatch' }}
105165

106166
environment:
107167
name: pypi

0 commit comments

Comments
 (0)