From 6eac23f3e1fe0623e72a015a1b2a123b6098ad68 Mon Sep 17 00:00:00 2001 From: RichieHakim Date: Mon, 29 Jan 2024 18:06:50 -0500 Subject: [PATCH] try setting up actions and pypi release --- .github/workflows/build.yml | 153 +++++++++++++++++++++++++++++ .github/workflows/pypi_release.yml | 101 +++++++++++++++++++ bnpm/__init__.py | 2 +- 3 files changed, 255 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/build.yml create mode 100644 .github/workflows/pypi_release.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..5c61e12 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,153 @@ +name: build + +on: + push: + branches: [ "main" ] + # branches: [ "dev" ] + # branches: [ "main", "dev" ] + # pull_request: + # branches: [ "main" ] + # branches: [ "dev" ] + # branches: [ "main", "dev" ] + workflow_dispatch: + inputs: + name: + description: 'description' + required: false + default: '' + +permissions: + contents: read + +jobs: + + build: + + name: ${{ matrix.platform }}, py${{ matrix.python-version }}, ${{ matrix.extra }}, ${{ matrix.install-level }} + runs-on: ${{ matrix.platform }} + strategy: + fail-fast: false + matrix: + platform: [ + # ubuntu-latest, + ubuntu-22.04, + ubuntu-20.04, + # # windows-latest, + windows-2022, + windows-2019, + # # macos-latest, + macos-12, + macos-11.0, + # macos-10.15, + ] + python-version: [ + # "3.9", + # "3.10", + "3.11", + # "3.12", + ] + extra: [ + all, + all_latest, + ] + install-level: [ + system, + user, + ] + + steps: + + - name: Set up conda + uses: conda-incubator/setup-miniconda@v2 + with: + miniconda-version: latest + activate-environment: bnpm + auto-activate-base: true + auto-update-conda: false + remove-profiles: true + architecture: x64 + clean-patched-environment-file: true + run-post: true + + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v3 + with: + python-version: ${{ matrix.python-version }} + + - name: Check out repository code + uses: actions/checkout@v3 + + - name: Prepare PowerShell + shell: pwsh + run: | + conda info + conda list + + - name: Check specs of the machine -- Linux + if: startsWith(matrix.platform, 'ubuntu') + run: | + ## check cpu, memory, disk, etc. + ## print the command inputs to the workflow + echo "CPU info (lscpu):" + lscpu + echo "Memory info (free -h):" + free -h + echo "Disk info (df -h):" + df -h + echo "Network info (ip a):" + ip a + echo "OS info (uname -a):" + uname -a + - name: Check specs of the machine -- Windows + if: startsWith(matrix.platform, 'windows') + run: | + ## check cpu, memory, disk, etc. + ## just do a generic check on system info + ## print the command inputs to the workflow + echo "System info (systeminfo):" + systeminfo + - name: Check specs of the machine -- MacOS + if: startsWith(matrix.platform, 'macos') + run: | + ## check cpu, memory, disk, etc. + ## print the command inputs to the workflow + echo "CPU info (sysctl -n machdep.cpu.brand_string):" + sysctl -n machdep.cpu.brand_string + echo "Memory info (sysctl -n hw.memsize):" + sysctl -n hw.memsize + echo "Disk info (df -h):" + df -h + echo "OS info (uname -a):" + uname -a + + + - name: Install package with pip dependencies -- system-level + if: matrix.install-level == 'system' + run: | + ## install dependencies with optional extras + pip install -v -e .[${{ matrix.extra }}] + - name: Install package with pip dependencies -- user-level + if: matrix.install-level == 'user' + run: | + pip install -v -e .[${{ matrix.extra }}] --user + + + - name: Check installed packages + run: | + pip list + ## Below, check which versions of torch and torchvision are installed; and whether CUDA is available + python -c "import torch, torchvision; print(f'Using versions: torch=={torch.__version__}, torchvision=={torchvision.__version__}'); print('torch.cuda.is_available() = ', torch.cuda.is_available())" + + - name: Run pytest and generate coverage report + run: | + # pip install tox tox-gh-actions + pip install pytest pytest-cov + python -m pytest --capture=tee-sys --cov=bnpm --cov-report=xml:coverage.xml --color=yes + + - name: Upload coverage reports to Codecov + uses: codecov/codecov-action@v3 ## this is a public action recognized by GitHub Actions + with: + token: ${{ secrets.CODECOV_TOKEN }} ## this is a secret variable + file: coverage.xml ## this is the default name of the coverage report file + fail_ci_if_error: false + verbose: true diff --git a/.github/workflows/pypi_release.yml b/.github/workflows/pypi_release.yml new file mode 100644 index 0000000..fcdd4f3 --- /dev/null +++ b/.github/workflows/pypi_release.yml @@ -0,0 +1,101 @@ +name: Publish Python 🐍 distribution 📦 to PyPI + +on: + workflow_dispatch: + inputs: + name: + description: 'description' + required: false + default: '' +jobs: + build: + name: Build distribution 📦 + runs-on: ubuntu-20.04 + + steps: + - uses: actions/checkout@v4 + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: "3.11" + - 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 + # 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/project/bnpm # Replace with your PyPI project name + 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: + - uses: actions/checkout@v4 + - 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: List files in workspace + run: >- + ls ${{ github.workspace }} + - name: List files in upper directory + run: >- + ls ${{ github.workspace }}/.. + - name: List files in dist + run: >- + ls ${{ github.workspace }}/dist + - name: Store the version number + run: | + version=$(grep '__version__' ${{ github.workspace }}/bnpm/__init__.py | awk -F = '{print $2}' | tr -d ' ' | tr -d \"\') + echo "VERSION=$version" >> $GITHUB_ENV + - name: Check version number + run: echo "Version is $VERSION" + - name: Create GitHub Release + env: + GITHUB_TOKEN: ${{ github.token }} + run: >- + gh release create "v$VERSION" + --title "v$VERSION" + --notes "Release for version $VERSION. Also available on PyPI: https://pypi.org/project/bnpm/$VERSION/" + --repo ${{ github.repository }} \ No newline at end of file diff --git a/bnpm/__init__.py b/bnpm/__init__.py index 11401c6..5a92ec5 100644 --- a/bnpm/__init__.py +++ b/bnpm/__init__.py @@ -36,4 +36,4 @@ for pkg in __all__: exec('from . import ' + pkg) -__version__ = '0.3.0' \ No newline at end of file +__version__ = '0.3.1' \ No newline at end of file