Skip to content

Restrict changeset generator workflow to run only for PRs targeting default branch#1350

Merged
pelikhan merged 7 commits intomainfrom
copilot/restrict-changeset-generation-workflow
Oct 8, 2025
Merged

Restrict changeset generator workflow to run only for PRs targeting default branch#1350
pelikhan merged 7 commits intomainfrom
copilot/restrict-changeset-generation-workflow

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Oct 8, 2025

Overview

This PR restricts the changeset generation agentic workflow to run only for pull requests where the base branch is the repository's default branch. This prevents the workflow from running on PRs targeting feature branches, staging branches, or other non-default branches.

Changes

1. Added New Allowed GitHub Actions Expression

Added one new expression to the allowed list in pkg/constants/constants.go:

  • github.event.repository.default_branch - Provides access to the repository's default branch name

This expression is now validated as safe for use in agentic workflow markdown content.

2. Updated Changeset Generator Workflow

Modified .github/workflows/changeset-generator.md to include an if condition in the frontmatter:

if: github.event.pull_request.base.ref == github.event.repository.default_branch

This condition ensures the workflow only executes when the PR's base branch matches the repository's default branch.

Additionally, updated the changeset type determination logic to explicitly treat internal changes, tooling changes, and documentation changes as "patch" level only. This ensures consistent versioning for non-user-facing changes.

3. Workflow Compilation

The compiled workflow (.github/workflows/changeset-generator.lock.yml) now includes this restriction in the activation job's if condition, combined with the existing team membership check:

if: >
  (needs.check-membership.outputs.is_team_member == 'true') && 
  (github.event.pull_request.base.ref == github.event.repository.default_branch)

4. Updated Documentation

Updated .github/instructions/github-agentic-workflows.instructions.md to clarify that:

  • The if field in frontmatter can use any GitHub Actions expression
  • Expression restrictions only apply to ${{}} expressions embedded in markdown content that gets passed to the AI agent

This documentation clarifies the security model and helps developers understand when expression sanitization is required.

Security Note

The if condition in the frontmatter can safely use github.event.pull_request.base.ref because it's evaluated by GitHub Actions itself and not passed to the AI agent. The allowed expressions list in constants.go only applies to expressions in the markdown content that gets sent to the agent. This maintains proper security boundaries:

  • Frontmatter if conditions: Can use any GitHub Actions expression (evaluated by GitHub Actions)
  • Markdown content expressions: Must be in the allowed list (sanitized before being passed to the AI agent)

Behavior

Before: The changeset generator workflow ran for all pull requests marked as "ready for review", regardless of the target branch.

After: The workflow only runs when:

  1. The user has the required team membership (admin/maintainer), AND
  2. The pull request targets the repository's default branch

Additionally, the workflow now consistently categorizes internal, tooling, and documentation changes as "patch" level.

Example Scenarios:

  • ✅ PR from feature-branchmain (default): Workflow runs
  • ❌ PR from feature-astaging: Workflow skips
  • ❌ PR from feature-bdevelop: Workflow skips

Testing

  • ✅ All unit tests pass
  • ✅ All integration tests pass
  • ✅ Expression safety validation tests added and passing
  • ✅ Workflow compiles successfully
  • ✅ Code formatting verified

Impact

This change prevents unnecessary changeset generation for PRs that target non-default branches, which is appropriate since changesets are typically only needed when merging to the main release branch. The updated changeset categorization logic ensures that internal and documentation changes are versioned consistently as patches.

Original prompt

Restrict the changeset generation agentic workflow to run for pull request where the base branch is the default branch.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copilot AI and others added 2 commits October 8, 2025 12:43
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] Restrict changeset generation workflow to default branch Restrict changeset generator workflow to run only for PRs targeting default branch Oct 8, 2025
Copilot AI requested a review from pelikhan October 8, 2025 12:48
Comment thread pkg/constants/constants.go Outdated
"github.event.project_card.id",
"github.event.project_column.id",
"github.event.pull_request.number",
"github.event.pull_request.base.ref",
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@copilot remove, this variable is not 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.

Removed in commit 7a4d0ec. The unsafe expression has been removed from the allowed list, and the changeset generator workflow has been reverted to run for all PRs without the base branch restriction.

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title Restrict changeset generator workflow to run only for PRs targeting default branch Add github.event.repository.default_branch to allowed expressions Oct 8, 2025
Copilot AI requested a review from pelikhan October 8, 2025 13:00
@pelikhan
Copy link
Copy Markdown
Collaborator

pelikhan commented Oct 8, 2025

@copilot keep if expression using base.ref. It is safe to use any expression there since it is not passed to the agent. The "if" does not need to be sanitized.

@pelikhan
Copy link
Copy Markdown
Collaborator

pelikhan commented Oct 8, 2025

@copilot update instructions.md to specify that "if" expressions can use any expression. Only restriction when inlined in the prompt as ${{}} expression.

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

Copilot AI commented Oct 8, 2025

@copilot keep if expression using base.ref. It is safe to use any expression there since it is not passed to the agent. The "if" does not need to be sanitized.

Restored in commit d8a5f72. The if condition now uses base.ref to restrict the workflow to PRs targeting the default branch. The expression is safe in the if condition since it's evaluated by GitHub Actions and not passed to the agent.

@pelikhan
Copy link
Copy Markdown
Collaborator

pelikhan commented Oct 8, 2025

@copilot update prompt to treat any internal, tooling change or documentation change as "patch" level only.

Copilot AI changed the title Add github.event.repository.default_branch to allowed expressions Restrict changeset generator workflow to run only for PRs targeting default branch Oct 8, 2025
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Oct 8, 2025

@copilot update prompt to treat any internal, tooling change or documentation change as "patch" level only.

Updated in commit 6f8e891. The changeset generator prompt now explicitly treats internal changes, tooling changes, and documentation changes as "patch" level only.

@copilot update instructions.md to specify that "if" expressions can use any expression. Only restriction when inlined in the prompt as ${{}} expression.

Updated in commit 6f8e891. The instructions now clarify that if expressions in frontmatter can use any GitHub Actions expression, and only ${{}} expressions in markdown content are restricted.

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
@pelikhan pelikhan marked this pull request as ready for review October 8, 2025 13:17
@pelikhan pelikhan merged commit c0fd2c1 into main Oct 8, 2025
21 checks passed
@pelikhan pelikhan deleted the copilot/restrict-changeset-generation-workflow branch October 8, 2025 13:19
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