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

Open
wants to merge 17 commits into
base: main
Choose a base branch
from

Conversation

mfranzke
Copy link
Collaborator

@mfranzke mfranzke commented May 28, 2025

Proposed changes

On prettier and stylelint 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:

"There are no checks for this commit"

This happens especially when:

  • The workflow is modifying and committing to the same branch it is running from.
  • The commit is made with a bot token (e.g., GITHUB_TOKEN), not a real user PAT (Personal Access Token).
  • The workflow uses default on: pull_request or on: push triggers.

🔍 Why It Happens

  1. 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.

  2. GITHUB_TOKEN behavior

    • Commits made using GITHUB_TOKEN don't trigger workflows on push or pull_request events unless explicitly configured.
    • This token is designed to avoid self-triggering behavior.
  3. Triggering logic specifics

    • If the new commit doesn’t change any files that affect workflow conditions, or if the workflow file was modified but is now identical, GitHub may skip re-running the pipeline.
    • Also, if there is no 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.

- name: Commit and push changes
  run: |
    git config user.name "your-username"
    git config user.email "your-email@example.com"
    git add .
    git commit -m "Automated update"
    git push https://<username>:${{ secrets.PAT }}@github.com/owner/repo.git HEAD:branch

⚠️ Do not hardcode the token — use secrets.PAT.

✅ Option 2: Use workflow_run to chain jobs

If 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: conditions

Ensure your workflow is triggered by both push and pull_request:

on:
  push:
    branches:
      - '**'
  pull_request:
    types: [opened, synchronize, reopened]

🔍 Optional: Debug with actions/github-script

Use actions/github-script to log what's happening with events and commits programmatically if needed.


✅ TL;DR

  • Yes, GitHub Actions can make commits that trigger further workflows.
  • But if you use GITHUB_TOKEN, GitHub suppresses those triggers by default to avoid loops.
  • Use a Personal Access Token if you want those commits to start new workflows.
  • Also ensure your workflows are listening for the right 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 or stylelint --fix), those would still need to be done manually obviously.

I've successfully tested it with db-ui/base@e3efcf0

Types of changes

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Refactoring (fix on existing components or architectural decisions)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation Update (if none of the other choices apply)

Further comments

for prettier and stylelint updates
@mfranzke mfranzke self-assigned this May 28, 2025
@mfranzke mfranzke requested a review from nmerget as a code owner May 28, 2025 09:24
@mfranzke mfranzke added 🍄🆙improvement New feature or request 🪩🔥🕺coolTopic some relevant topics, that we even also need to report in different rounds / to stakeholders labels May 28, 2025
Copy link
Contributor

@mfranzke mfranzke moved this to 👀 In review in UX Engineering Team Backlog May 28, 2025
@mfranzke mfranzke removed their assignment May 28, 2025
@github-actions github-actions bot added the 🚢📀cicd Changes inside .github folder label May 28, 2025
@mfranzke mfranzke enabled auto-merge (squash) May 28, 2025 13:00
@mfranzke mfranzke requested a review from Copilot May 28, 2025 13:00
Copy link
Contributor

@Copilot Copilot AI left a 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"

@mfranzke mfranzke requested a review from nmerget May 30, 2025 09:17
@mfranzke mfranzke requested a review from Copilot May 30, 2025 15:15
Copy link
Contributor

@Copilot Copilot AI left a 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"

@mfranzke mfranzke requested review from nmerget and removed request for nmerget June 2, 2025 13:07
@mfranzke mfranzke moved this from 👀 In review to 🏗 In development in UX Engineering Team Backlog Jun 11, 2025
@mfranzke mfranzke self-assigned this Jun 11, 2025
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
Copy link
Collaborator

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?

Copy link
Collaborator Author

@mfranzke mfranzke Jun 12, 2025

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
Copy link
Collaborator

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.

Copy link
Collaborator Author

@mfranzke mfranzke Jun 12, 2025

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 ?

Comment on lines 50 to 51
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

Potential injection from the ${{ github.head_ref }}, which may be controlled by an external user.

Copilot Autofix

AI 3 days ago

To fix the issue, we will:

  1. Assign the value of github.head_ref to an intermediate environment variable.
  2. Use the environment variable in the shell command with native shell syntax (e.g., $VAR) instead of direct interpolation (${{ ... }}).
  3. 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.


Suggested changeset 1
.github/actions/auto-commit/action.yml

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/.github/actions/auto-commit/action.yml b/.github/actions/auto-commit/action.yml
--- a/.github/actions/auto-commit/action.yml
+++ b/.github/actions/auto-commit/action.yml
@@ -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."
 
EOF
@@ -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."

Copilot is powered by AI and may make mistakes. Always verify output.
@nmerget nmerget committed this autofix suggestion 3 days ago.
…Actions

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🚢📀cicd Changes inside .github folder 🪩🔥🕺coolTopic some relevant topics, that we even also need to report in different rounds / to stakeholders 🍄🆙improvement New feature or request
Projects
Status: 🏗 In development
Development

Successfully merging this pull request may close these issues.

2 participants