diff --git a/.github/workflows/build-test-release.yml b/.github/workflows/build-test-release.yml new file mode 100644 index 00000000..e6c46dbe --- /dev/null +++ b/.github/workflows/build-test-release.yml @@ -0,0 +1,208 @@ +# SPDX-FileCopyrightText: Contributors to the Power Grid Model project +# +# SPDX-License-Identifier: MPL-2.0 + + +name: Build, Test, Sonar + +on: + push: + branches: + - main + # run pipeline on pull request + pull_request: + # run pipeline on merge queue + merge_group: + # run pipeline from another workflow + workflow_call: + inputs: + create_release: + type: boolean + description: Create a (pre-)release when CI passes + default: false + required: false + # run this workflow manually from the Actions tab + workflow_dispatch: + inputs: + create_release: + type: boolean + description: Create a (pre-)release when CI passes + default: false + required: true + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }}-main + cancel-in-progress: true + +jobs: + + build-python: + runs-on: ubuntu-latest + outputs: + version: ${{ steps.version.outputs.version }} + steps: + + - name: Checkout source code + uses: actions/checkout@v4 + + - name: Setup Python 3.13 + uses: actions/setup-python@v5 + with: + python-version: "3.13" + + - name: Set PyPI version + uses: PowerGridModel/pgm-version-bump@main + with: + token: ${{ secrets.GITHUB_TOKEN }} + + - name: Build + run: | + cat PYPI_VERSION + pip install build + 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@v4 + with: + name: power-grid-model-io + path: wheelhouse/ + + sonar-cloud: + permissions: + contents: write + runs-on: ubuntu-latest + steps: + + - name: Checkout source code + uses: actions/checkout@v4 + with: + fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis + + - name: Setup Python 3.11 + uses: actions/setup-python@v5 + with: + python-version: "3.11" + + - name: Install in develop mode + run: | + pip install -e .[dev] + + - name: Test and Coverage + run: | + pytest + + # 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' python_coverage.xml + + - name: SonarCloud Scan + if: ${{ (github.event_name == 'push') || (github.event.pull_request.head.repo.owner.login == 'PowerGridModel') }} + uses: SonarSource/sonarqube-scan-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.11", "3.12"] + fail-fast: false + runs-on: ${{ matrix.os }} + + steps: + + - name: Checkout source code + uses: actions/checkout@v4 + + - name: Setup Python ${{ matrix.python }} + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python }} + + - name: Load built wheel file + uses: actions/download-artifact@v4 + 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.11", "3.12"] + fail-fast: false + runs-on: ${{ matrix.os }} + + steps: + + - name: Checkout source code + uses: actions/checkout@v4 + + - name: Setup Python ${{ matrix.python }} + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python }} + + - name: Load built wheel file + uses: actions/download-artifact@v4 + 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 + + github-release: + needs: + - build-python + - unit-tests + - validation-tests + - sonar-cloud + permissions: + contents: write + runs-on: ubuntu-latest + steps: + - name: Setup Python 3.13 + uses: actions/setup-python@v5 + with: + python-version: "3.13" + + - name: Load built wheel file + uses: actions/download-artifact@v4 + with: + name: power-grid-model-io + path: wheelhouse/ + + - name: Get tag + id: tag + run: echo "tag=v${{ needs.build-python.outputs.version }}" >> $GITHUB_OUTPUT + + - name: Display tag + run: echo "${{ steps.tag.outputs.tag }}" + + - name: Create GitHub release + if: (github.event_name == 'push') || ((github.event_name == 'workflow_dispatch') && (github.event.inputs.create_release == 'true')) + uses: softprops/action-gh-release@v2 + with: + files: | + ./wheelhouse/* + tag_name: "${{ steps.tag.outputs.tag }}" + prerelease: ${{github.ref != 'refs/heads/main'}} + generate_release_notes: true + target_commitish: ${{ github.sha }} diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 165246d0..69cf0219 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -35,177 +35,16 @@ concurrency: cancel-in-progress: true jobs: - - build-python: - runs-on: ubuntu-latest - outputs: - version: ${{ steps.version.outputs.version }} - steps: - - - name: Checkout source code - uses: actions/checkout@v4 - - - name: Setup Python 3.13 - uses: actions/setup-python@v5 - with: - python-version: "3.13" - - - name: Set PyPI version - uses: PowerGridModel/pgm-version-bump@main - with: - token: ${{ secrets.GITHUB_TOKEN }} - - - name: Build - run: | - cat PYPI_VERSION - pip install build - 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@v4 - with: - name: power-grid-model-io - path: wheelhouse/ - - sonar-cloud: + build-test-release: + name: build-test-release + uses: "./.github/workflows/build-test-release.yml" permissions: contents: write - runs-on: ubuntu-latest - steps: - - - name: Checkout source code - uses: actions/checkout@v4 - with: - fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis - - - name: Setup Python 3.11 - uses: actions/setup-python@v5 - with: - python-version: "3.11" - - - name: Install in develop mode - run: | - pip install -e .[dev] - - - name: Test and Coverage - run: | - pytest - - # 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' python_coverage.xml - - - name: SonarCloud Scan - if: ${{ (github.event_name == 'push') || (github.event.pull_request.head.repo.owner.login == 'PowerGridModel') }} - uses: SonarSource/sonarqube-scan-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.11", "3.12"] - fail-fast: false - runs-on: ${{ matrix.os }} - - steps: - - - name: Checkout source code - uses: actions/checkout@v4 - - - name: Setup Python ${{ matrix.python }} - uses: actions/setup-python@v5 - with: - python-version: ${{ matrix.python }} - - - name: Load built wheel file - uses: actions/download-artifact@v4 - 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.11", "3.12"] - fail-fast: false - runs-on: ${{ matrix.os }} - - steps: - - - name: Checkout source code - uses: actions/checkout@v4 - - - name: Setup Python ${{ matrix.python }} - uses: actions/setup-python@v5 - with: - python-version: ${{ matrix.python }} - - - name: Load built wheel file - uses: actions/download-artifact@v4 - 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 - - github-release: - needs: - - build-python - - unit-tests - - validation-tests - - sonar-cloud - permissions: - contents: write - runs-on: ubuntu-latest - steps: - - name: Setup Python 3.13 - uses: actions/setup-python@v5 - with: - python-version: "3.13" - - - name: Load built wheel file - uses: actions/download-artifact@v4 - with: - name: power-grid-model-io - path: wheelhouse/ - - - name: Get tag - id: tag - run: echo "tag=v${{ needs.build-python.outputs.version }}" >> $GITHUB_OUTPUT - - - name: Display tag - run: echo "${{ steps.tag.outputs.tag }}" - - - name: Create GitHub release - if: (github.event_name == 'push') || ((github.event_name == 'workflow_dispatch') && (github.event.inputs.create_release == 'true')) - uses: softprops/action-gh-release@v2 - with: - files: | - ./wheelhouse/* - tag_name: "${{ steps.tag.outputs.tag }}" - prerelease: ${{github.ref != 'refs/heads/main'}} - generate_release_notes: true - target_commitish: ${{ github.sha }} + with: + # create_release becomes true if the event that triggered this workflow is "workflow_dispatch" and inputs.create_release is true + # create_release becomes true if the event that triggered this workflow is "push" on main + # otherwise create_release becomes false + create_release: ${{ (github.event_name == 'workflow_dispatch' && inputs.create_release) || github.event_name == 'push'}} publish: name: Publish to PyPI diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml index d36882f0..d69e070b 100644 --- a/.github/workflows/nightly.yml +++ b/.github/workflows/nightly.yml @@ -16,7 +16,7 @@ concurrency: jobs: main: - uses: "./.github/workflows/ci.yml" + uses: "./.github/workflows/build-test-release.yml" permissions: contents: write with: