From 06ab047d876255e90911a6a978f450d070215867 Mon Sep 17 00:00:00 2001 From: Maxim V4S Date: Thu, 10 Oct 2024 12:49:10 +0300 Subject: [PATCH] ci: publish to PyPI (test) on publish release --- .../{release.yaml => release_github.yaml} | 2 + .github/workflows/release_pypi.yaml | 61 +++++++++++++++++++ .github/workflows/reusable-build.yaml | 8 ++- 3 files changed, 69 insertions(+), 2 deletions(-) rename .github/workflows/{release.yaml => release_github.yaml} (95%) create mode 100644 .github/workflows/release_pypi.yaml diff --git a/.github/workflows/release.yaml b/.github/workflows/release_github.yaml similarity index 95% rename from .github/workflows/release.yaml rename to .github/workflows/release_github.yaml index dce10542..814c5fd9 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release_github.yaml @@ -13,6 +13,8 @@ on: jobs: build: uses: qua-platform/quam/.github/workflows/reusable-build.yaml@main + with: + ref: ${{ env.GITHUB_REF_NAME }} release: runs-on: ubuntu-latest needs: diff --git a/.github/workflows/release_pypi.yaml b/.github/workflows/release_pypi.yaml new file mode 100644 index 00000000..d812d7c3 --- /dev/null +++ b/.github/workflows/release_pypi.yaml @@ -0,0 +1,61 @@ +name: Release + +on: + release: + types: [ published ] + workflow_dispatch: + inputs: + ref: + type: string + description: Ref to checkout + required: true +env: + # make sure the poetry creates the venv inside the workspace under .venv + POETRY_VIRTUALENVS_IN_PROJECT: true + +jobs: + build-release: + name: Publish from release + if: github.event_name == 'release' + uses: qua-platform/quam/.github/workflows/reusable-build.yaml@main + with: + ref: ${{inputs.ref}} + build-manually: + name: Publish from manual trigger + if: github.event_name == 'workflow_dispatch' + uses: qua-platform/quam/.github/workflows/reusable-build.yaml@main + + release: + name: Release package to PyPi + runs-on: ubuntu-latest + needs: + - build-release + - build-manually + if: | # TODO: remove when only release trigger be kept + always() + && contains(needs.*.result, 'success') + && !contains(needs.*.result, 'failure') + permissions: + id-token: write + contents: read + checks: write + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + # This is necessary so that we have the tags. + fetch-depth: 0 + ref: ${{inputs.ref}} + + - uses: actions/download-artifact@v4 + with: + path: dist + merge-multiple: true + pattern: python-package-* + + - name: Publish distribution to PyPI + uses: pypa/gh-action-pypi-publish@v1.10.3 + with: + repository-url: https://test.pypi.org/legacy/ + password: ${{ secrets.TEST_PYPI_API_TOKEN }} + # password: ${{ secrets.PYPI_API_TOKEN }} diff --git a/.github/workflows/reusable-build.yaml b/.github/workflows/reusable-build.yaml index e8627733..27f5f608 100644 --- a/.github/workflows/reusable-build.yaml +++ b/.github/workflows/reusable-build.yaml @@ -5,19 +5,23 @@ name: Build python package on: - workflow_call + workflow_call: + inputs: + ref: + type: string jobs: build: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 + with: + ref: ${{ inputs.ref }} - uses: actions/setup-python@v5 with: python-version: "3.8" cache: "pip" - - name: Install python deps run: python -m pip install -e .[build]