Refresh linter dependencies #1
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: Refresh linter dependencies | |
| on: | |
| workflow_call: | |
| inputs: | |
| create-pr: | |
| type: boolean | |
| description: "Whether to create a pull request with the changes" | |
| required: false | |
| default: false | |
| workflow_dispatch: | |
| inputs: | |
| create-pr: | |
| type: boolean | |
| description: "Whether to create a pull request with the changes" | |
| required: false | |
| default: false | |
| schedule: | |
| - cron: "0 2 * * 1" # Every Monday at 2:00 UTC | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.ref }}-linter-dependencies | |
| cancel-in-progress: true | |
| jobs: | |
| refresh-lock-and-linter-dependencies: | |
| name: Refresh linter dependencies | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0 | |
| - name: update npm packages | |
| run: | | |
| npm update | |
| - name: retrieve npm development package versions | |
| id: versions_npm | |
| run: | | |
| grab_installed_version_npm() { | |
| local pkg="$1" | |
| local nospecialchars_pkg | |
| local version | |
| # remove characters `@` and `/` | |
| nospecialchars_pkg=$(echo $pkg | tr -d '@/') | |
| version=$(npm ls --json --package-lock-only $pkg | grep -i '"version": ' | cut -d\" -f4) | |
| echo "${nospecialchars_pkg}=$version" >> "$GITHUB_OUTPUT" | |
| } | |
| grab_installed_version_npm "@biomejs/biome" | |
| grab_installed_version_npm "markdownlint-cli" | |
| - name: Update .pre-commit-config.yaml | |
| uses: cuchi/jinja2-action@8bd801365a8d36a0b20f45ee969161685de7785a # v1.3.0 | |
| with: | |
| template: .pre-commit-config.yaml.jinja | |
| output_file: .pre-commit-config.yaml | |
| variables: | | |
| biome=${{ steps.versions_npm.outputs.biomejsbiome }} | |
| markdownlint_cli=${{ steps.versions_npm.outputs.markdownlint-cli }} | |
| - name: show changed files | |
| run: | | |
| git status | |
| git diff .pre-commit-config.yaml | |
| - name: try to install pre-commit | |
| run: | | |
| source .venv/bin/activate | |
| pre-commit install | |
| pre-commit install-hooks | |
| pre-commit uninstall | |
| - name: generate GitHub App token | |
| uses: actions/create-github-app-token@bcd2ba49218906704ab6c1aa796996da409d3eb1 # v3.2.0 | |
| id: generate-token | |
| with: | |
| app-id: ${{ secrets.CI_BOT_APP_ID }} | |
| private-key: ${{ secrets.CI_BOT_PRIVATE_KEY }} | |
| - name: create pull request | |
| if: ${{ inputs.create-pr || github.event_name == 'schedule' }} | |
| uses: peter-evans/create-pull-request@5f6978faf089d4d20b00c7766989d076bb2fc7f1 # v8.1.1 | |
| with: | |
| commit-message: "Refresh linter dependencies" | |
| branch: "dependencies/refresh-linter-dependencies" | |
| title: "Refresh linter dependencies" | |
| body: "This PR refreshes the linter dependencies to their latest versions." | |
| labels: "dependencies" | |
| signoff: true | |
| sign-commits: true | |
| delete-branch: true | |
| base: ${{ github.head_ref }} | |
| token: ${{ steps.generate-token.outputs.token }} |