Skip to content

Commit

Permalink
[infra] add testpypi nightly build (#1601)
Browse files Browse the repository at this point in the history
Closes #872

This PR adds the ability to run and publish pypi artifacts nightly to
testpypi. It will publish as `pyiceberg` with new version under
`0.9.0.dev${TIMESTAMP}`, i.e. `0.9.0.dev20250206050843`, adhering to
PEP440 conversion.

Here's a [test run on my
fork](https://github.com/kevinjqliu/iceberg-python/actions/runs/13172235318)
which published to https://test.pypi.org/project/pyiceberg-kevinliu/

This requires setting up [Publishing to PyPI with a Trusted
Publisher](https://docs.pypi.org/trusted-publishers/) on
https://test.pypi.org/ and using example of publishing
[pyiceberg_core](https://github.com/apache/iceberg-rust/blob/8714ffd69c411990a89e1c3f03b51c33670f18ec/.github/workflows/release_python.yml#L120-L146)
to testpypi


Note, this PR also refactors `.github/workflows/python-release.yml`,
i've [ran the workflow on my
fork](https://github.com/kevinjqliu/iceberg-python/actions/runs/13172075517)
and manually verified the version for both pypi and svn artifacts.



Setup trusted publisher on testpypi for apache/iceberg-python repo
https://test.pypi.org/manage/project/pyiceberg/settings/publishing/
  • Loading branch information
kevinjqliu authored Feb 7, 2025
1 parent 4d648bb commit b47af2d
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 16 deletions.
85 changes: 85 additions & 0 deletions .github/workflows/nightly-pypi-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#

name: "Nightly PyPI Build"

on:
schedule:
- cron: "0 0 * * *" # Runs at midnight UTC every day
workflow_dispatch: # Allows manual triggering

jobs:
set-version:
if: github.repository == 'apache/iceberg-python' # Only run for apache repo
runs-on: ubuntu-latest
outputs:
VERSION: ${{ steps.set-version.outputs.VERSION }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 1

- uses: actions/setup-python@v5
with:
python-version: 3.12

- name: Install Poetry
run: make install-poetry

- name: Set version
id: set-version
run: |
CURRENT_VERSION=$(poetry version --short)
TIMESTAMP=$(date +%Y%m%d%H%M%S)
echo "VERSION=${CURRENT_VERSION}.dev${TIMESTAMP}" >> "$GITHUB_OUTPUT"
- name: Debug version
run: echo "Publishing version ${{ steps.set-version.outputs.VERSION }}"

nightly-build:
needs: set-version
uses: ./.github/workflows/pypi-build-artifacts.yml
with:
version: ${{ needs.set-version.outputs.VERSION }}
testpypi-publish:
name: Publish to TestPypi
needs:
- nightly-build
runs-on: ubuntu-latest
environment:
name: testpypi
url: https://test.pypi.org/p/pyiceberg

permissions:
id-token: write # IMPORTANT: mandatory for trusted publishing

steps:
- name: Download all the artifacts
uses: actions/download-artifact@v4
with:
merge-multiple: true
path: dist/
- name: List downloaded artifacts
run: ls -R dist/
- name: Publish to TestPyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://test.pypi.org/legacy/
skip-existing: true
verbose: true
10 changes: 3 additions & 7 deletions .github/workflows/pypi-build-artifacts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,14 @@ on:
VERSION:
required: true
type: string
RC:
required: true
type: string

jobs:
pypi-build-artifacts:
name: Build artifacts for PyPi on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ ubuntu-22.04, windows-2022, macos-13, macos-14, macos-15 ]
os: [ ubuntu-22.04, windows-2022, macos-13, macos-14 ]

steps:
- uses: actions/checkout@v4
Expand All @@ -56,8 +53,7 @@ jobs:
- name: Set version with RC
env:
VERSION: ${{ inputs.VERSION }}
RC: ${{ inputs.RC }}
run: python -m poetry version "${{ env.VERSION }}rc${{ env.RC }}" # e.g., 0.8.0rc1
run: python -m poetry version "${{ env.VERSION }}"

# Publish the source distribution with the version that's in
# the repository, otherwise the tests will fail
Expand Down Expand Up @@ -97,6 +93,6 @@ jobs:
- name: Merge Artifacts
uses: actions/upload-artifact/merge@v4
with:
name: "pypi-release-candidate-${{ inputs.VERSION }}rc${{ inputs.RC }}"
name: "pypi-release-candidate-${{ inputs.VERSION }}"
pattern: pypi-release-candidate*
delete-merged: true
6 changes: 2 additions & 4 deletions .github/workflows/python-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,7 @@ jobs:
- validate-library-version
uses: ./.github/workflows/svn-build-artifacts.yml
with:
version: ${{ needs.validate-inputs.outputs.VERSION }}
rc: ${{ needs.validate-inputs.outputs.RC }}
version: ${{ needs.validate-inputs.outputs.VERSION }}rc${{ needs.validate-inputs.outputs.RC }}

# PyPi
pypi-build-artifacts:
Expand All @@ -131,5 +130,4 @@ jobs:
- validate-library-version
uses: ./.github/workflows/pypi-build-artifacts.yml
with:
version: ${{ needs.validate-inputs.outputs.VERSION }}
rc: ${{ needs.validate-inputs.outputs.RC }}
version: ${{ needs.validate-inputs.outputs.VERSION }}rc${{ needs.validate-inputs.outputs.RC }}
7 changes: 2 additions & 5 deletions .github/workflows/svn-build-artifacts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,14 @@ on:
VERSION:
required: true
type: string
RC:
required: true
type: string

jobs:
svn-build-artifacts:
name: Build artifacts for SVN on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ ubuntu-22.04, windows-2022, macos-13, macos-14, macos-15 ]
os: [ ubuntu-22.04, windows-2022, macos-13, macos-14 ]

steps:
- uses: actions/checkout@v4
Expand Down Expand Up @@ -91,6 +88,6 @@ jobs:
- name: Merge Artifacts
uses: actions/upload-artifact/merge@v4
with:
name: "svn-release-candidate-${{ inputs.VERSION }}rc${{ inputs.RC }}"
name: "svn-release-candidate-${{ inputs.VERSION }}"
pattern: svn-release-candidate*
delete-merged: true

0 comments on commit b47af2d

Please sign in to comment.