Skip to content

Generate zizmor annotations for workflow_run triggers#4129

Merged
pelikhan merged 5 commits intomainfrom
copilot/ignore-workflow-run-zizmor
Nov 16, 2025
Merged

Generate zizmor annotations for workflow_run triggers#4129
pelikhan merged 5 commits intomainfrom
copilot/ignore-workflow-run-zizmor

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Nov 16, 2025

Add zizmor annotations for workflow_run validation ✅

Problem

The compiler adds specific validation (role checking, fork prevention) to secure workflow_run triggers. However, zizmor flags these as "dangerous-triggers" which required manual configuration in .github/zizmor.yml to suppress the warnings.

Solution - COMPLETE ✅

  • Understand current workflow_run validation implementation
  • Add YAML comment annotations in the on: section for workflow_run triggers
  • Use annotation format that zizmor recognizes to suppress dangerous-triggers warning
  • Update compiler to automatically add annotations during compilation
  • Test with actual zizmor to ensure warnings are suppressed
  • Add tests to verify annotations are generated
  • Clean up manual suppressions in .github/zizmor.yml
  • Address PR feedback: improve validation and edge case handling

Implementation Complete

Added automatic inline zizmor annotations that suppress dangerous-triggers warnings for workflow_run triggers.

Key Changes:

  1. Job struct - Added HasWorkflowRunSafetyChecks field to track jobs with workflow_run safety validation
  2. Job rendering - Modified renderJob to add zizmor ignore comment before job if conditions when flag is set
  3. On section annotation - Created addZizmorIgnoreForWorkflowRun function to add annotations after workflow_run: line
  4. Compiler integration - Integrated annotation in both extractTopLevelYAMLSection and parseOnSection code paths
  5. Cleanup - Removed manual suppressions for ci-doctor and dev-hawk from .github/zizmor.yml
  6. Enhanced validation - Added checks to skip comments and prevent duplicate annotations

Generated Annotation Format:

"on":
  workflow_run:
    # zizmor: ignore[dangerous-triggers] - workflow_run trigger is secured with role and fork validation
    branches:
    - main

Tests:

  • TestAddZizmorIgnoreForWorkflowRun - Comprehensive tests including edge cases for comments, inline comments, duplicates, and values
  • TestJobHasWorkflowRunSafetyChecks - Verifies job field is set and rendered correctly

Validation:

  • ✅ All unit tests pass (including new edge case tests)
  • ✅ Linting passes (make lint)
  • ✅ ci-doctor.lock.yml: zizmor reports "(2 ignored, 48 suppressed)" - annotation working
  • ✅ dev-hawk.lock.yml: zizmor reports "(2 ignored, 48 suppressed)" - annotation working
  • ✅ All 80 workflows compile successfully
  • ✅ Manual suppressions removed from .github/zizmor.yml

