From 734d93513512418fcaa08dabd2194f67604ace85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Magimel?= Date: Fri, 17 Apr 2026 08:18:32 +0000 Subject: [PATCH] ci: add a workflow to build and release The workflow builds the package when a PR is merged on the `main` branch, and release it in on PyPI when a tag is created. This workflow is taken from: - https://github.com/marshmallow-code/apispec/blob/dev/.github/workflows/build-release.yml - https://packaging.python.org/en/latest/guides/publishing-package-distribution-releases-using-github-actions-ci-cd-workflows/. --- .github/workflows/build-release.yml | 53 +++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 .github/workflows/build-release.yml diff --git a/.github/workflows/build-release.yml b/.github/workflows/build-release.yml new file mode 100644 index 0000000..c54d054 --- /dev/null +++ b/.github/workflows/build-release.yml @@ -0,0 +1,53 @@ +name: build-release + +on: + push: + branches: ["main"] + tags: ["*"] + +permissions: + contents: read + +jobs: + build: + name: Build package + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 + with: + persist-credentials: false + - uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0 + with: + python-version-file: pyproject.toml + - name: Build the binary wheel and the source tarball + run: | + python -m pip install build + python -m build + - name: Check distribution packages + run: | + python -m pip install twine + twine check --strict dist/* + - name: Store the distribution packages + uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 + with: + name: python-package-distributions + path: dist/ + + publish-to-pypi: + name: Publish Python distribution to PyPI + if: startsWith(github.ref, 'refs/tags/') # only publish to PyPI on tag pushes + needs: [build] + runs-on: ubuntu-latest + environment: + name: pypi + url: https://pypi.org/p/apispec-fromfile + permissions: + id-token: write + steps: + - name: Download all the dists + uses: actions/download-artifact@018cc2cf5baa6db3ef3c5f8a56943fffe632ef53 # v6.0.0 + with: + name: python-package-distributions + path: dist/ + - name: Publish distribution to PyPI + uses: pypa/gh-action-pypi-publish@cef221092ed1bacb1cc03d23a2d87d1d172e277b # v1.14.0