From c9a549ac73c4a71c3549df50065bf6ed7e8cded6 Mon Sep 17 00:00:00 2001 From: jenisys Date: Sun, 25 Aug 2024 22:54:13 +0200 Subject: [PATCH] CI: Add release workflows --- .github/workflows/manual-release-to-pypi.yml | 65 ++++++++++++++++++++ .github/workflows/release-to-pypi.yml | 53 ++++++++++++++++ .github/workflows/release-to-testpypi.yml | 58 +++++++++++++++++ 3 files changed, 176 insertions(+) create mode 100644 .github/workflows/manual-release-to-pypi.yml create mode 100644 .github/workflows/release-to-pypi.yml create mode 100644 .github/workflows/release-to-testpypi.yml diff --git a/.github/workflows/manual-release-to-pypi.yml b/.github/workflows/manual-release-to-pypi.yml new file mode 100644 index 0000000..73dc558 --- /dev/null +++ b/.github/workflows/manual-release-to-pypi.yml @@ -0,0 +1,65 @@ +# -- WORKFLOW: Publish/release this package on PyPI +# SEE: +# * https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python +# * https://docs.github.com/en/actions/use-cases-and-examples/building-and-testing/building-and-testing-python#publishing-to-pypi +# +# * https://docs.github.com/en/actions/writing-workflows +# * https://docs.github.com/en/actions/writing-workflows/choosing-when-your-workflow-runs +# * https://docs.github.com/en/actions/writing-workflows/choosing-when-your-workflow-runs/events-that-trigger-workflows#release +# +# GITHUB ACTIONS: +# * https://github.com/actions/checkout +# * https://github.com/pypa/gh-action-pypi-publish +# +# RELATED: +# * https://github.com/actions/starter-workflows/blob/main/ci/python-publish.yml + +# -- STATE: PREPARED_ONLY, NOT_RELEASED_YET +name: manual-release-to-pypi +on: + workflow_dispatch: # -- NOTE: Run it manually and provide the version. + inputs: + VERSION: + description: "Existing version to publish the release (to pypi; EXAMPLE: VERSION=1.2.7)" + required: true + type: string + +permissions: + contents: read + +jobs: + publish-package: + runs-on: ubuntu-latest + # MAYBE: if: github.event_name == "push" && startsWith(github.ref, "refs/tags/v") + environment: + name: pypi + url: https://pypi.org/project/parse-type + # OR: https://pypi.org/p/ + permissions: + id-token: write # REQUIRED-FOR: Trusted publishing. + steps: + - uses: actions/checkout@v4 + with: + ref: "v${{inputs.VERSION}}" + # env: + # VERSION: "${{inputs.VERSION}}" + - uses: actions/setup-python@v5 + with: + python-version: "3.10" + - name: "Install Python package dependencies (with: uv)" + run: | + python -m pip install -U uv + python -m uv pip install -U pip setuptools wheel build twine + - name: Build this package + run: python -m build + - name: Check this package (before upload) + run: twine check dist/* ─╯ + - name: Upload this package to PyPI + uses: pypa/gh-action-pypi-publish@release/v1 + with: + print-hash: true + verbose: true + # -- MAYBE: + # with: + # repository-url: https://test.pypi.org/legacy/ + # password: ${{ secrets.TEST_PYPI_API_TOKEN }} diff --git a/.github/workflows/release-to-pypi.yml b/.github/workflows/release-to-pypi.yml new file mode 100644 index 0000000..88e25e4 --- /dev/null +++ b/.github/workflows/release-to-pypi.yml @@ -0,0 +1,53 @@ +# -- WORKFLOW: Publish/release this package on PyPI +# SEE: +# * https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python +# * https://docs.github.com/en/actions/use-cases-and-examples/building-and-testing/building-and-testing-python#publishing-to-pypi +# +# * https://docs.github.com/en/actions/writing-workflows +# * https://docs.github.com/en/actions/writing-workflows/choosing-when-your-workflow-runs +# * https://docs.github.com/en/actions/writing-workflows/choosing-when-your-workflow-runs/events-that-trigger-workflows#release +# +# GITHUB ACTIONS: +# * https://github.com/actions/checkout +# * https://github.com/pypa/gh-action-pypi-publish +# +# RELATED: +# * https://github.com/actions/starter-workflows/blob/main/ci/python-publish.yml + +# -- STATE: PREPARED_ONLY, NOT_RELEASED_YET +name: release-to-pypi +on: + release: + types: [published] + # MAYBE: if: github.event_name == "push" && startsWith(github.ref, "refs/tags/v") + +permissions: + contents: read + +jobs: + publish-package: + runs-on: ubuntu-latest + # MAYBE: if: github.event_name == "push" && startsWith(github.ref, "refs/tags/v") + environment: + name: pypi + url: https://pypi.org/p/parse-type + permissions: + id-token: write # REQUIRED-FOR: Trusted publishing. + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + with: + python-version: "3.10" + - name: "Install Python package dependencies (with: uv)" + run: | + python -m pip install -U uv + python -m uv pip install -U pip setuptools wheel build twine + - name: Build this package + run: python -m build + - name: Check this package (before upload) + run: twine check dist/* ─╯ + - name: Upload this package to PyPI + uses: pypa/gh-action-pypi-publish@release/v1 + with: + print-hash: true + verbose: true diff --git a/.github/workflows/release-to-testpypi.yml b/.github/workflows/release-to-testpypi.yml new file mode 100644 index 0000000..40924ac --- /dev/null +++ b/.github/workflows/release-to-testpypi.yml @@ -0,0 +1,58 @@ +# -- WORKFLOW: Publish/release this package on PyPI (testpypi) +# SEE: +# * https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python +# * https://docs.github.com/en/actions/use-cases-and-examples/building-and-testing/building-and-testing-python#publishing-to-pypi +# +# * https://docs.github.com/en/actions/writing-workflows +# * https://docs.github.com/en/actions/writing-workflows/choosing-when-your-workflow-runs +# * https://docs.github.com/en/actions/writing-workflows/choosing-when-your-workflow-runs/events-that-trigger-workflows#release +# +# GITHUB ACTIONS: +# * https://github.com/actions/checkout +# * https://github.com/pypa/gh-action-pypi-publish +# +# RELATED: +# * https://github.com/actions/starter-workflows/blob/main/ci/python-publish.yml + +# -- STATE: PREPARED_ONLY, NOT_RELEASED_YET +name: release-to-pypi +on: + release: + types: [published] + # MAYBE: if: github.event_name == "push" && startsWith(github.ref, "refs/tags/v") + +permissions: + contents: read + +jobs: + publish-package: + runs-on: ubuntu-latest + # MAYBE: if: github.event_name == "push" && startsWith(github.ref, "refs/tags/v") + environment: + name: pypi + url: https://test.pypi.org/project/parse-type + # OR: https://test.pypi.org/p/ + permissions: + id-token: write # REQUIRED-FOR: Trusted publishing. + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + with: + python-version: "3.10" + - name: "Install Python package dependencies (with: uv)" + run: | + python -m pip install -U uv + python -m uv pip install -U pip setuptools wheel build twine + - name: Build this package + run: python -m build + - name: Check this package (before upload) + run: twine check dist/* ─╯ + - name: Upload this package to PyPI + uses: pypa/gh-action-pypi-publish@release/v1 + with: + print-hash: true + verbose: true + # -- MAYBE: + # with: + # repository-url: https://test.pypi.org/legacy/ + # password: ${{ secrets.TEST_PYPI_API_TOKEN }}