Skip to content

feat: list secrets & custom actions in lock file header; move gh-aw-metadata to first line#24495

Merged
pelikhan merged 2 commits intomainfrom
copilot/add-secrets-and-actions-to-lockfile
Apr 4, 2026
Merged

feat: list secrets & custom actions in lock file header; move gh-aw-metadata to first line#24495
pelikhan merged 2 commits intomainfrom
copilot/add-secrets-and-actions-to-lockfile

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 4, 2026

Lock files lacked a human-readable manifest of their external dependencies, and gh-aw-metadata was buried after the ASCII banner making machine parsing cumbersome.

Changes

Header structure

  • # gh-aw-metadata: {...} is now line 1 of every lock file (before the ASCII logo)
  • Two new sections appended after existing header content:
    • # Secrets used: — sorted, deduplicated list of all secrets.* references in the workflow
    • # Custom actions used: — sorted, deduplicated list of all external uses: references (local ./ refs excluded), including inline version tags

Example output

# gh-aw-metadata: {"schema_version":"v3","frontmatter_hash":"...","strict":true,"agent_id":"copilot"}
#    ___  ...ASCII logo...
# This file was automatically generated by gh-aw. DO NOT EDIT.
# ...
# Secrets used:
#   - COPILOT_GITHUB_TOKEN
#   - GH_AW_GITHUB_TOKEN
#   - GITHUB_TOKEN
#
# Custom actions used:
#   - actions/checkout@de0fac2e... # v6.0.2
#   - actions/github-script@ed5974... # v8
#   - actions/upload-artifact@bbbca2... # v7

name: "My Workflow"

Implementation

  • CollectActionReferences(yamlContent string) []string added to redact_secrets.go — regex-based extraction of external uses: values, supporting both uses: ref and - uses: ref YAML forms
  • generateYAML now generates the workflow body first, then passes collected secrets/actions into generateWorkflowHeader — avoids a two-pass scan
  • generateWorkflowHeader signature extended with secrets []string, actions []string; metadata block moved to top

…tadata to first line

- Add CollectActionReferences() to extract external uses: refs from YAML
- Move gh-aw-metadata to be the first line of lock files
- Add '# Secrets used:' and '# Custom actions used:' sections in header
- Generate body first to collect secrets/actions before header is written
- Add tests for CollectActionReferences and lock file header ordering
- Recompile all 184 workflows with new header format

Agent-Logs-Url: https://github.com/github/gh-aw/sessions/7b42071d-e47b-4be4-aa1f-e315084741be

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
@pelikhan pelikhan marked this pull request as ready for review April 4, 2026 13:31
Copilot AI review requested due to automatic review settings April 4, 2026 13:31
@pelikhan
Copy link
Copy Markdown
Collaborator

pelikhan commented Apr 4, 2026

@copilot merge main and recompile

Copy link
Copy Markdown
Contributor

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 improves generated GitHub Actions lock file headers by making external dependencies more human- and machine-readable, primarily by moving the gh-aw-metadata JSON block to the first line and adding explicit manifests for referenced secrets and external actions.

Changes:

  • Emit # gh-aw-metadata: {...} as the first line in generated lock files and append new header sections for “Secrets used” and “Custom actions used”.
  • Add regex-based extraction for external uses: references (CollectActionReferences) alongside existing secret reference collection.
  • Refactor YAML generation to build the workflow body first, then derive secrets/actions lists for the header.
