Skip to content

temporarily hide the contributor #45

temporarily hide the contributor

temporarily hide the contributor #45

Workflow file for this run

name: Publish the latest release on PyPI
on:
push:
tags:
- 'v*'
branches:
- release # Restricts the workflow to only run on tags pushed to the release branch
workflow_dispatch: # allows manual control
inputs:
version:
description: 'Override the version number'
required: false
rollback:
description: 'Trigger a rollback to the previous stable version'
required: false
default: false
jobs:
validate-tag:
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/')
steps:
- uses: actions/checkout@v3
- name: Validate Tag Format
run: |
TAG_REGEX='^v[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9\-\.]+)?$'
echo "Regex to match: $TAG_REGEX"
TAG="${GITHUB_REF/refs\/tags\//}"
echo "Tag extracted: $TAG"
if [[ "$TAG" =~ $TAG_REGEX ]]; then
echo "Tag format is valid."
else
echo "::error::Tag $TAG does not match the 'vMAJOR.MINOR.PATCH' or 'vMAJOR.MINOR.PATCH-pre-release' format."
exit 1
fi
shell: bash
build-and-package:
needs: validate-tag
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.10', '3.11', '3.12'] # Ensure consistency with build-and-package job
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install Poetry
run: |
python -m pip install --upgrade pip
pip install poetry
- name: Install dependencies
run: |
poetry install --no-dev
- name: Build the distribution
run: |
poetry build
- name: Upload distribution for publishing
uses: actions/upload-artifact@v2
with:
name: dist
path: dist/**
dry-run-publish:
needs: build-and-package
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.10', '3.11', '3.12'] # Ensure consistency with build-and-package job
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install Poetry
run: |
python -m pip install --upgrade pip
pip install poetry
- name: Dry run publish to PyPI
run: |
cd lightrag
poetry publish --dry-run --build -v
# Uncomment the following lines to enable TestPyPI publishing
# test-publish-to-testpypi:
# needs: build-and-package
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v3
# - name: Set up Python
# uses: actions/setup-python@v4
# with:
# python-version: '3.11'
# - name: Download distribution
# uses: actions/download-artifact@v2
# with:
# name: dist
# path: dist
# - name: Publish to TestPyPI
# run: |
# poetry config repositories.testpypi https://test.pypi.org/legacy/
# poetry publish --repository testpypi --username __token__ --password ${{ secrets.TEST_PYPI_API_TOKEN }}
publish-to-pypi:
needs:
- validate-tag
- build-and-package
- dry-run-publish
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.10', '3.11', '3.12'] # Ensure consistency with build-and-package job
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install Poetry
run: |
python -m pip install --upgrade pip
pip install poetry
- name: Publish to PyPI
uses: pypa/[email protected]
with:
user: __token__
password: ${{ secrets.PYPI_KEY }}
create-github-release:
needs: publish-to-pypi
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Create Release on GitHub
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref_name }}
release_name: Release ${{ github.ref_name }}
body: 'Automated release of version ${{ github.ref_name }}'
draft: false
prerelease: false
rollback:
needs: publish-to-pypi
if: ${{ github.event.inputs.rollback == 'true' }}
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.10', '3.11', '3.12'] # Ensure consistency with build-and-package job
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Rollback to previous stable version
run: |
echo "Rolling back to previous stable version..."
# Add rollback logic here