Skip to content

CIS-3816 Audit workflow - #11

Merged
saligiad merged 5 commits into
mainfrom
CIS-3816
Aug 5, 2026
Merged

CIS-3816 Audit workflow#11
saligiad merged 5 commits into
mainfrom
CIS-3816

Conversation

@saligiad

@saligiad saligiad commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Overview

Create a shared workflow to npm audit fix:

  • Creates branch, commits the dependency changes, and opens a PR
  • Parameterizes branch name, commit title, and cleanup behavior for different use cases
    • By default, cleans up branches with the same name and associated PRs

Currently, workflow fails if npm audit fix returns non-zero exit code

  • meaning PRs will not be created for breaking changes or conflicts in dependency resolution.

Issues

CIS-3816

[x] Added to CHANGELOG.md

Discussion

I'll leave some more specific points as comments in the code, but the main idea here is that the primary use case is a cron-based dispatch in the project workflow files (with a few things parameterized to support other use cases).

Create a shared workflow to `npm audit fix`:

* Creates branch, commits the dependency changes, and opens a PR
* Parameterizes branch name, commit title, and cleanup behavior for
  different use cases
  * By default, cleans up branches with the same name and associated PRs

Currently, workflow fails if `npm audit fix` returns non-zero exit code
- meaning PRs will not be created for breaking changes or conflicts in
  dependency resolution.
Reference new workflow file in CHANGELOG.md
Adds `content: write` to the job permissions, allowing the workflow to
push branch deletion to the main repo.
Comment thread .github/workflows/node-audit.yaml Outdated
Comment on lines +20 to +24
cleanup_previous:
description: Whether to cleanup unresolved PR/branch and start over
type: boolean
required: false
default: true

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This controls the execution of step that looks for a branch name conflict, locates and deletes the associated PR (if present) then deletes the branch. This seemed like desirable behavior if this is going to run on some kind of schedule - but that it might also be nice to be able to switch that behavior off in certain use cases.

Including it as a parameter has the added benefit of increasing the visibility of a pretty impactful side-effect of the workflow.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't think of a reason to want the workflow to leave obsolete PRs and stale branches in the repository. What did you have in mind?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The discussion of failure modes in README.md indicates that the workflow will just fail if cleanup_previous is false and the branch already exists. If that's true, this option is a bit of a footgun, and I'm inclined to eliminate it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I was writing the workflow, I had some half-formed idea that this could be useful - but I'm having a hard time coming up with a concrete use case. If we want to trigger this from another workflow, we should just be able to specify a non-conflicting branch name and avoid issues - so I'm happy to remove this until a use case becomes clear.

Comment on lines +47 to +54
echo "AUDIT_REPORT<<EOF" >> "$GITHUB_OUTPUT"
npm audit fix &>> "$GITHUB_OUTPUT"
echo "EOF" >> "$GITHUB_OUTPUT"
if [ -n "$(git status --porcelain)" ]; then
echo "CHANGED=true" >> "$GITHUB_OUTPUT"
else
echo "CHANGED=false" >> "$GITHUB_OUTPUT"
fi

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I picked up a couple tricks from AI suggestions:

  • Capturing the npm output in AUDIT_REPORT allows me to use that in the PR body, and
  • Establising a CHANGED output flag lets me skip most of the rest of the job the package files were not changed

Comment thread .github/workflows/node-audit.yaml Outdated
git config --global user.name "github-actions[bot]"

- name: Clean up previous branch/PR
if: ${{ inputs.cleanup_previous }}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the only step after audit-step that isn't gated by the CHANGED flag. Since we may occasionally update these dependencies manually, it seems useful for the workflow to clean up old PRs - even if we aren't creating a new one.

@saligiad
saligiad marked this pull request as ready for review August 4, 2026 21:16
@saligiad
saligiad requested a review from heathharrelson August 4, 2026 21:22
Comment thread .github/workflows/node-audit.yaml Outdated
description: Text for the title line of the git commit
type: string
required: false
default: 'chore: Node security update'

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Except for Erik (because of habit from AI-READI), we don't typically use the conventional commits labels. Any particular reason you picked this default?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a particularly strong reason. I believe I'd seen it used in a few places and examples on the web, and my brain found it natural to try and substitute something in the place where we typically place the ticket number. I'm happy to shorten this to "Node security update", or whatever would most fit with the team conventions.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think "Node security update" is fine. I just don't want to adopt conventional commits without agreement from the whole team.

@heathharrelson heathharrelson left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! I'm curious to see how this works in practice.

Incorporate feedback from the PR:

* Simplify commit message default
* Remove `cleanup_previous` flag, given absense of compelling use case
Ensure that git user/email are setup, regardless of whether files have
changed, because the workflow will always attempt to cleanup previous
PRs.
@saligiad
saligiad merged commit a256b0a into main Aug 5, 2026
@saligiad
saligiad deleted the CIS-3816 branch August 5, 2026 15:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants