Skip to content

CICD

CICD #22

Workflow file for this run

name: CICD
on:
workflow_dispatch:
permissions:
contents: write
checks: write
pull-requests: write
jobs:
build:
name: Run Tests, Pre-Commits, and Build Python package
uses: ./.github/workflows/ci.yml
check-branch:
needs: build
name: Check Branch
runs-on: ubuntu-latest
steps:
- name: Fail if branch is not main
run: |
if [[ "${{ github.ref }}" != "refs/heads/main" ]]; then
echo "This workflow can only be run on the main branch."
exit 1
fi
check-version:
needs: check-branch
runs-on: ubuntu-latest
outputs:
version: ${{ steps.get_version.outputs.VERSION }}
steps:
- uses: actions/checkout@v3
- name: Set up Python and Poetry
uses: ./.github/actions/python-poetry
with:
cache: true
- name: Get version from pyproject.toml
id: get_version
run: |
echo "VERSION=$(poetry version -s)" >> $GITHUB_OUTPUT
- name: Get latest release version
id: get_latest_release
run: |
latest_release=$(curl -s https://api.github.com/repos/${{ github.repository }}/releases/latest | jq -r .tag_name)
echo "LATEST_VERSION=${latest_release#v}" >> $GITHUB_OUTPUT
- name: Compare versions
run: |
current_version="${{ steps.get_version.outputs.VERSION }}"
latest_version="${{ steps.get_latest_release.outputs.LATEST_VERSION }}"
if [ "$(printf '%s\n' "$latest_version" "$current_version" | sort -V | tail -n1)" != "$current_version" ]; then
echo "Error: Current version ($current_version) is not higher than the latest release ($latest_version)"
exit 1
fi
create-release:
needs: check-version
runs-on: ubuntu-latest
permissions:
contents: write
id-token: write
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Create and push tag
run: |
git config --local user.email "[email protected]"
git config --local user.name "GitHub Action"
git tag -a v${{ needs.check-version.outputs.version }} -m "Release v${{ needs.check-version.outputs.version }}"
git push origin v${{ needs.check-version.outputs.version }}
- name: Set release notes file path
id: release-notes
run: echo "RELEASE_NOTES_PATH=./docs/release-notes/v${{ needs.check-version.outputs.version }}.md" >> $GITHUB_ENV
- name: Check if release notes file exists
id: check-release-notes
run: |
if [ ! -f "$RELEASE_NOTES_PATH" ]; then
echo "Error: Release notes file does not exist at path: $RELEASE_NOTES_PATH"
exit 1
fi
- name: Create GitHub Release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: v${{ needs.check-version.outputs.version }}
release_name: Release v${{ needs.check-version.outputs.version }}
body_path: ${{ env.RELEASE_NOTES_PATH }}
draft: false
prerelease: false
create-docs:
needs: create-release
name: Create and Deploy Documentation
uses: ./.github/workflows/docs.yml
publish-to-pypi:
needs: [build, check-version, create-release]
name: Publish Python package to PyPI
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python and Poetry
uses: ./.github/actions/python-poetry
with:
cache: true # Enable caching if your custom action supports it
- name: Download wheel
uses: actions/download-artifact@v4
with:
name: ${{ github.event.repository.name }}
path: dist/
- name: Publish to PyPI
env:
PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }}
run: |
poetry config pypi-token.pypi $PYPI_TOKEN
poetry publish