From 9676813362616382cb9fc41d66a05fdc9c135605 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20Paduszy=C5=84ski?= <92403542+paduszyk@users.noreply.github.com> Date: Thu, 23 May 2024 18:45:42 +0200 Subject: [PATCH] ci: set up the package CD pipeline (#17) --- .github/workflows/pre-commit-run.yml | 1 + .github/workflows/python-cd.yml | 70 ++++++++++++++++++++++++++++ .github/workflows/python-ci.yml | 2 + 3 files changed, 73 insertions(+) create mode 100644 .github/workflows/python-cd.yml diff --git a/.github/workflows/pre-commit-run.yml b/.github/workflows/pre-commit-run.yml index 3cd6d2d..1c944a1 100644 --- a/.github/workflows/pre-commit-run.yml +++ b/.github/workflows/pre-commit-run.yml @@ -10,6 +10,7 @@ on: jobs: pre-commit-run: + if: ${{ !startsWith(github.event.head_commit.message, 'bump:') }} name: Run Pre-commit hooks runs-on: ubuntu-latest steps: diff --git a/.github/workflows/python-cd.yml b/.github/workflows/python-cd.yml new file mode 100644 index 0000000..a78f8f5 --- /dev/null +++ b/.github/workflows/python-cd.yml @@ -0,0 +1,70 @@ +name: "Python: CD" + +on: + push: + tags: + - "*.*.*" + +jobs: + build: + name: Build package + runs-on: ubuntu-latest + outputs: + package-version: ${{ steps.package-version.outputs.package-version }} + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + with: + cache: pip + - run: python -m pip install --upgrade pip + - run: python -m pip install build + - run: python -m build + - uses: actions/upload-artifact@v4 + with: + name: dist + path: dist/* + - id: package-version + run: | + python -m pip install . + echo "package-version=$( + python -c 'import sys, xlsx_serializer; sys.stdout.write(xlsx_serializer.__version__)' + )" >> $GITHUB_OUTPUT + check-tag: + name: Check tag + needs: + - build + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - run: | + if [ "${{ needs.build.outputs.package-version }}" != "${{ github.ref_name }}" ]; then + exit 1 + fi + pypi: + name: Publish package to PyPI + needs: + - check-tag + runs-on: ubuntu-latest + permissions: + id-token: write + environment: + name: PyPI + url: https://pypi.org/p/django-xlsx-serializer/ + steps: + - uses: actions/download-artifact@v4 + with: + name: dist + path: dist/ + - uses: pypa/gh-action-pypi-publish@release/v1 + release: + name: Create GitHub release + needs: + - pypi + runs-on: ubuntu-latest + permissions: + contents: write + steps: + - uses: actions/checkout@v4 + - uses: softprops/action-gh-release@v2 + with: + generate_release_notes: true diff --git a/.github/workflows/python-ci.yml b/.github/workflows/python-ci.yml index b578294..be62b5d 100644 --- a/.github/workflows/python-ci.yml +++ b/.github/workflows/python-ci.yml @@ -10,6 +10,7 @@ on: jobs: get-python-versions: + if: ${{ !startsWith(github.event.head_commit.message, 'bump:') }} name: Get Python versions runs-on: ubuntu-latest outputs: @@ -23,6 +24,7 @@ jobs: echo "$(python ./scripts/get_python_versions.py)" >> $GITHUB_OUTPUT echo "EOF" >> $GITHUB_OUTPUT format-nox-sessions: + if: ${{ !startsWith(github.event.head_commit.message, 'bump:') }} name: Format Nox sessions runs-on: ubuntu-latest outputs: