From 412a4e90aa67ba0cbe6a33ec53142351fe95bac5 Mon Sep 17 00:00:00 2001 From: DraftMan Date: Tue, 30 Jul 2024 19:19:51 +0200 Subject: [PATCH] ci: add deploy pipeline --- .github/workflows/publish.yml | 52 +++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 .github/workflows/publish.yml diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..0a15715 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,52 @@ +name: Publish to PyPI + +on: + push: + branches: + - main + +jobs: + publish: + runs-on: ubuntu-latest + + if: github.repository_owner == 'Blagues-API' + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 2 + + - name: Check if version changed + id: check_version + run: | + git diff HEAD^ HEAD -- pyproject.toml | grep '+version' && echo "version_changed=true" >> $GITHUB_OUTPUT || echo "version_changed=false" >> $GITHUB_OUTPUT + + - uses: actions/setup-python@v5 + if: steps.check_version.outputs.version_changed == 'true' + id: setup-python + with: + python-version: '3.12' + + - name: Install Poetry + if: steps.check_version.outputs.version_changed == 'true' + uses: snok/install-poetry@v1 + with: + virtualenvs-create: true + virtualenvs-in-project: true + + - name: Load cached venv + if: steps.check_version.outputs.version_changed == 'true' + id: cached-poetry-dependencies + uses: actions/cache@v3 + with: + path: .venv + key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }} + + - name: Build + if: steps.check_version.outputs.version_changed == 'true' + run: poetry build + + - name: Publish package distributions to PyPI + if: steps.check_version.outputs.version_changed == 'true' + uses: pypa/gh-action-pypi-publish@release/v1 + with: + packages-dir: dist/ \ No newline at end of file