Sync version of upstream repository #506
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 <powergridmodel@lfenergy.org> | |
| # | |
| # SPDX-License-Identifier: MPL-2.0 | |
| name: Sync version of upstream repository | |
| on: | |
| workflow_dispatch: | |
| schedule: | |
| - cron: "0 2 * * *" # Based on UTC time | |
| jobs: | |
| sync-version: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: generate GitHub App token | |
| uses: actions/create-github-app-token@bcd2ba49218906704ab6c1aa796996da409d3eb1 # v3.2.0 | |
| id: generate-token | |
| with: | |
| client-id: ${{ secrets.CI_BOT_APP_ID }} | |
| private-key: ${{ secrets.CI_BOT_PRIVATE_KEY }} | |
| repositories: ${{ github.repository }} | |
| permission-contents: write | |
| permission-pull-requests: write | |
| - name: Checkout repository | |
| uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | |
| with: | |
| token: ${{ steps.generate-token.outputs.token }} | |
| - id: get-release | |
| uses: pozetroninc/github-action-get-latest-release@2a61c339ea7ef0a336d1daa35ef0cb1418e7676c # v0.8.0 | |
| with: | |
| owner: PowerGridModel | |
| repo: power-grid-model | |
| excludes: prerelease, draft | |
| - name: Verify upstream immutable release | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| run: | | |
| gh release verify ${{ steps.get-release.outputs.release }} \ | |
| --repo PowerGridModel/power-grid-model | |
| continue-on-error: false # explicitly fail the workflow if the release is not verified | |
| - id: get-sha256 | |
| name: Download and hash | |
| run: | | |
| wget https://github.com/PowerGridModel/power-grid-model/archive/refs/tags/${{ steps.get-release.outputs.release }}.tar.gz | |
| echo "sha256=$(shasum -a 256 ${{ steps.get-release.outputs.release }}.tar.gz | awk '{print $1}')" >> "$GITHUB_OUTPUT" | |
| - name: Render formulae | |
| uses: cuchi/jinja2-action@8bd801365a8d36a0b20f45ee969161685de7785a # v1.3.0 | |
| with: | |
| template: formula_generation/power-grid-model.rb.jinja | |
| output_file: Formula/power-grid-model.rb | |
| variables: | | |
| tag=${{ steps.get-release.outputs.release }} | |
| sha256=${{ steps.get-sha256.outputs.sha256 }} | |
| - name: Show diff | |
| run: | | |
| git diff | |
| - name: Ensure only formula changes are auto-committed | |
| run: | | |
| changed_files=$(git diff --name-only) | |
| if [ -z "$changed_files" ]; then | |
| exit 0 | |
| fi | |
| non_formula_changes=$(echo "$changed_files" | grep -v '^Formula/power-grid-model.rb$' || true) | |
| if [ -n "$non_formula_changes" ]; then | |
| echo "Unexpected changed files:" | |
| echo "$non_formula_changes" | |
| echo "Template or workflow changes must go through a regular PR review." | |
| exit 1 | |
| fi | |
| - name: Validate formula | |
| uses: ./.github/actions/validate-formula | |
| - name: create pull request | |
| uses: peter-evans/create-pull-request@5f6978faf089d4d20b00c7766989d076bb2fc7f1 # v8.1.1 | |
| with: | |
| commit-message: "Sync version" | |
| branch: "sync-version" | |
| title: "Sync version of upstream repository" | |
| body: "This PR updates the formula to match the latest version of the upstream repository." | |
| labels: "sync-version" | |
| signoff: true | |
| sign-commits: true | |
| delete-branch: true | |
| base: ${{ github.head_ref }} | |
| token: ${{ steps.generate-token.outputs.token }} |