Update to the latest prettier version using pre-commit-mirror-maker #409
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
| name: Update to the latest prettier version using pre-commit-mirror-maker | |
| on: | |
| workflow_dispatch: | |
| push: | |
| branches: [main] | |
| schedule: | |
| - cron: "15 8 * * *" | |
| permissions: | |
| contents: write | |
| defaults: | |
| run: | |
| shell: bash | |
| jobs: | |
| build-main: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Install pre-commit-mirror-maker | |
| run: pip install pre-commit-mirror-maker | |
| - name: Adjust pre-commit-mirror-maker source code | |
| run: | | |
| $ErrorActionPreference = "Stop" | |
| $packageInfo = pip show pre-commit-mirror-maker | |
| $pythonPackageLocation = ($packageInfo -match 'Location: (.*)')[0].TrimStart('Location: ') | |
| $sourceFilePath = "$pythonPackageLocation/pre_commit_mirror_maker/languages.py" | |
| $sourceFileContent = Get-Content -Raw -Path $sourceFilePath | |
| if ($IsWindows) { | |
| # add missing shell flag (else it fails running npm command) | |
| $sourceFileContent = $sourceFileContent -replace 'subprocess\.check_output\(cmd\)', 'subprocess.check_output(cmd, shell=True)' | |
| } | |
| # filter pre release versions | |
| $sourceFileContent = $sourceFileContent -replace "return output\['versions'\]", "return [x for x in output['versions'] if not '-' in x]" | |
| Set-Content -Path $sourceFilePath -Value $sourceFileContent | |
| # remove the template files that we have overwritten with custom parameters | |
| Remove-Item -Path "$pythonPackageLocation/pre_commit_mirror_maker/node/.npmignore" -ErrorAction Ignore | |
| Remove-Item -Path "$pythonPackageLocation/pre_commit_mirror_maker/node/package.json" -ErrorAction Ignore | |
| shell: pwsh | |
| - name: Configure Git user so we can commit the changes | |
| run: | | |
| git config --local user.name 'Github Actions' | |
| git config --local user.email '41898282+github-actions[bot]@users.noreply.github.com' | |
| - name: Run pre-commit-mirror-maker | |
| run: | | |
| pre-commit-mirror \ | |
| . \ | |
| --language=node \ | |
| --package-name=prettier \ | |
| --types=text \ | |
| --id=prettier \ | |
| --entry "pre-commit-prettier --write --ignore-unknown --experimental-cli --no-cache" | |
| - name: Push the new version to repository (the tag and the commit with the changes) | |
| run: git push origin HEAD:refs/heads/main --tags |