Skip to content

feat: self healing dependabot updates #4292

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 21 commits into from
Jun 25, 2025
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
dc81a5a
feat: self healing dependabot updates
mfranzke May 28, 2025
6016a8e
Create 99-self-healing-dependabot-updates.yml
mfranzke May 28, 2025
b7d9cc2
Merge branch 'main' into feat-self-healing-dependabot-updates
mfranzke May 28, 2025
2e60968
Update 99-self-healing-dependabot-updates.yml
mfranzke May 28, 2025
16af60f
Update 99-self-healing-dependabot-updates.yml
mfranzke May 30, 2025
23666c7
Update 99-self-healing-dependabot-updates.yml
mfranzke May 30, 2025
9d52c9e
Update package.json
mfranzke May 30, 2025
f0d4193
Merge branch 'main' into feat-self-healing-dependabot-updates
mfranzke May 30, 2025
157d49f
Merge branch 'main' into feat-self-healing-dependabot-updates
mfranzke Jun 2, 2025
3fae29d
Update 99-self-healing-dependabot-updates.yml
mfranzke Jun 2, 2025
7db5853
Update 99-self-healing-dependabot-updates.yml
mfranzke Jun 11, 2025
ffa5d87
Update pull-request.yml
mfranzke Jun 11, 2025
84c207e
Update .github/workflows/99-self-healing-dependabot-updates.yml
mfranzke Jun 11, 2025
85e5d49
Merge branch 'main' into feat-self-healing-dependabot-updates
nmerget Jun 12, 2025
879d5a5
refactor: moved auto-commit to own composite action
nmerget Jun 12, 2025
9807ba6
chore: run fmt
nmerget Jun 12, 2025
7988041
Potential fix for code scanning alert no. 9: Expression injection in …
nmerget Jun 18, 2025
eb913c3
Merge remote-tracking branch 'origin/main' into feat-self-healing-dep…
nmerget Jun 25, 2025
e5a9ee3
Merge branch 'main' into feat-self-healing-dependabot-updates
nmerget Jun 25, 2025
4cd1a54
Potential fix for code scanning alert no. 10: Expression injection in…
nmerget Jun 25, 2025
d94f654
Merge branch 'main' into feat-self-healing-dependabot-updates
nmerget Jun 25, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 91 additions & 0 deletions .github/workflows/99-self-healing-dependabot-updates.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
name: Auto-Format with Stylelint and Prettier on PR for "self-healing" PRs

on:
workflow_call:

jobs:
format:
if: ${{ github.actor == 'dependabot[bot]' }}
runs-on: ubuntu-24.04 # Use Ubuntu 24.04 explicitly
permissions:
contents: write
pull-requests: write
env:
NEW_PR_BRANCH: "${{ github.head_ref }}-auto"
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}

- name: Check if Stylelint or Prettier update PR
id: check_pr
run: |
echo "PR title: ${{ github.event.pull_request.title }}"
if [[ "${{ github.event.pull_request.title }}" =~ "bump stylelint from" ]]; then
echo "Stylelint update detected."
echo "stylelint_update=true" >> $GITHUB_ENV
elif [[ "${{ github.event.pull_request.title }}" =~ "bump prettier from" ]]; then
echo "Prettier update detected."
echo "prettier_update=true" >> $GITHUB_ENV
else
echo "No Stylelint or prettier updates detected."
fi

- name: Set up Node.js
if: env.stylelint_update == 'true' || env.prettier_update == 'true'
uses: actions/setup-node@v4
with:
node-version-file: ".nvmrc"

- name: Install dependencies
if: env.stylelint_update == 'true' || env.prettier_update == 'true'
run: |
npm ci

- name: Run Stylelint to format the code
if: env.stylelint_update == 'true'
run: |
npm run lint:stylelint --fix

- name: Run Prettier to format the code
if: env.prettier_update == 'true'
run: |
npx --no prettier . --write

# https://docs.github.com/en/apps/creating-github-apps/authenticating-with-a-github-app/making-authenticated-api-requests-with-a-github-app-in-a-github-actions-workflow
- name: 🧬 Generate a token
if: env.stylelint_update == 'true' || env.prettier_update == 'true'
id: generate-token
uses: actions/create-github-app-token@v2
with:
app-id: ${{ vars.AUTO_MERGE_APP_ID }}
private-key: ${{ secrets.AUTO_MERGE_PRIVATE_KEY }}

- name: 🏗️ Create new branch and commit changes
if: env.stylelint_update == 'true' || env.prettier_update == 'true'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"

git checkout -b "$NEW_PR_BRANCH"
git add .

# We can't use semantic commits here because of the if statement in the workflow
git commit --no-verify --all -m "auto format code" || echo "No changes to commit"
git push -f origin "$NEW_PR_BRANCH"

- name: 🪗 Create Pull Request
if: env.stylelint_update == 'true' || env.prettier_update == 'true'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh pr create --base ${{ github.head_ref }} --head "$NEW_PR_BRANCH" --title "Automated PR: Auto update snapshots" --body "This PR was created automatically by a GitHub Action."

- name: 🤖 Squash the PR
if: env.stylelint_update == 'true' || env.prettier_update == 'true'
run: gh pr merge --squash "$NEW_PR_BRANCH"
env:
GITHUB_TOKEN: ${{ steps.generate-token.outputs.token }}
4 changes: 4 additions & 0 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ jobs:
dependabot:
uses: ./.github/workflows/99-auto-merge.yml

self-healing-dependabot-updates:
uses: ./.github/workflows/99-self-healing-dependabot-updates.yml
secrets: inherit

codeql:
uses: ./.github/workflows/99-codeql-analysis.yml

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"lint": "npm-run-all -p lint:*",
"lint:jscpd": "jscpd . --exitCode 1 --config .config/.jscpd.json",
"lint:markdownlint": "markdownlint -c .config/.markdown-lint.yml **/*.md",
"lint:stylelint": "stylelint **/*.scss",
"lint:stylelint": "stylelint **/*.{css,scss}",
"lint:xo": "cross-env TIMING=1 NODE_OPTIONS=\"--max-old-space-size=4096\" xo",
"prepare": "husky",
"regenerate:screenshots": "npm run build && npm run build --workspace=react-showcase && docker-compose -f ./e2e/docker-compose.regenerate.yml up",
Expand Down
Loading