From bb48aefb5c6dc12fff4d8a9028470a09a8129fec Mon Sep 17 00:00:00 2001 From: erexer <13180883+erexer@users.noreply.github.com> Date: Thu, 7 Nov 2024 12:11:51 -0800 Subject: [PATCH] autopush to pypi action, rename build to test action, add python versions badge --- .github/workflows/docs.yml | 40 +++++++ .github/workflows/publish-to-pypi.yml | 125 ++++++++++++++++++++++ .github/workflows/{build.yml => test.yml} | 4 +- README.md | 2 + 4 files changed, 169 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/docs.yml create mode 100644 .github/workflows/publish-to-pypi.yml rename .github/workflows/{build.yml => test.yml} (93%) diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml new file mode 100644 index 0000000..8e8756d --- /dev/null +++ b/.github/workflows/docs.yml @@ -0,0 +1,40 @@ +name: docs + +on: + push: + branches: [ main ] + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Install pandoc + run: | + sudo apt-get update -y && sudo apt-get install -y pandoc + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + with: + python-version: '3.9' + - name: Update pip and install python dependencies + run: | + python -m pip install --upgrade pip + pip install .[dev] + - name: Build html docs + working-directory: 'docs/' + run: | + make html + - name: Commit documentation changes + run: | + cd docs/build/html + git init + git add -A + git config --local user.email "action@github.com" + git config --local user.name "GitHub Action" + git commit -m 'deploy' -a || true + - name: Push changes to gh-pages + uses: ad-m/github-push-action@master + with: + branch: gh-pages + directory: docs/build/html + force: true + github_token: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/.github/workflows/publish-to-pypi.yml b/.github/workflows/publish-to-pypi.yml new file mode 100644 index 0000000..6499ed6 --- /dev/null +++ b/.github/workflows/publish-to-pypi.yml @@ -0,0 +1,125 @@ +# This GitHub Action will only push to PyPI if the branch is tagged and then merged to main. +# Tag the branch with: +# $ git push REMOTE-NAME TAG-NAME + +name: Publish Python to PyPI + +on: + push: + branches: + - main + +jobs: + build: + name: Build distribution + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: "3.10.x" + - name: Install pypa/build + run: >- + python3 -m + pip install + build + --user + - name: Build a binary wheel and a source tarball + run: python3 -m build + - name: Store the distribution packages + uses: actions/upload-artifact@v4 + 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/mosartwmpy + permissions: + id-token: write # IMPORTANT: mandatory for trusted publishing + + steps: + - name: Download all the dists + uses: actions/download-artifact@v4 + with: + name: python-package-distributions + path: dist/ + - name: Publish distribution to PyPI + uses: pypa/gh-action-pypi-publish@release/v1 + + github-release: + name: >- + Sign the Python distribution with Sigstore + and upload them to GitHub Release + needs: + - publish-to-pypi + runs-on: ubuntu-latest + + permissions: + contents: write # IMPORTANT: mandatory for making GitHub Releases + id-token: write # IMPORTANT: mandatory for sigstore + + steps: + - name: Download all the dists + uses: actions/download-artifact@v4 + with: + name: python-package-distributions + path: dist/ + - name: Sign the dists with Sigstore + uses: sigstore/gh-action-sigstore-python@v2.1.1 + with: + inputs: >- + ./dist/*.tar.gz + ./dist/*.whl + - name: Create GitHub Release + env: + GITHUB_TOKEN: ${{ github.token }} + run: >- + gh release create + '${{ github.ref_name }}' + --repo '${{ github.repository }}' + --notes "" + - name: Upload artifact signatures to GitHub Release + env: + GITHUB_TOKEN: ${{ github.token }} + # Upload to GitHub Release using the `gh` CLI. + # `dist/` contains the built packages, and the + # sigstore-produced signatures and certificates. + run: >- + gh release upload + '${{ github.ref_name }}' dist/** + --repo '${{ github.repository }}' + + publish-to-testpypi: + name: Publish to TestPyPI + needs: + - build + runs-on: ubuntu-latest + + environment: + name: testpypi + url: https://test.pypi.org/p/mosartwmpy + + permissions: + id-token: write # IMPORTANT: mandatory for trusted publishing + + steps: + - name: Download all the dists + uses: actions/download-artifact@v4 + with: + name: python-package-distributions + path: dist/ + - name: Publish distribution to TestPyPI + uses: pypa/gh-action-pypi-publish@release/v1 + with: + repository-url: https://test.pypi.org/legacy/ + verbose: true \ No newline at end of file diff --git a/.github/workflows/build.yml b/.github/workflows/test.yml similarity index 93% rename from .github/workflows/build.yml rename to .github/workflows/test.yml index ab74e77..51c0001 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/test.yml @@ -1,4 +1,4 @@ -name: build +name: test on: [push] @@ -19,7 +19,7 @@ jobs: steps: - - uses: actions/checkout@v1 + - uses: actions/checkout@v4 - name: Set up Python uses: actions/setup-python@master diff --git a/README.md b/README.md index 7d31c55..00f0787 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,8 @@ [![codecov](https://codecov.io/gh/IMMM-SFA/mosartwmpy/branch/main/graph/badge.svg?token=IPOY8984MB)](https://codecov.io/gh/IMMM-SFA/mosartwmpy) [![DOI](https://joss.theoj.org/papers/10.21105/joss.03221/status.svg)](https://doi.org/10.21105/joss.03221) [![DOI](https://zenodo.org/badge/312114600.svg)](https://zenodo.org/badge/latestdoi/312114600) +[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/mosartwmpy)](https://pypi.org/project/mosartwmpy/) + ## mosartwmpy