update CI #3
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
# This workflow will install Python dependencies, run tests and lint with a single version of Python | |
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python | |
name: Python application CI | |
on: | |
push: | |
branches: [ "main" ] | |
pull_request: | |
branches: [ "main" ] | |
permissions: | |
contents: write | |
jobs: | |
check: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Install poetry | |
run: pipx install poetry | |
- uses: actions/setup-python@v5 | |
name: Set up Python 3.12 | |
with: | |
python-version: '3.12' | |
cache: 'poetry' | |
- name: Install dependencies | |
run: | | |
poetry install | |
- name: Run ruff | |
run: | | |
poetry run ruff check . | |
poetry run ruff format --check . | |
- name: Test with pytest | |
run: | | |
poetry run pytest | |
build: | |
if: github.ref == 'refs/heads/main' && github.event_name != 'pull_request' | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Install poetry | |
run: pipx install poetry | |
- uses: actions/setup-python@v5 | |
name: Set up Python 3.12 | |
with: | |
python-version: '3.12' | |
cache: 'poetry' | |
- name: Install dependencies | |
run: | | |
poetry install | |
- name: Get version from pyproject.toml | |
id: get_version | |
run: | | |
VERSION=$(poetry version -s) | |
echo "VERSION=$VERSION" >> $GITHUB_ENV | |
- name: Check if tag exists | |
id: check_tag | |
run: | | |
if git rev-parse "v${{ env.VERSION }}" >/dev/null 2>&1; then | |
echo "tag_exists=true" >> $GITHUB_OUTPUT | |
else | |
echo "tag_exists=false" >> $GITHUB_OUTPUT | |
fi | |
- name: Create tag and release | |
if: steps.check_tag.outputs.tag_exists == 'false' | |
run: | | |
git tag "v${{ env.VERSION }}" | |
git push origin "v${{ env.VERSION }}" | |
gh release create "v${{ env.VERSION }}" --title "v${{ env.VERSION }}" --notes "Release version ${{ env.VERSION }}" | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |