Skip to content

feat: Add automated GitHub Actions pinning workflow#187

Draft
hoegertn wants to merge 11 commits intomainfrom
claude/implement-issue-186-wABh9
Draft

feat: Add automated GitHub Actions pinning workflow#187
hoegertn wants to merge 11 commits intomainfrom
claude/implement-issue-186-wABh9

Conversation

@hoegertn
Copy link
Copy Markdown
Contributor

Description

Adds a scheduled workflow and supporting tooling to automatically pin GitHub Action references to their latest stable release commit SHAs. This addresses the challenge that action references embedded as TypeScript string literals in src/ are invisible to Dependabot and Renovate, causing versions to drift over time.

Changes

  • New script: src/security/update-github-actions.ts — A Node.js CLI tool that:

    • Scans TypeScript, JSON, and YAML files for uses: 'owner/repo@ref' literals
    • Queries the GitHub Releases API to find the latest stable tag (skipping pre-releases by default)
    • Resolves tags to full commit SHAs (following annotated tags to their underlying commits)
    • Rewrites literals in place with the SHA, preserving the tag as a trailing TypeScript comment for readability
    • Outputs a summary table to the GitHub Actions job summary for review
  • New workflow: .github/workflows/update-actions.yml — Runs weekly (Monday 06:00 UTC) and on manual dispatch:

    • Job 1 (upgrade): Runs the pinning script, regenerates the project, and creates a patch artifact
    • Job 2 (pr): Downloads the patch and opens a PR with the changes using a GitHub App token
  • Configuration: Updated .projenrc.ts to define the workflow and added tsx as a build dependency for running TypeScript directly

  • Documentation: Added a new "Maintenance" section to README.md explaining the workflow, how to run the script locally, and how to review resulting PRs

Motivation

Generated GitHub Actions workflows in this repository reference actions as string literals (e.g., actions/checkout@v6). Unlike real workflow YAML files, these are not tracked by Dependabot or Renovate, leading to stale action versions and potential security gaps. This automation keeps pinned actions current by resolving them to the latest stable release SHAs on a weekly schedule.

Test Plan

The workflow is configured to run on schedule and via workflow_dispatch. Manual testing can be performed locally:

GH_TOKEN=$(gh auth token) npx tsx src/security/update-github-actions.ts src .projen .projenrc.ts

The generated workflow will be validated by CI on merge.

https://claude.ai/code/session_01Avf49PnGcNWmgpViU3uzyE

claude added 4 commits April 17, 2026 06:18
Adds a scheduled workflow that scans TypeScript source under src/ for
`uses: 'owner/repo@ref'` literals, resolves each action to the latest
stable release commit SHA, and opens a PR with the pinned updates.

Closes #186

https://claude.ai/code/session_01Avf49PnGcNWmgpViU3uzyE
Converts the maintenance script from .mjs to .ts so it participates in
the project's lint/type-check pipeline. Adds scripts/ to the dev
tsconfig includes and to the eslint scope, and invokes the script via
ts-node from the workflow.

https://claude.ai/code/session_01Avf49PnGcNWmgpViU3uzyE
Replaces ts-node with tsx in the update-actions workflow, drops the
default src argument, and has the script scan src/, .projen/, and
.projenrc.ts for action references. Reworks the regex to also handle
inline `{ name: ..., uses: ... }` entries without corrupting the
surrounding properties.

https://claude.ai/code/session_01Avf49PnGcNWmgpViU3uzyE
Relocates the action-pinning maintenance script into the main source
tree so it's covered by the standard tsconfig and eslint scope without
bespoke includes. Drops the now-unnecessary `scripts/` directory and
its projenrc hooks; the workflow invokes the script at its new path.

https://claude.ai/code/session_01Avf49PnGcNWmgpViU3uzyE
@github-actions github-actions Bot requested a review from Lock128 April 17, 2026 08:11
claude and others added 7 commits April 17, 2026 08:19
Adds a `update-github-actions` bin entry pointing at the compiled
pinning script, and introduces `UpdateActionsWorkflow` as a reusable
projen Component so downstream projects can add the same scheduled
maintenance workflow to their own pipelines. This addresses the stretch
goal from #186.

The repo's own `.projenrc.ts` now consumes the new class with a
`command` override that runs the script from source (since the bin
isn't yet installed when this package builds itself).

https://claude.ai/code/session_01Avf49PnGcNWmgpViU3uzyE
Downstream consumers of UpdateActionsWorkflow have their action
references in `.projenrc.ts` and `.projen/` rather than in their
application source, so the default now targets those paths only.
`projen-pipelines` itself extends the list with `src` since it embeds
action strings in its hand-authored library code.

https://claude.ai/code/session_01Avf49PnGcNWmgpViU3uzyE
Signed-off-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Covers default path scoping, custom paths/command/schedule/runner/labels/
branch/prerelease overrides, GitHub App token vs GITHUB_TOKEN fallback,
job outputs, and the defensive error when github integration is
disabled. Achieves 100% coverage for the new component.

https://claude.ai/code/session_01Avf49PnGcNWmgpViU3uzyE
Refactors the script's core logic into testable @internal functions
(isScannable, walk, collect, repoRoot, rewriteContent, renderSummary)
gated behind `require.main === module` for the CLI entry point. The
@internal JSDoc tag keeps them off the public jsii API surface.

Adds 16 tests covering extension filtering, directory walking with
mixed file/dir inputs, sub-path action resolution, standalone vs
inline rewrite behavior, comment refresh, no-op on matching SHA,
unresolved references, and the markdown summary format.

https://claude.ai/code/session_01Avf49PnGcNWmgpViU3uzyE
Adds `.js`, `.cjs`, and `.mjs` to the scannable extensions so projects
using `.projenrc.js` benefit from the same pinning maintenance. The
default scan paths now include both `.projenrc.ts` and `.projenrc.js`;
`collect` silently skips non-existent paths so either variant works
without configuration.

https://claude.ai/code/session_01Avf49PnGcNWmgpViU3uzyE
Signed-off-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@hoegertn hoegertn marked this pull request as draft April 17, 2026 14:49
@hoegertn hoegertn changed the title Add automated GitHub Actions pinning workflow feat: Add automated GitHub Actions pinning workflow Apr 17, 2026
name: 'Set git identity',
run: [
'git config user.name "github-actions[bot]"',
'git config user.email "41898282+github-actions[bot]@users.noreply.github.com"',
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.

is this hardcoded id good?

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.

afaik this is the "magic" number of the github-actions bot

},
{
name: 'Create Pull Request',
uses: 'peter-evans/create-pull-request@v8',
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.

is this action safe?

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.

Might switch to "gh pr create" later. afair projen is migrating right now.

'',
'*Automatically created by the `update-actions` workflow.*',
].join('\n'),
'author': 'github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>',
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.

see above

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.

afaik this is the "magic" number of the github-actions bot

Copy link
Copy Markdown
Contributor

@Lock128 Lock128 left a comment

Choose a reason for hiding this comment

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

see comments

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.

3 participants