Skip to content

Merge pull request #189 from PowerGridModel/dependabot/github_actions… #1069

Merge pull request #189 from PowerGridModel/dependabot/github_actions…

Merge pull request #189 from PowerGridModel/dependabot/github_actions… #1069

# SPDX-FileCopyrightText: 2022 Contributors to the Power Grid Model project <[email protected]>
#
# SPDX-License-Identifier: MPL-2.0
name: Build, Test, Sonar and Publish
on:
push:
branches:
- main
- 'release/**'
# run pipeline on pull request
pull_request:
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
jobs:
build-python:
if: (github.event_name == 'push') || (github.event_name == 'workflow_dispatch') || !startsWith(github.head_ref, 'release')
runs-on: ubuntu-latest
outputs:
version: ${{ steps.version.outputs.version }}
steps:
- name: Checkout source code
uses: actions/checkout@v3
- name: Setup Python 3.11
uses: actions/setup-python@v4
with:
python-version: "3.11"
- name: Build
run: |
pip install requests build
python set_pypi_version.py
python -m build --outdir wheelhouse .
- name: Save version
id: version
run: echo "version=$(cat PYPI_VERSION)" >> $GITHUB_OUTPUT
- name: Store built wheel file
uses: actions/upload-artifact@v3
with:
name: power-grid-model-io
path: wheelhouse/
sonar-cloud:
# only run sonar server in push event or pull request event from own repo
if: (github.event_name == 'push') || (github.event_name == 'workflow_dispatch') || (!startsWith(github.head_ref, 'release') && (github.event.pull_request.head.repo.owner.login == 'PowerGridModel'))
permissions:
contents: write
runs-on: ubuntu-latest
steps:
- name: Checkout source code
uses: actions/checkout@v3
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
- name: Setup Python 3.10
uses: actions/setup-python@v4
with:
python-version: "3.10"
- name: Install in develop mode
run: |
pip install -e .[dev]
- name: Test and Coverage
run: |
pytest --cov-report=xml:coverage.xml --cov-fail-under=0
# Fix relative paths in coverage file
# Known bug: https://community.sonarsource.com/t/sonar-on-github-actions-with-python-coverage-source-issue/36057
sed -i 's@/home/runner/work/power-grid-model-io/power-grid-model-io@/github/workspace@g' coverage.xml
- name: SonarCloud Scan
uses: SonarSource/sonarcloud-github-action@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
unit-tests:
needs: build-python
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python: ["3.8", "3.9", "3.10", "3.11"]
fail-fast: false
runs-on: ${{ matrix.os }}
steps:
- name: Checkout source code
uses: actions/checkout@v3
- name: Setup Python ${{ matrix.python }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python }}
- name: Load built wheel file
uses: actions/download-artifact@v3
with:
name: power-grid-model-io
path: wheelhouse/
- name: Install built wheel file
run: pip install power-grid-model-io[dev]==${{ needs.build-python.outputs.version }} --find-links=wheelhouse
- name: Unit test and coverage
run: pytest --verbose
validation-tests:
needs: build-python
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python: ["3.8", "3.9", "3.10", "3.11"]
fail-fast: false
runs-on: ${{ matrix.os }}
steps:
- name: Checkout source code
uses: actions/checkout@v3
- name: Setup Python ${{ matrix.python }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python }}
- name: Load built wheel file
uses: actions/download-artifact@v3
with:
name: power-grid-model-io
path: wheelhouse/
- name: Install built wheel file
run: pip install power-grid-model-io[dev]==${{ needs.build-python.outputs.version }} --find-links=wheelhouse
- name: Validation tests
run: pytest tests/validation --no-cov --verbose
publish:
needs:
- build-python
- unit-tests
- validation-tests
- sonar-cloud
permissions:
contents: write
env:
TWINE_USERNAME: ${{ secrets.PYPI_USER }}
TWINE_PASSWORD: ${{ secrets.PYPI_PASS }}
runs-on: ubuntu-latest
steps:
- name: Setup Python 3.10
uses: actions/setup-python@v4
with:
python-version: "3.10"
- name: Load built wheel file
uses: actions/download-artifact@v3
with:
name: power-grid-model-io
path: wheelhouse/
- name: Upload wheels
if: (github.event_name == 'push') || (github.event_name == 'workflow_dispatch')
run: |
pip install twine
echo "Publish to PyPI..."
twine upload --verbose wheelhouse/*
- name: Release
if: (github.event_name == 'push') || (github.event_name == 'workflow_dispatch')
uses: softprops/action-gh-release@v1
with:
files: |
./wheelhouse/*
tag_name: v${{ needs.build-python.outputs.version }}
prerelease: ${{ contains(needs.build-python.outputs.version, 'rc') || contains(needs.build-python.outputs.version, 'a') }}
generate_release_notes: true
target_commitish: ${{ github.sha }}