Skip to content

Commit

Permalink
build: Build and release workflow updates (#142)
Browse files Browse the repository at this point in the history
* build: abandoned poetry, added ruff

* refactor: release workflow
  • Loading branch information
JuanPedroGHM authored Aug 14, 2024
1 parent cfef4ec commit 84cbb40
Show file tree
Hide file tree
Showing 13 changed files with 182 additions and 226 deletions.
120 changes: 31 additions & 89 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,99 +2,41 @@ name: Release

on:
push:
branches:
- release
- release-test

tags:
- 'v*.*.*'
- 'v*.*.*rc'
jobs:
Test:
uses: Helmholtz-AI-Energy/perun/.github/workflows/run_tests.yaml@main
VersionAndChangelog:
outputs:
tag: ${{ steps.semantic-release.outputs.tag }}
needs: Test
runs-on: ubuntu-latest
environment: release
concurrency: publish
permissions:
contents: write
id-token: write
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.PERSONAL_GH_TOKEN }}
- uses: actions/setup-python@v4
- name: Install dependencies
run: |
pip install poetry
poetry install --with dev
- name: Update version and changelog
id: semantic-release
run: |
poetry run semantic-release version --no-vcs-release --skip-build
cat $GITHUB_OUTPUT
env:
GH_TOKEN: ${{ secrets.PERSONAL_GH_TOKEN }}
Release-to-Pypi:
runs-on: ubuntu-latest
needs: VersionAndChangelog
environment: release
concurrency: publish
permissions:
contents: write
id-token: write
steps:
- name: Get new tag
run: |
echo ${{ needs.VersionAndChangelog.outputs.tag }}
- uses: actions/checkout@v4
with:
ref: ${{ needs.VersionAndChangelog.outputs.tag }}
- uses: actions/setup-python@v5
- name: Install dependencies
run: |
pip install poetry
- name: Build perun
run: |
poetry build
- name: Store the distribution packages
uses: actions/upload-artifact@v4
with:
name: python-package-distributions
path: dist/
- name: Publish to Pypi

