Skip to content

chore(pre-commit): update pre-commit hooks #415

chore(pre-commit): update pre-commit hooks

chore(pre-commit): update pre-commit hooks #415

Workflow file for this run

name: Build
on:
push:
branches:
- main # allow to trigger the workflow with tag push event
pull_request:
paths:
- setup.py
- setup.cfg
- pyproject.toml
- MANIFEST.in
- nvitop/version.py
- Dockerfile
- .github/workflows/build.yaml
release:
types:
- published
# Allow to trigger the workflow manually
workflow_dispatch:
inputs:
task:
description: "Task type"
type: choice
options:
- build-only
- build-and-publish
required: true
concurrency:
group: "${{ github.workflow }}-${{ github.ref }}"
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
permissions:
contents: read
jobs:
build:
runs-on: ubuntu-20.04
if: github.repository == 'XuehaiPan/nvitop'
timeout-minutes: 30
steps:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: "recursive"
fetch-depth: 0
- name: Set up Python
id: py
uses: actions/setup-python@v5
with:
python-version: "3.7 - 3.12"
update-environment: true
- name: Set up Python 3.7
id: py37
uses: actions/setup-python@v5
with:
python-version: "3.7"
update-environment: false
- name: Check syntax (Python 3.7)
run: |
"${{ steps.py37.outputs.python-path }}" -m compileall nvitop
- name: Upgrade build dependencies
run: python -m pip install --upgrade pip setuptools wheel build
- name: Quick test
run: |
python -m venv venv &&
(
source venv/bin/activate &&
python -m pip install --upgrade pip setuptools pre-commit pylint[spelling] mypy typing-extensions &&
python -m pip install -r requirements.txt &&
python -m pip install -r nvitop-exporter/requirements.txt &&
python -m pre_commit install --install-hooks &&
python -m pre_commit run --all-files &&
python -c 'import nvitop' &&
python -m nvitop --version &&
python -m nvitop --help &&
python -m nvitop.select --version &&
python -m nvitop.select --help &&
(
cd nvitop-exporter &&
python -c 'import nvitop_exporter' &&
python -m nvitop_exporter --version &&
python -m nvitop_exporter --help
)
)
- name: Test docker build
run: |
docker build --tag nvitop:latest .
docker run --rm nvitop:latest --help
- name: Set __release__
if: startsWith(github.ref, 'refs/tags/') || github.event_name == 'workflow_dispatch'
run: |
sed -i -E 's/^__release__\s*=.*$/__release__ = True/' nvitop/version.py
sed -i -E 's/^__release__\s*=.*$/__release__ = True/' nvitop-exporter/nvitop_exporter/version.py
- name: Print version
run: |
python setup.py --version
python nvitop-exporter/setup.py --version
- name: Build sdist and wheels
run: |
python -m build --outdir dist .
python -m build --outdir dist nvitop-exporter
- name: List built sdist and wheels
run: ls -lh dist/
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: artifact
path: dist/*
if-no-files-found: error
publish:
runs-on: ubuntu-latest
needs: [build]
if: |
github.repository == 'XuehaiPan/nvitop' && github.event_name != 'pull_request' &&
(github.event_name != 'workflow_dispatch' || github.event.inputs.task == 'build-and-publish') &&
(github.event_name != 'push' || startsWith(github.ref, 'refs/tags/'))
timeout-minutes: 15
steps:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: "recursive"
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v5
if: startsWith(github.ref, 'refs/tags/')
with:
python-version: "3.7 - 3.12"
update-environment: true
- name: Upgrade pip
run: |
python -m pip install --upgrade pip setuptools
- name: Set __release__
if: startsWith(github.ref, 'refs/tags/') || github.event_name == 'workflow_dispatch'
run: |
sed -i -E 's/^__release__\s*=.*$/__release__ = True/' nvitop/version.py
sed -i -E 's/^__release__\s*=.*$/__release__ = True/' nvitop-exporter/nvitop_exporter/version.py
- name: Print version
run: |
python setup.py --version
python nvitop-exporter/setup.py --version
- name: Check consistency between the package version and release tag
if: startsWith(github.ref, 'refs/tags/')
run: |
RELEASE_TAG="${GITHUB_REF#refs/*/}"
PACKAGE_VER="v$(python setup.py --version)"
if [[ "${PACKAGE_VER}" != "${RELEASE_TAG}" ]]; then
echo "package ver. (${PACKAGE_VER}) != release tag. (${RELEASE_TAG})"
exit 1
fi
PACKAGE_VER="v$(python nvitop-exporter/setup.py --version)"
if [[ "${PACKAGE_VER}" != "${RELEASE_TAG}" ]]; then
echo "package ver. (${PACKAGE_VER}) != release tag. (${RELEASE_TAG})"
exit 1
fi
- name: Download built sdist and wheels
uses: actions/download-artifact@v4
with:
# unpacks default artifact into dist/
# if `name: artifact` is omitted, the action will create extra parent dir
name: artifact
path: dist
- name: Publish to TestPyPI
if: startsWith(github.ref, 'refs/tags/') || github.event_name == 'workflow_dispatch'
uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
password: ${{ secrets.TESTPYPI_UPLOAD_TOKEN }}
repository-url: https://test.pypi.org/legacy/
verbose: true
print-hash: true
skip-existing: true
- name: Publish to PyPI
if: startsWith(github.ref, 'refs/tags/') || github.event_name == 'workflow_dispatch'
uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
password: ${{ secrets.PYPI_UPLOAD_TOKEN }}
verbose: true
print-hash: true
skip-existing: true