Update continuous_delivery.yml #9
This file contains 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
name: CD | |
on: | |
push: | |
branches: | |
- main | |
jobs: | |
check_version_and_publish: | |
runs-on: ubuntu-latest | |
strategy: | |
fail-fast: false | |
matrix: | |
python-version: [ 3.8, 3.9 ] | |
include: | |
- python-version: 3.8 | |
enable_publish: true # Publish only for python 3.8 | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Set up Python ${{ matrix.python-version }} | |
uses: actions/setup-python@v5 | |
with: | |
python-version: ${{ matrix.python-version }} | |
- name: Install Poetry | |
run: | | |
curl -sSL https://install.python-poetry.org | python3 - | |
export PATH="$HOME/.poetry/bin:$PATH" | |
- name: Install project dependencies with Poetry | |
run: | | |
poetry install | |
- name: Extract version from pyproject.toml | |
id: extract_version | |
run: | | |
VERSION=$(poetry version -s) | |
echo "PACKAGE_VERSION=${VERSION}" >> $GITHUB_ENV | |
- name: Verify if version has changed | |
id: version_check | |
run: | | |
if [ $(git tag -l "v${{ env.PACKAGE_VERSION }}") ]; then | |
echo "Version ${{ env.PACKAGE_VERSION }} already exists." | |
exit 0 | |
fi | |
- name: Verify whether to publish | |
run: | | |
if ! (( ${{ matrix.enable_publish }} )) || [ ${{ steps.version_check.outcome }} != "success" ]; then | |
exit 0 | |
fi | |
- name: Build and publish to pypi | |
run: | | |
poetry config pypi-token.pypi ${{ secrets.PYPI_TOKEN }} | |
poetry publish --build | |
- name: Create a Git tag | |
run: | | |
git config --global user.email "github-actions[bot]@users.noreply.github.com" | |
git config --global user.name "GitHub Actions" | |
git tag "v${{ env.PACKAGE_VERSION }}" | |
git push origin "v${{ env.PACKAGE_VERSION }}" |