Show a summary per file
File Description
pkg/workflow/compiler_yaml.go Refactors YAML generation order; updates header generation to place gh-aw-metadata first and to print secrets/actions manifests.
pkg/workflow/redact_secrets.go Adds CollectActionReferences and a uses:-matching regex to extract and dedupe external action references.
pkg/workflow/compiler_yaml_helpers_test.go Updates unit test call site for the expanded generateWorkflowHeader signature.
.github/workflows/*.lock.yml Regenerates lock files to reflect new header structure (metadata first line; secrets/actions manifests).

Copilot's findings

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comments suppressed due to low confidence (1)

pkg/workflow/redact_secrets.go:80

  • CollectActionReferences claims to return a deduplicated list of uses: values, but it deduplicates on entry (ref + optional tag comment). If the same action ref appears with different inline tags/comments (or once with and once without), it will be emitted multiple times. Consider deduplicating by ref and choosing a single display string (e.g., prefer the one with a tag comment when available).
  • Files reviewed: 189/189 changed files
  • Comments generated: 2

Comment on lines +17 to +20
// actionReferencePattern matches "uses: <action-ref>" lines in YAML, including
// both key-value format ("uses: ref") and list-item format ("- uses: ref").
// Captures the action reference (group 1) and optional inline comment tag (group 2).
var actionReferencePattern = regexp.MustCompile(`(?m)^\s+(?:-\s+)?uses:\s+(\S+)(?:\s+#\s*(.+?))?$`)
Copy link

Copilot AI Apr 4, 2026

Choose a reason for hiding this comment

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

actionReferencePattern currently requires at least one leading whitespace (^\s+) and does not tolerate trailing whitespace after the ref unless an inline comment is present. This will miss valid uses: lines like uses: actions/checkout@sha or uses: actions/checkout@sha# v4 (no space before #). Consider relaxing the regex to ^\s*(?:-\s+)?uses:\s*(\S+)\s*(?:#\s*(.*))?$ so extraction is resilient to formatting differences.

This issue also appears on line 64 of the same file.

Copilot uses AI. Check for mistakes.
Comment on lines +77 to +81
// Add lock metadata as the very first line for easy machine parsing.
// Single-line JSON format to minimize merge conflicts.
if frontmatterHash != "" {
agentInfo := AgentMetadataInfo{}
// Agent ID: prefer EngineConfig.ID, fall back to legacy AI field
Copy link

Copilot AI Apr 4, 2026

Choose a reason for hiding this comment

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

The new requirement is that # gh-aw-metadata: {...} is line 1 of every lock file for machine parsing, but this header only emits metadata when frontmatterHash != "". If hash computation fails (currently treated as non-fatal), the lock file will revert to starting with the ASCII banner and break the parsing contract. Consider always emitting gh-aw-metadata (allowing empty frontmatter_hash) or making hash computation failure fatal for lockfile generation.

Copilot uses AI. Check for mistakes.
…nd-actions-to-lockfile

# Conflicts:
#	.github/workflows/claude-token-optimizer.lock.yml
#	.github/workflows/claude-token-usage-analyzer.lock.yml
#	.github/workflows/copilot-token-optimizer.lock.yml
#	.github/workflows/copilot-token-usage-analyzer.lock.yml
#	.github/workflows/token-logs-fetch.lock.yml

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 4, 2026

@copilot merge main and recompile

Done in d41c4e8. Merged origin/main, resolved the 5 modify/delete conflicts (accepting the deletions from main), rebuilt the binary, and recompiled all 179 workflows.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • https://api.github.com/graphql
    • Triggering command: /usr/bin/gh /usr/bin/gh api graphql -f query=query($owner: String!, $name: String!) { repository(owner: $owner, name: $name) { hasDiscussionsEnabled } } -f owner=github -f name=gh-aw (http block)
    • Triggering command: /usr/bin/gh /usr/bin/gh api graphql -f query=query($owner: String!, $name: String!) { repository(owner: $owner, name: $name) { hasDiscussionsEnabled } } -f owner=github -f name=gh-aw -pack /home/REDACTED/work/gh-aw/gh-aw/cmd/gh-aw/main.go (http block)
  • https://api.github.com/repos/astral-sh/setup-uv/git/ref/tags/eac588ad8def6316056a12d4907a9d4d84ff7a3b
    • Triggering command: /usr/bin/gh gh api /repos/astral-sh/setup-uv/git/ref/tags/eac588ad8def6316056a12d4907a9d4d84ff7a3b --jq .object.sha (http block)
  • https://api.github.com/repos/github/gh-aw
    • Triggering command: /usr/bin/gh gh api /repos/github/gh-aw --jq .visibility (http block)
  • https://api.github.com/repos/githubnext/agentics/git/ref/tags/
    • Triggering command: /usr/bin/gh gh api /repos/githubnext/agentics/git/ref/tags/# --jq .object.sha (http block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI requested a review from pelikhan April 4, 2026 13:38
@pelikhan pelikhan merged commit 4a8ed89 into main Apr 4, 2026
@pelikhan pelikhan deleted the copilot/add-secrets-and-actions-to-lockfile branch April 4, 2026 13:39
github-actions bot added a commit that referenced this pull request Apr 4, 2026
- Update gh aw audit diff signature to reflect multi-run support:
  accepts one base run and one or more comparison runs (from #24544)
- Document token usage diff breakdown (input/output/cache tokens,
  API requests, cache efficiency) added in #24544
- Document JSON array output and divider behavior for multiple diffs
- Add lock file header section to workflow-structure.md documenting
  the gh-aw-metadata first-line placement and the Secrets/Custom
  actions manifest sections added in #24495

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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