feat(ci): add release workflow (#1562)
This commit is contained in:
88
.github/workflows/release.yml
vendored
Normal file
88
.github/workflows/release.yml
vendored
Normal file
@@ -0,0 +1,88 @@
|
||||
# Copyright 2025 The HuggingFace Inc. team. All rights reserved.
|
||||
#
|
||||
# Licensed 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: Create Release and Publish to PyPI
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- 'v*.*.*' # Trigger on tags like v0.1.0, v1.0.0
|
||||
|
||||
jobs:
|
||||
# TODO(Steven): Publish draft/pre-release and to test pypi
|
||||
# TODO(Steven): Tag documentation with the same version as the package
|
||||
# TODO(Steven): Define entry points for main CLI scripts
|
||||
build-and-publish:
|
||||
name: Build and publish Python distributions
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
contents: write
|
||||
id-token: write
|
||||
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
persist-credentials: false
|
||||
|
||||
- name: Set up Python
|
||||
uses: actions/setup-python@v5
|
||||
with:
|
||||
python-version: '3.10'
|
||||
|
||||
- name: Extract Version and Package Name
|
||||
id: extract_info
|
||||
# zizmor: ignore[template-injection]
|
||||
run: |
|
||||
# Extract version from tag (e.g., v0.1.0 -> 0.1.0)
|
||||
VERSION=${{ github.ref_name }}
|
||||
VERSION_NUMBER=${VERSION#v}
|
||||
echo "tag_version=$VERSION_NUMBER" >> $GITHUB_OUTPUT
|
||||
|
||||
# Extract package name from pyproject.toml
|
||||
PACKAGE_NAME=$(grep -oP 'name = "\K[^"]+' pyproject.toml)
|
||||
echo "package_name=$PACKAGE_NAME" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Check if version exists on PyPI
|
||||
# zizmor: ignore[template-injection]
|
||||
run: |
|
||||
PACKAGE_NAME=${{ steps.extract_info.outputs.package_name }}
|
||||
NEW_VERSION=${{ steps.extract_info.outputs.tag_version }}
|
||||
|
||||
response=$(curl -s "https://pypi.org/pypi/$PACKAGE_NAME/$NEW_VERSION/json")
|
||||
if echo "$response" | grep -q "message"; then
|
||||
echo "Version $NEW_VERSION is available on PyPI. Proceeding with release."
|
||||
else
|
||||
echo "Error: Version $NEW_VERSION already exists on PyPI. Aborting."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
- name: Install build dependencies
|
||||
run: python -m pip install build
|
||||
|
||||
- name: Build package
|
||||
run: python -m build
|
||||
|
||||
- name: Create GitHub Release
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
# zizmor: ignore[template-injection]
|
||||
run: gh release create ${{ github.ref_name }} --release-name "Release ${{ github.ref_name }}" --generate-notes ./dist/*
|
||||
|
||||
# TODO(Steven): Uncomment when ready to publish to PyPI
|
||||
# - name: Publish to PyPI
|
||||
# if: startsWith(github.ref, 'refs/tags/v')
|
||||
# uses: pypa/gh-action-pypi-publish@v1.12.4
|
||||
# with:
|
||||
# password: ${{ secrets.PYPI_API_TOKEN }}
|
||||
Reference in New Issue
Block a user