Impact:
The compiler now automatically generates inline zizmor annotations when compiling workflows with workflow_run triggers. The annotation function includes robust validation to:

  • Skip lines that are comments (start with #)
  • Only annotate workflow_run: keys without values
  • Prevent duplicate annotations in malformed YAML
    This eliminates the need for brittle line-number-based suppressions that break when workflows are modified.
Original prompt

Generate annotations such that workflow_run is ignored by zizmor. The compiler already adds specific validation (role, fork) to secure it.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 3 commits November 16, 2025 14:01
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Update annotations to ignore workflow_run in Zizmor Generate zizmor annotations for workflow_run triggers Nov 16, 2025
Copilot AI requested a review from pelikhan November 16, 2025 14:09
@pelikhan pelikhan marked this pull request as ready for review November 16, 2025 17:31
Copilot AI review requested due to automatic review settings November 16, 2025 17:31
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 adds automatic generation of zizmor ignore annotations for workflow_run triggers to replace brittle manual line-number suppressions. The compiler already secures workflow_run triggers with role and fork validation checks, so these annotations inform zizmor to skip the "dangerous-triggers" warnings.

Key changes:

  • Automatic inline comment injection at workflow trigger level (workflow_run: lines)
  • Job-level annotation support via new HasWorkflowRunSafetyChecks field for jobs with workflow_run safety conditions
  • Removal of manual suppressions from .github/zizmor.yml for ci-doctor and dev-hawk workflows

Reviewed Changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
pkg/workflow/zizmor_annotation_test.go Unit tests for annotation generation at trigger and job levels
pkg/workflow/jobs.go Added HasWorkflowRunSafetyChecks field and annotation rendering in renderJob()
pkg/workflow/frontmatter_extraction.go Implemented addZizmorIgnoreForWorkflowRun() for trigger-level annotations
pkg/workflow/compiler_jobs.go Sets HasWorkflowRunSafetyChecks flag when building activation jobs
pkg/workflow/compiler.go Integrated annotation generation in parseOnSection()
.github/zizmor.yml Removed manual line-number suppressions for ci-doctor and dev-hawk
.github/workflows/dev-hawk.lock.yml Generated workflow with inline annotations
.github/workflows/ci-doctor.lock.yml Generated workflow with inline annotations

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

Comment thread pkg/workflow/frontmatter_extraction.go Outdated
Comment on lines +674 to +686
// Check if this is the workflow_run: line
trimmedLine := strings.TrimSpace(line)
if trimmedLine == "workflow_run:" {
// Get the indentation of the workflow_run line
indentation := ""
if len(line) > len(trimmedLine) {
indentation = line[:len(line)-len(trimmedLine)]
}

// Add zizmor ignore comment with proper indentation
// The comment explains that the trigger is secured with role and fork validation
comment := indentation + " # zizmor: ignore[dangerous-triggers] - workflow_run trigger is secured with role and fork validation"
result = append(result, comment)
Copy link

Copilot AI Nov 16, 2025

Choose a reason for hiding this comment

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

The function adds an annotation after every line that contains workflow_run: when trimmed, but doesn't verify this is actually a YAML key at the appropriate level. This could incorrectly annotate lines like # Comment about workflow_run: or string values containing workflow_run:. Consider checking that the line doesn't start with # (comment) and matches the expected YAML key pattern.

Suggested change
// Check if this is the workflow_run: line
trimmedLine := strings.TrimSpace(line)
if trimmedLine == "workflow_run:" {
// Get the indentation of the workflow_run line
indentation := ""
if len(line) > len(trimmedLine) {
indentation = line[:len(line)-len(trimmedLine)]
}
// Add zizmor ignore comment with proper indentation
// The comment explains that the trigger is secured with role and fork validation
comment := indentation + " # zizmor: ignore[dangerous-triggers] - workflow_run trigger is secured with role and fork validation"
result = append(result, comment)
// Check if this is a non-comment workflow_run: key at the correct YAML level
trimmedLine := strings.TrimSpace(line)
// Skip if the line is a comment
if strings.HasPrefix(trimmedLine, "#") {
continue
}
// Match lines that are only 'workflow_run:' (possibly with trailing whitespace or a comment)
// e.g., 'workflow_run:', 'workflow_run: # comment', ' workflow_run:'
// But not 'someworkflow_run:', 'workflow_run: value', etc.
// We'll check that after trimming leading whitespace, the line starts with 'workflow_run:' and
// is either exactly 'workflow_run:' or 'workflow_run:' followed by whitespace or a comment.
if idx := strings.Index(trimmedLine, "workflow_run:"); idx == 0 {
after := strings.TrimSpace(trimmedLine[len("workflow_run:"):])
// Only allow if nothing or only a comment follows
if after == "" || strings.HasPrefix(after, "#") {
// Get the indentation of the workflow_run line
indentation := ""
if len(line) > len(trimmedLine) {
indentation = line[:len(line)-len(trimmedLine)]
}
// Add zizmor ignore comment with proper indentation
// The comment explains that the trigger is secured with role and fork validation
comment := indentation + " # zizmor: ignore[dangerous-triggers] - workflow_run trigger is secured with role and fork validation"
result = append(result, comment)
}

Copilot uses AI. Check for mistakes.
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.

Updated the function to validate that workflow_run: is a proper YAML key by:

  • Skipping lines that start with # (comments)
  • Verifying nothing follows workflow_run: except whitespace or a comment
  • Only annotating lines matching the pattern workflow_run: or workflow_run: # comment

Added comprehensive test coverage for these edge cases. Commit: cd5b9cf

Comment thread pkg/workflow/frontmatter_extraction.go Outdated
Comment on lines +668 to +676
lines := strings.Split(yamlStr, "\n")
var result []string

for _, line := range lines {
result = append(result, line)

// Check if this is the workflow_run: line
trimmedLine := strings.TrimSpace(line)
if trimmedLine == "workflow_run:" {
Copy link

Copilot AI Nov 16, 2025

Choose a reason for hiding this comment

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

The function will add multiple annotations if workflow_run: appears more than once in the YAML string. While this is unlikely in well-formed YAML (since YAML keys should be unique), it could cause duplicate annotations in malformed input. Consider adding a flag to ensure the annotation is only added once, or document this behavior.

Copilot uses AI. Check for mistakes.
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.

Added an annotationAdded flag to ensure the annotation is only added once, even if workflow_run: appears multiple times in malformed YAML. Added test case to verify this behavior. Commit: cd5b9cf

@pelikhan
Copy link
Copy Markdown
Collaborator

@copilot lint

@github-actions
Copy link
Copy Markdown
Contributor

Agentic Changeset Generator triggered by this pull request.

- Add validation to skip comment lines and lines with values after workflow_run:
- Add flag to prevent duplicate annotations in malformed YAML
- Add comprehensive tests for edge cases: comments, inline comments, duplicates, values

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

Copilot AI commented Nov 16, 2025

@copilot lint

Linting completed successfully. All validation checks pass (formatting, Go vet, staticcheck, JavaScript linting).

Copilot AI requested a review from pelikhan November 16, 2025 18:02
@pelikhan pelikhan merged commit b3dd05a into main Nov 16, 2025
51 of 56 checks passed
@pelikhan pelikhan deleted the copilot/ignore-workflow-run-zizmor branch November 16, 2025 18:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants