ci: fix release #119
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # SPDX-FileCopyrightText: Contributors to the Power Grid Model project <[email protected]> | |
| # | |
| # SPDX-License-Identifier: MPL-2.0 | |
| name: CI/CD | |
| on: | |
| push: | |
| branches: | |
| - main # run pipeline on pull request | |
| pull_request: | |
| workflow_dispatch: # run this workflow manually from the Actions tab | |
| inputs: | |
| create_release: | |
| type: boolean | |
| description: Create a release (only works on main branch) | |
| default: false | |
| required: true | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.ref }}-ci-build | |
| cancel-in-progress: true | |
| jobs: | |
| ci-started: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - run: echo "ci started" | |
| build-python: | |
| if: ${{ github.event_name == 'workflow_dispatch' && github.ref == 'refs/heads/main' && inputs.create_release }} | |
| runs-on: ubuntu-latest | |
| outputs: | |
| version: ${{ steps.version.outputs.version }} | |
| steps: | |
| - name: Checkout source code | |
| uses: actions/checkout@v5 | |
| - name: Install uv | |
| uses: astral-sh/setup-uv@v6 | |
| if: ${{ always() }} | |
| with: | |
| activate-environment: true | |
| enable-cache: true | |
| - name: Install dependencies | |
| if: ${{ always() }} | |
| run: uv sync --frozen | |
| - name: Set PyPI version | |
| uses: PowerGridModel/pgm-version-bump@main | |
| with: | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Save version | |
| id: version | |
| run: echo "version=$(cat PYPI_VERSION)" >> $GITHUB_OUTPUT | |
| - name: Build | |
| run: | | |
| uv build | |
| - name: Store built wheel file | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: power-grid-model-ds | |
| path: dist/ | |
| tests: | |
| if: ${{ github.event_name == 'workflow_dispatch' && github.ref == 'refs/heads/main' && inputs.create_release }} | |
| needs: build-python | |
| strategy: | |
| matrix: | |
| os: [ ubuntu-latest, macos-latest, windows-latest ] | |
| python: ["3.11", "3.12", "3.13"] | |
| fail-fast: false | |
| runs-on: ${{ matrix.os }} | |
| steps: | |
| - name: Checkout source code | |
| uses: actions/checkout@v5 | |
| - name: Install uv | |
| uses: astral-sh/setup-uv@v6 | |
| if: ${{ always() }} | |
| with: | |
| activate-environment: true | |
| enable-cache: true | |
| - name: install poe | |
| run: uv tool install poethepoet | |
| - name: Load built wheel file | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: power-grid-model-ds | |
| path: dist/ | |
| - name: Install built wheel file | |
| run: uv pip install power-grid-model-ds[dev]==${{ needs.build-python.outputs.version }} --find-links=dist | |
| - name: Run All Code Quality Checks & Tests | |
| run: poe all --check | |
| github-release: | |
| if: ${{ github.event_name == 'workflow_dispatch' && github.ref == 'refs/heads/main' && inputs.create_release }} | |
| needs: | |
| - build-python | |
| - tests | |
| permissions: | |
| contents: write | |
| runs-on: ubuntu-latest | |
| outputs: | |
| tag: ${{ steps.tag.outputs.tag }} | |
| steps: | |
| - name: Checkout source code | |
| uses: actions/checkout@v5 | |
| - name: Load built wheel file | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: power-grid-model-ds | |
| path: dist/ | |
| - name: Prevent automatic major/minor release | |
| run: | | |
| echo "Fetching the latest release..." | |
| tag=$(gh release view --json tagName --jq '.tagName' || echo "v0.0.0") | |
| tag=${tag#v} # Remove the leading 'v' | |
| major_minor=$(echo "$tag" | cut -d. -f1,2) | |
| version_file=$(cat VERSION) | |
| if [ "$major_minor" = "$version_file" ]; then | |
| echo "Patch release detected. Proceeding with automatic release." | |
| else | |
| echo "Cannot automatically release a new major/minor version. Please trigger manually if desired." | |
| exit 1 | |
| fi | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - 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: Release | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| files: | | |
| ./dist/* | |
| tag_name: ${{ steps.tag.outputs.tag }} | |
| generate_release_notes: true | |
| target_commitish: ${{ github.sha }} | |
| publish: | |
| name: Publish to PyPI | |
| if: ${{ github.event_name == 'workflow_dispatch' && github.ref == 'refs/heads/main' && inputs.create_release }} | |
| needs: github-release | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| id-token: write # Required for Trusted Publishing | |
| steps: | |
| - name: Download assets from latest GitHub release using gh CLI | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| mkdir -p assets-to-publish | |
| release_tag="${{ needs.github-release.outputs.tag }}" | |
| gh release download "$release_tag" --repo "$GITHUB_REPOSITORY" --dir assets-to-publish | |
| - name: List downloaded assets | |
| run: ls -la assets-to-publish | |
| - name: Upload assets to PyPI | |
| uses: pypa/gh-action-pypi-publish@release/v1 | |
| with: | |
| # To test, use the TestPyPI: | |
| # repository-url: https://test.pypi.org/legacy/ | |
| # You must also create an account and project on TestPyPI, | |
| # as well as set the trusted-publisher in the project settings: | |
| # https://docs.pypi.org/trusted-publishers/adding-a-publisher/ | |
| # To publish to the official PyPI repository, just keep | |
| # repository-url commented out. | |
| packages-dir: assets-to-publish | |
| skip-existing: true | |
| print-hash: true | |
| verbose: true | |
| check-code-quality: | |
| uses: "./.github/workflows/check-code-quality.yml" | |
| reuse-compliance: | |
| uses: "./.github/workflows/reuse-compliance.yml" |