From 60df4079ad3aed27d16716057de9282170825a11 Mon Sep 17 00:00:00 2001 From: Carlos Adir Date: Fri, 14 Feb 2025 15:45:40 +0000 Subject: [PATCH] fix: github workflows --- .github/workflows/black.yaml | 22 +++++ .github/workflows/{tests.yml => build.yaml} | 26 ++++-- .github/workflows/codecov.yaml | 45 ++++++++++ .github/workflows/publish.yaml | 94 +++++++++++++++++++++ 4 files changed, 180 insertions(+), 7 deletions(-) create mode 100644 .github/workflows/black.yaml rename .github/workflows/{tests.yml => build.yaml} (60%) create mode 100644 .github/workflows/codecov.yaml create mode 100644 .github/workflows/publish.yaml diff --git a/.github/workflows/black.yaml b/.github/workflows/black.yaml new file mode 100644 index 0000000..218ff4c --- /dev/null +++ b/.github/workflows/black.yaml @@ -0,0 +1,22 @@ +name: Lint with Black + +on: + push: + paths: + - src/** + - tests/** + branches: + - main + pull_request: + +jobs: + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - uses: psf/black@stable + with: + options: "--check --verbose --exclude docs" + + diff --git a/.github/workflows/tests.yml b/.github/workflows/build.yaml similarity index 60% rename from .github/workflows/tests.yml rename to .github/workflows/build.yaml index 6c6ed4a..f33fda0 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/build.yaml @@ -1,29 +1,41 @@ +# This is a basic workflow to help you get started with Actions + name: Tests # Controls when the workflow will run on: - - push - - pull_request + push: + paths: + - src/** + - tests/** + branches: [ main ] + pull_request: + branches: [ main ] + workflow_dispatch: # A workflow run is made up of one or more jobs that can run sequentially or in parallel jobs: # This workflow contains a single job called "build" - test: + build: # The type of runner that the job will run on runs-on: ${{ matrix.os }} strategy: matrix: os: [ubuntu-latest, windows-latest] - python-version: ['3.6', '3.7', '3.8', '3.9'] + python-version: ['3.7', '3.8', '3.9', '3.10'] steps: - - uses: actions/checkout@v2 + - name: Checkout sources + uses: actions/checkout@v2 + - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v2 with: python-version: ${{ matrix.python-version }} + - name: Install dependencies run: | python -m pip install --upgrade pip - pip install tox tox-gh-actions - - name: Test with tox + python -m pip install tox tox-gh-actions + + - name: Run with tox run: tox diff --git a/.github/workflows/codecov.yaml b/.github/workflows/codecov.yaml new file mode 100644 index 0000000..09e8e70 --- /dev/null +++ b/.github/workflows/codecov.yaml @@ -0,0 +1,45 @@ +name: Coverage + +on: + push: + paths: + - src/** + - tests/** + branches: [ main ] + pull_request: + branches: [ main ] + workflow_dispatch: + +jobs: + coverage: + runs-on: ubuntu-latest + + steps: + - name: Checkout sources + uses: actions/checkout@v2 + + - name: Setup Python + uses: actions/setup-python@v2 + with: + python-version: "3.10" + + - name: Checkout sources + uses: actions/checkout@v2 + + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + python -m pip install tox tox-gh-actions + + - name: Run coverage + run: tox -e coverage + + - name: Upload coverage reports to Codecov + uses: codecov/codecov-action@v3 + with: + fail_ci_if_error: true diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml new file mode 100644 index 0000000..b28c499 --- /dev/null +++ b/.github/workflows/publish.yaml @@ -0,0 +1,94 @@ +name: Publish to PyPI + +on: + release: + types: [ published ] + branches: [ main ] + workflow_dispatch: + +jobs: + build: + name: Build distribution 📦 + runs-on: ubuntu-latest + + steps: + - name: Checkout sources + uses: actions/checkout@v4 + + - name: Setup Python + uses: actions/setup-python@v2 + with: + python-version: "3.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@v3 + with: + name: python-package-distributions + path: dist/ + + publish-to-pypi: + name: | + Publish Python distribution to PyPI + needs: + - build + runs-on: ubuntu-latest + environment: + name: pypi + url: https://pypi.org/p/compmec-hyper + permissions: + id-token: write # IMPORTANT: mandatory for trusted publishing + steps: + - name: Download all the dists + uses: actions/download-artifact@v3 + 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@v3 + with: + name: python-package-distributions + path: dist/ + - name: Sign the dists with Sigstore + uses: sigstore/gh-action-sigstore-python@v1.2.3 + 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 }}' \ No newline at end of file