if: ${{ !contains(needs.VersionAndChangelog.outputs.tag, 'rc') }}
run: |
poetry config pypi-token.pypi ${{ secrets.PYPI_TOKEN }}
poetry publish
- name: Publish to Test Pypi
if: ${{ contains(needs.VersionAndChangelog.outputs.tag, 'rc') }}
run: |
poetry config repositories.testpypi https://test.pypi.org/legacy/
poetry config pypi-token.testpypi ${{ secrets.TESTPYPI_TOKEN }}
poetry publish --repository testpypi
Release-to-GitHub:
needs: [Release-to-Pypi, VersionAndChangelog]
runs-on: ubuntu-latest
environment: release
concurrency: publish
permissions:
contents: write
id-token: write
steps:
pypi-publish:
name: Upload release to PyPI
runs-on: ubuntu-latest
# Specifying a GitHub environment is optional, but strongly encouraged
environment: release
permissions:
# IMPORTANT: this permission is mandatory for trusted publishing
id-token: write
steps:
- uses: actions/checkout@v4
# Checkout the tag that triggered the workflow
with:
ref: ${{ needs.VersionAndChangelog.outputs.tag }}
- name: Download all the dists
uses: actions/download-artifact@v4
ref: ${{ github.ref }}
- uses: actions/setup-python@v4
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -e .[dev]
- name: Build package
run: |
python -m build
- name: Publish package distributions to PyPI
# Only run if the tag is a release
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') && !contains(github.ref, 'rc')
uses: pypa/gh-action-pypi-publish@release/v1
- name: Publish package to Test PyPI
# Only run if the tag is a release candidate
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') && contains(github.ref, 'rc')
uses: pypa/gh-action-pypi-publish@release/v1
with:
name: python-package-distributions
path: dist/
- name: Upload artifact signatures to GitHub Release
env:
GITHUB_TOKEN: ${{ github.token }}
PERUN_VERSION: ${{ needs.VersionAndChangelog.outputs.tag }}
run: >-
gh release create --draft --generate-notes --title $PERUN_VERSION --verify-tag $PERUN_VERSION ./dist/**
server: https://test.pypi.org/legacy/
13 changes: 7 additions & 6 deletions .github/workflows/run_tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11"]
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]

steps:
- uses: actions/checkout@v4
Expand All @@ -23,13 +23,14 @@ jobs:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
pip install poetry
poetry install --with dev
python -m pip install --upgrade pip
pip install -e .[dev]
- name: Test with pytest and cmdline commands
run: |
poetry run perun
poetry run perun sensors
poetry run pytest --cov=perun --cov-report=xml
perun
perun sensors
coverage run
coverage xml
- name: Upload coverage reports to Codecov
uses: codecov/[email protected]
with:
Expand Down
52 changes: 16 additions & 36 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,55 +1,35 @@
repos:
- repo: https://github.com/commitizen-tools/commitizen
rev: v3.28.0
rev: v3.29.0
hooks:
- id: commitizen
stages: [commit-msg]
# - repo: https://github.com/python-poetry/poetry
# rev: '1.4.0' # add version here
# hooks:
# - id: poetry-check
# - id: poetry-lock
# - id: poetry-export
# args: ["-f", "requirements.txt", "-o", "requirements.txt"]
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.11.0 # Use the sha / tag you want to point at
rev: v1.11.1 # Use the sha / tag you want to point at
hooks:
- id: mypy
additional_dependencies: [types-all]
- repo: https://github.com/pycqa/pydocstyle
rev: 6.3.0 # pick a git hash / tag to point to
hooks:
- id: pydocstyle
additional_dependencies: [tomli]
files: ^perun/
args:
- --config=pyproject.toml
- repo: https://github.com/asottile/seed-isort-config
rev: v2.2.0
hooks:
- id: seed-isort-config
args:
- --exclude=examples/
- repo: https://github.com/pycqa/isort
rev: 5.13.2
hooks:
- id: isort
name: isort (python)
- repo: https://github.com/psf/black
rev: 24.4.2
hooks:
- id: black
# additional_dependencies: [types-all]
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.5.7
hooks:
# Run the linter.
- id: ruff
args: [ --fix ]
# Run the formatter.
- id: ruff-format
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files
- repo: https://github.com/PyCQA/flake8
rev: 7.1.0
- repo: https://github.com/Yelp/detect-secrets
rev: v1.5.0
hooks:
- id: flake8
- id: detect-secrets
exclude: .pre-commit-config.yaml
- repo: "https://github.com/citation-file-format/cffconvert"
rev: "054bda51dbe278b3e86f27c890e3f3ac877d616c"
hooks:
Expand Down
1 change: 0 additions & 1 deletion perun/backend/nvml.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ def getSensors(self, deviceList: Set[str]) -> List[Sensor]:
return devices

def _getPowerSensor(self, device_idx: int) -> Sensor:

handle = self.pynvml.nvmlDeviceGetHandleByIndex(device_idx)
uuid = self.pynvml.nvmlDeviceGetUUID(handle)
log.debug(f"Index: {device_idx} - UUID : {uuid}")
Expand Down
1 change: 0 additions & 1 deletion perun/backend/rocmsmi.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ def getSensors(self, deviceList: Set[str]) -> List[Sensor]:
return devices

def _getPowerSensor(self, device_idx: int) -> Sensor:

device_id = self.rocml.smi_get_device_id(device_idx)
log.debug(f"Setting up device {device_id}")

Expand Down
4 changes: 3 additions & 1 deletion perun/io/hdf5.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,9 @@ def _readRawData(group: h5py.Group) -> RawData:
v_md = _readMetricMetadata(group["values"]) # type: ignore

alt_values = group["alt_values"][:] if "alt_values" in group else None # type: ignore
alt_v_md = _readMetricMetadata(group["alt_values"]) if alt_values is not None else None # type: ignore
alt_v_md = (
_readMetricMetadata(group["alt_values"]) if alt_values is not None else None
) # type: ignore
return RawData(
timesteps=timesteps, # type: ignore
values=values, # type: ignore
Expand Down
3 changes: 0 additions & 3 deletions perun/monitoring/monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ def __init__(
l_assigned_sensors: Dict[str, Tuple],
config: ConfigParser,
) -> None:

self._app = app
self._comm = comm
self._backends = backends
Expand Down Expand Up @@ -243,7 +242,6 @@ def _run_python_app(self, run_id: str) -> Tuple[MonitorStatus, Optional[DataNode
return self.status, self._process_single_run(run_id, starttime_ns)

def _run_binary_app(self, run_id: str) -> Tuple[MonitorStatus, Optional[DataNode]]:

# 1) Prepare sensors
(
timesteps,
Expand Down Expand Up @@ -292,7 +290,6 @@ def _run_binary_app(self, run_id: str) -> Tuple[MonitorStatus, Optional[DataNode
return MonitorStatus.SUCCESS, runNode

def _handle_failed_run(self) -> Optional[DataNode]:

availableRanks = self._comm.check_available_ranks()

log.error(f"Rank {self._comm.Get_rank()}: Available ranks {availableRanks}")
Expand Down
6 changes: 2 additions & 4 deletions perun/processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ def processEnergyData(
magFactor = raw_data.v_md.mag.value / Magnitude.ONE.value

if raw_data.v_md.unit == Unit.JOULE:

# If getting energy, transform to power
e_J = raw_data.values
maxValue = raw_data.v_md.max
Expand Down Expand Up @@ -90,7 +89,6 @@ def processEnergyData(
)

elif raw_data.v_md.unit == Unit.WATT:

power_W = raw_data.values.astype("float32") * magFactor

if start and end:
Expand Down Expand Up @@ -175,9 +173,9 @@ def processSensorData(sensorData: DataNode) -> DataNode:

elif sensorData.deviceType == DeviceType.OTHER:
sensorData.metrics[MetricType.OTHER_ENERGY] = energyMetric.copy()
sensorData.metrics[MetricType.OTHER_ENERGY].type = (
sensorData.metrics[
MetricType.OTHER_ENERGY
)
].type = MetricType.OTHER_ENERGY
sensorData.metrics[MetricType.OTHER_POWER] = powerMetric.copy()
sensorData.metrics[MetricType.OTHER_POWER].type = MetricType.OTHER_POWER

Expand Down
1 change: 0 additions & 1 deletion perun/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ class has already been instantiated.
--------
>>> class MyClass(metaclass=Singleton):
... pass
...
>>> my_instance = MyClass() # Returns the instance of MyClass
"""

Expand Down
Loading

0 comments on commit 84cbb40

Please sign in to comment.