Skip to content

Add GH_TOKEN to Install gh-aw extension step#1994

Merged
pelikhan merged 6 commits intomainfrom
copilot/update-gh-cli-install-step
Oct 19, 2025
Merged

Add GH_TOKEN to Install gh-aw extension step#1994
pelikhan merged 6 commits intomainfrom
copilot/update-gh-cli-install-step

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Oct 19, 2025

Problem

The "Install gh-aw extension" step in compiled workflows was missing the GH_TOKEN environment variable, which is required by the gh CLI for authentication. This caused the installation step to fail when the workflow runs in GitHub Actions.

The gh CLI requires the GitHub token to be available as GH_TOKEN when performing operations that interact with the GitHub API, including installing extensions.

Solution

Updated the compiler in pkg/workflow/mcps.go to include the GH_TOKEN environment variable in the "Install gh-aw extension" step. The token uses getEffectiveGitHubToken() helper function to resolve the correct token with proper precedence:

  1. Top-level github-token from frontmatter (if specified)
  2. Default fallback: ${{ secrets.GH_AW_GITHUB_TOKEN || secrets.GITHUB_TOKEN }}

Additionally, simplified the install command to remove the upgrade fallback (|| gh extension upgrade githubnext/gh-aw) since the workflow runs in a fresh container where the extension is never pre-installed.

Before

- name: Install gh-aw extension
  run: |
    echo "Installing gh-aw extension..."
    gh extension install githubnext/gh-aw || gh extension upgrade githubnext/gh-aw
    gh aw --version

After (default token)

- name: Install gh-aw extension
  env:
    GH_TOKEN: ${{ secrets.GH_AW_GITHUB_TOKEN || secrets.GITHUB_TOKEN }}
  run: |
    echo "Installing gh-aw extension..."
    gh extension install githubnext/gh-aw
    gh aw --version

After (with custom github-token in frontmatter)

- name: Install gh-aw extension
  env:
    GH_TOKEN: ${{ secrets.CUSTOM_PAT }}
  run: |
    echo "Installing gh-aw extension..."
    gh extension install githubnext/gh-aw
    gh aw --version

Changes

  • pkg/workflow/mcps.go:
    • Added GH_TOKEN environment variable to the install step
    • Used getEffectiveGitHubToken() helper to resolve the correct token with precedence support
    • Simplified install command by removing upgrade fallback for fresh containers
  • pkg/workflow/agentic_workflow_test.go:
    • Added test TestAgenticWorkflowsInstallStepIncludesGHToken to verify the default token is used
    • Added test TestAgenticWorkflowsInstallStepWithCustomToken to verify custom token precedence
  • Recompiled workflows: Updated all .lock.yml files that use the agentic-workflows tool

Testing

  • ✅ Added new tests for both default and custom token scenarios
  • ✅ All existing unit and integration tests pass
  • ✅ Verified compiled workflows include the GH_TOKEN environment variable with correct token resolution
  • ✅ Code formatting and linting passes

This follows the same pattern used elsewhere in the codebase for steps that invoke gh commands (e.g., push_to_pull_request_branch.go, create_issue.go) and uses the same token resolution helper (getEffectiveGitHubToken) used throughout the workflow package.

Original prompt

Update compiler such that the "install gh aw cli" step passes the github token to the gh cli


name: Install gh-aw extension
run: |
echo "Installing gh-aw extension..."
gh extension install githubnext/gh-aw || gh extension upgrade githubnext/gh-aw
gh aw --version

gh requires the GitHub token as GH_TOKEN


💡 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 2 commits October 19, 2025 20:36
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Comment thread pkg/workflow/mcps.go Outdated
Copilot AI changed the title [WIP] Update compiler to pass GitHub token to gh cli Add GH_TOKEN to Install gh-aw extension step Oct 19, 2025
Copilot AI requested a review from pelikhan October 19, 2025 20:43
@pelikhan pelikhan marked this pull request as ready for review October 19, 2025 20:46
@github-actions
Copy link
Copy Markdown
Contributor

Agentic Changeset Generator triggered by this pull request.

@pelikhan
Copy link
Copy Markdown
Collaborator

Use helper to resolve the correct GitHub token (see GH_AW_GITHUB_TOKEN) @copilot

github-actions Bot and others added 2 commits October 19, 2025 20:49
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Oct 19, 2025

Use helper to resolve the correct GitHub token (see GH_AW_GITHUB_TOKEN) @copilot

Updated to use getEffectiveGitHubToken() helper which resolves tokens with proper precedence:

  1. Top-level github-token from frontmatter (if specified)
  2. Default: ${{ secrets.GH_AW_GITHUB_TOKEN || secrets.GITHUB_TOKEN }}

The install step now generates:

env:
  GH_TOKEN: ${{ secrets.GH_AW_GITHUB_TOKEN || secrets.GITHUB_TOKEN }}

Added tests for both default and custom token scenarios.

@pelikhan pelikhan merged commit 67bce52 into main Oct 19, 2025
4 checks passed
@pelikhan pelikhan deleted the copilot/update-gh-cli-install-step branch October 19, 2025 21:02
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