diff --git a/.github/workflows/99-auto-format-dependabot-prettier-updates.yml b/.github/workflows/99-auto-format-dependabot-prettier-updates.yml new file mode 100644 index 0000000000..c83c14c484 --- /dev/null +++ b/.github/workflows/99-auto-format-dependabot-prettier-updates.yml @@ -0,0 +1,50 @@ +name: Auto-Format with Prettier on PR for "self-healing" PRs + +on: + workflow_call: + +jobs: + format: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + ref: ${{github.event.pull_request.head.ref}} + fetch-depth: 0 + + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + node-version-file: '.nvmrc' + + - name: Install dependencies + run: | + npm ci + + - name: Check if Prettier update PR + id: check_pr + run: | + echo "PR title: ${{ github.event.pull_request.title }}" + if [[ "${{ github.event.pull_request.title }}" =~ "bump prettier from" ]]; then + echo "Prettier update detected." + echo "prettier_update=true" >> $GITHUB_ENV + else + echo "No Prettier update detected." + echo "prettier_update=false" >> $GITHUB_ENV + fi + + - name: Run Prettier to format the code + if: env.prettier_update == 'true' + run: | + npx --no prettier . --write + + - name: Commit changes if formatting is done + if: env.prettier_update == 'true' + run: | + git config --global user.name 'github-actions[bot]' + git config --global user.email 'github-actions[bot]@users.noreply.github.com' + + git add . + git commit --all -m "Auto-format codebase with Prettier" || echo "No changes to commit" + git push origin HEAD:${{ github.head_ref }} # Push back to the same PR branch diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 64a996e358..134d8322a0 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -15,6 +15,9 @@ jobs: auto-merge: uses: ./.github/workflows/99-auto-merge.yml + dependabot-prettier-self-healing: + uses: ./.github/workflows/99-auto-format-dependabot-prettier-updates.yml + codeql: uses: ./.github/workflows/99-codeql-analysis.yml diff --git a/package-lock.json b/package-lock.json index 807406d212..026ae06377 100644 --- a/package-lock.json +++ b/package-lock.json @@ -46,7 +46,7 @@ "postcss-cli": "^11.0.1", "postcss-focus": "^7.0.0", "postcss-list-style-safari-fix": "^1.0.0", - "prettier": "^3.4.2", + "prettier": "^3.5.3", "rimraf": "^6.0.1", "sass": "^1.87.0", "start-server-and-test": "^2.0.11", @@ -16136,10 +16136,11 @@ } }, "node_modules/prettier": { - "version": "3.4.2", - "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.4.2.tgz", - "integrity": "sha512-e9MewbtFo+Fevyuxn/4rrcDAaq0IYxPGLvObpQjiZBMAzB9IGmzlnG9RZy3FFas+eBMu2vA0CszMeduow5dIuQ==", + "version": "3.5.3", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.5.3.tgz", + "integrity": "sha512-QQtaxnoDJeAkDvDKWCLiwIXkTgRhwYDEQCghU9Z6q03iyek/rxRh/2lC3HB7P8sWT2xC/y5JDctPLBIGzHKbhw==", "dev": true, + "license": "MIT", "bin": { "prettier": "bin/prettier.cjs" }, @@ -31794,9 +31795,9 @@ "dev": true }, "prettier": { - "version": "3.4.2", - "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.4.2.tgz", - "integrity": "sha512-e9MewbtFo+Fevyuxn/4rrcDAaq0IYxPGLvObpQjiZBMAzB9IGmzlnG9RZy3FFas+eBMu2vA0CszMeduow5dIuQ==", + "version": "3.5.3", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.5.3.tgz", + "integrity": "sha512-QQtaxnoDJeAkDvDKWCLiwIXkTgRhwYDEQCghU9Z6q03iyek/rxRh/2lC3HB7P8sWT2xC/y5JDctPLBIGzHKbhw==", "dev": true }, "prettier-linter-helpers": { diff --git a/package.json b/package.json index 8ae2a2d4ad..806c6252b2 100644 --- a/package.json +++ b/package.json @@ -94,7 +94,7 @@ "postcss-cli": "^11.0.1", "postcss-focus": "^7.0.0", "postcss-list-style-safari-fix": "^1.0.0", - "prettier": "^3.4.2", + "prettier": "^3.5.3", "rimraf": "^6.0.1", "sass": "^1.87.0", "start-server-and-test": "^2.0.11",