-
Notifications
You must be signed in to change notification settings - Fork 27
[Feature] Add automated PyPI publishing workflow #985
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ylangtsou
wants to merge
1
commit into
main
Choose a base branch
from
ylang/publish_package_to_pypi
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| #!/bin/bash | ||
| set -eu pipefail | ||
|
|
||
| # --- SCHEDULE TRIGGER --- | ||
| if [[ "$GH_EVENT_NAME" == "schedule" ]]; then | ||
| echo "Trigger: Schedule - Generating nightly build" | ||
|
|
||
| # --- Get Base Version from Tag --- | ||
| echo "Fetching latest tags..." | ||
| git fetch --tags --force | ||
| echo "Finding the latest stable version tag (vX.Y.Z)..." | ||
| LATEST_STABLE_TAG=$(git tag --sort=-v:refname | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' | head -n 1) | ||
| if [[ -z "$LATEST_STABLE_TAG" ]]; then | ||
| echo "Warning: No stable tag found." | ||
| exit 1 | ||
| else | ||
| BASE_VERSION=${LATEST_STABLE_TAG#v} | ||
| fi | ||
| echo "Using BASE_VERSION=${BASE_VERSION}" | ||
|
|
||
| # --- Generate Nightly Version --- | ||
| DATETIME_STR=$(date -u +%Y%m%d%H%M) | ||
| VERSION="${BASE_VERSION}.dev${DATETIME_STR}" | ||
|
|
||
| # --- PUSH TAG TRIGGER --- | ||
| elif [[ "$GH_EVENT_NAME" == "push" && "$GH_REF" == refs/tags/* ]]; then | ||
| echo "Trigger: Push Tag - Generating stable build" | ||
| TAG_NAME="$GH_REF_NAME" | ||
| VERSION=${TAG_NAME#v} | ||
|
|
||
| else | ||
| echo "Error: Unknown or unsupported trigger." | ||
| exit 1 | ||
| fi | ||
|
|
||
| # --- output --- | ||
| echo "Final determined values: VERSION=${VERSION}" | ||
| echo "VERSION=${VERSION}" >> "$GITHUB_OUTPUT" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| name: Publish Package to PyPI | ||
|
|
||
| on: | ||
| push: | ||
| tags: | ||
| - 'v[0-9]+.[0-9]+.[0-9]+*' | ||
| schedule: | ||
| - cron: '0 8 * * *' | ||
|
|
||
| jobs: | ||
| pypi_publish: | ||
| name: Build and Publish | ||
| runs-on: ubuntu-latest | ||
|
|
||
| permissions: | ||
| id-token: write | ||
| contents: read | ||
|
|
||
| steps: | ||
| - name: Checkout Code | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| fetch-depth: 0 | ||
|
|
||
| - name: Check if tag is on main branch | ||
| if: github.event_name == 'push' | ||
| run: | | ||
| echo "Checking if tag ${{ github.ref_name }} is on main branch..." | ||
| if git branch -r --contains ${{ github.ref_name }} | grep -q "origin/main"; then | ||
| echo "Tag is on origin/main. Proceeding with release." | ||
| else | ||
| echo "ERROR Tag ${{ github.ref_name }} is not on origin/main." | ||
| echo "This release will be aborted to prevent publishing from a non-main branch." | ||
| exit 1 | ||
| fi | ||
|
|
||
| - name: Set up Python | ||
| uses: actions/setup-python@v5 | ||
| with: | ||
| python-version: '3.x' | ||
|
|
||
| - name: Determine Version | ||
| id: vars | ||
| env: | ||
| GH_EVENT_NAME: ${{ github.event_name }} | ||
| GH_REF_NAME: ${{ github.ref_name }} | ||
| GH_REF: ${{ github.ref }} | ||
| run: bash .github/scripts/determine_release_vars.sh | ||
|
|
||
| - name: Install dependencies (build) | ||
| run: | ||
| python3 -m pip install build | ||
|
|
||
| - name: Build package (sdist and wheel) | ||
| env: | ||
| VLLM_VERSION_OVERRIDE: ${{ steps.vars.outputs.VERSION }} | ||
| run: python3 -m build | ||
|
|
||
| - name: Publish package distributions to PyPI | ||
| uses: pypa/gh-action-pypi-publish@release/v1 | ||
|
|
||
| - name: Publish completed message | ||
| run: echo "---Build and publish completed successfully.---" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,3 @@ | ||
| include requirements.txt | ||
| include README.md | ||
| include version.py | ||
| include tpu_inference/models/jax/utils/quantization/configs/*.yaml |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Your current setup will lead to triggering the release workflow even if the tag is created on a non-main branch.
We only want the release tag to go off if it's created on the protected (main) branch. This is required to ensure only admins or selected people can trigger a stable release via release tag