-
Notifications
You must be signed in to change notification settings - Fork 10
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
base: main
Are you sure you want to change the base?
Conversation
for prettier and stylelint updates
🔭🐙🐈 Test this branch here: https://db-ux-design-system.github.io/core-web/review/feat-self-healing-dependabot-updates |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR introduces a new self-healing pipeline for Dependabot updates related to Prettier and Stylelint so that code formatting issues are automatically fixed after dependency updates. The key changes include:
- Adding a new workflow (self-healing-dependabot-updates) in the pull-request pipeline.
- Implementing conditional steps to identify, format, commit, and push code changes based on the PR title.
- Configuring Node.js, dependency installation, and commit steps within the new workflow.
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
File | Description |
---|---|
.github/workflows/pull-request.yml | Adds a new job to trigger the self-healing dependabot updates workflow. |
.github/workflows/99-self-healing-dependabot-updates.yml | Implements the self-healing logic with formatting, commit, and push steps. |
Comments suppressed due to low confidence (1)
.github/workflows/99-self-healing-dependabot-updates.yml:59
- [nitpick] The commit message 'refactor(test): auto-format codebase' may be confusing since the update only performs code formatting. Consider revising the commit message to better reflect that it's an auto-format commit.
git commit --all -m "refactor(test): auto-format codebase" || echo "No changes to commit"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds an automated self-healing mechanism to handle formatting updates triggered by dependabot PRs for stylelint and prettier. Key changes include updating the stylelint linting pattern in package.json, integrating a new job into pull-request.yml, and adding a dedicated workflow to auto-format updated code.
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
File | Description |
---|---|
package.json | Updates lint:stylelint command to target both CSS and SCSS files. |
.github/workflows/pull-request.yml | Introduces a self-healing dependabot updates job in the PR pipeline. |
.github/workflows/99-self-healing-dependabot-updates.yml | Adds a workflow to auto-format code using stylelint and prettier on PRs. |
Comments suppressed due to low confidence (1)
.github/workflows/99-self-healing-dependabot-updates.yml:60
- Consider using a more appropriate commit type (e.g., 'chore') instead of 'refactor(test)' for auto-format commits, as it may be misleading about the nature of the changes.
git commit --all -m "refactor(test): auto-format codebase" || echo "No changes to commit"
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it makes sense to move the part below into a custom action to use it for every auto-commit in our repo.
It would be an additional advantage because you could use the if: env.stylelint_update == 'true' || env.prettier_update == 'true'
once. Would you like to do it or should I help you?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nmerget I like this idea, and the latter, please.
# env: | ||
# GITHUB_CONTEXT: ${{ toJson(github) }} | ||
# run: echo "$GITHUB_CONTEXT" | ||
- name: 🚮 Dump GitHub context for debugging |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mfranzke I would keep this always inside the pipeline. We don't like to uncommet/comment it every time we debug.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was a comment by GitHub Copilot that sharing the full content of this variable might leak internal information. As the logs are public, this might be a valid aspect. Is there a non-public-space we could pass the output to ?
run: | | ||
gh pr create --base ${{ github.head_ref }} --head "$NEW_PR_BRANCH" --title "Automated PR: $COMMIT_MESSAGE" --body "This PR was created automatically by a GitHub Action." |
Check failure
Code scanning / CodeQL
Expression injection in Actions Critical
This autofix suggestion was applied.
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 3 days ago
To fix the issue, we will:
- Assign the value of
github.head_ref
to an intermediate environment variable. - Use the environment variable in the shell command with native shell syntax (e.g.,
$VAR
) instead of direct interpolation (${{ ... }}
). - This approach ensures that the value is treated as a literal string by the shell, preventing command injection.
The changes will be made in the .github/actions/auto-commit/action.yml
file, specifically in the step where gh pr create
is executed.
-
Copy modified lines R51-R52
@@ -50,3 +50,4 @@ | ||
run: | | ||
gh pr create --base ${{ github.head_ref }} --head "$NEW_PR_BRANCH" --title "Automated PR: $COMMIT_MESSAGE" --body "This PR was created automatically by a GitHub Action." | ||
BASE_BRANCH="${{ github.head_ref }}" | ||
gh pr create --base "$BASE_BRANCH" --head "$NEW_PR_BRANCH" --title "Automated PR: $COMMIT_MESSAGE" --body "This PR was created automatically by a GitHub Action." | ||
|
…Actions Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Proposed changes
On
prettier
andstylelint
dependency updates the codestyles might have changed so that the pipelines would initially fail and someone would need to run those linter/code formatters to transform the codebase to the new codestyles. Instead of doing this manually it would be nice to have a "self-healing" pipeline.The only remaining step at the moment would be to retrigger the pipeline again, as GitHub wouldn't allow a pipeline run to get triggered after the pipeline has commited changed code (like in this case).
ChatGPTs answer on why the pipeline wouldn't run after a commit by the pipeline itself
You're running into a known and nuanced behavior of GitHub Actions.
✅ Summary of the Issue
When you push a commit to a Pull Request branch from within a GitHub Actions workflow, GitHub cancels the current workflow (as expected) and starts a new one, but sometimes the new one does not run any jobs and just says:
This happens especially when:
GITHUB_TOKEN
), not a real user PAT (Personal Access Token).on: pull_request
oron: push
triggers.🔍 Why It Happens
Workflow-trigger loop prevention
GitHub has safety logic to prevent infinite CI loops. If a workflow pushes a commit back to the same branch (or PR) it's running from, GitHub may choose not to trigger a new workflow, especially if the commit came from a GitHub Action itself.
GITHUB_TOKEN
behaviorGITHUB_TOKEN
don't trigger workflows onpush
orpull_request
events unless explicitly configured.Triggering logic specifics
on: push
event configured, and you're committing directly to a branch, nothing may run.🛠 How to Fix It
✅ Option 1: Use a Personal Access Token (PAT)
Replace
GITHUB_TOKEN
with a PAT from a GitHub user with permission. This allows the commit to trigger workflows as if it were from a real developer.✅ Option 2: Use
workflow_run
to chain jobsIf you want to chain workflows after a commit, use
workflow_run
to explicitly start a second workflow after the first completes.✅ Option 3: Modify
on:
conditionsEnsure your workflow is triggered by both
push
andpull_request
:🔍 Optional: Debug with
actions/github-script
Use
actions/github-script
to log what's happening with events and commits programmatically if needed.✅ TL;DR
GITHUB_TOKEN
, GitHub suppresses those triggers by default to avoid loops.on:
events.Let me know if you want a code example or help setting up a PAT securely.
Additionally some problems wouldn't be auto-fixable (by
prettier --write
orstylelint --fix
), those would still need to be done manually obviously.I've successfully tested it with db-ui/base@e3efcf0
Types of changes
Further comments