Skip to content

Sync eng/common directory with azure-sdk-tools for PR 14219#48167

Open
azure-sdk wants to merge 5 commits intomainfrom
sync-eng/common-AddGHAppWorkflowLogin-14219
Open

Sync eng/common directory with azure-sdk-tools for PR 14219#48167
azure-sdk wants to merge 5 commits intomainfrom
sync-eng/common-AddGHAppWorkflowLogin-14219

Conversation

@azure-sdk
Copy link
Collaborator

Sync eng/common directory with azure-sdk-tools for PR Azure/azure-sdk-tools#14219 See eng/common workflow

@azure-sdk azure-sdk requested a review from a team as a code owner February 27, 2026 23:05
@azure-sdk azure-sdk added EngSys This issue is impacting the engineering system. Central-EngSys This issue is owned by the Engineering System team. labels Feb 27, 2026
Copy link
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

Synchronizes eng/common GitHub authentication tooling with azure-sdk-tools by extending the existing login-to-github.ps1 script to support GitHub Actions and introducing a composite action wrapper for workflows.

Changes:

  • Update login-to-github.ps1 to support exporting/masking tokens in GitHub Actions and improve signing error output.
  • Add a new composite GitHub Action (eng/common/actions/login-to-github) that wraps the PowerShell script for workflow usage.

Reviewed changes

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

File Description
eng/common/scripts/login-to-github.ps1 Adds GitHub Actions export/masking behavior and updates error handling text when Key Vault signing fails.
eng/common/actions/login-to-github/action.yml Introduces a composite action wrapper that invokes login-to-github.ps1 from GitHub Actions with configurable inputs.

Comment on lines +183 to +186
if ($env:GITHUB_ACTIONS -eq 'true') {
Write-Host "::add-mask::$installationToken"
Add-Content -Path $env:GITHUB_ENV -Value "$variableName=$installationToken"
Write-Host "GitHub Actions env variable '$variableName' has been exported."
Copy link

Copilot AI Feb 27, 2026

Choose a reason for hiding this comment

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

In GitHub Actions, $variableName is derived from the owner string (e.g., azure-sdk), which can produce environment variable names containing -. Those are awkward or invalid to reference in common shells and in Actions expressions (env.GH_TOKEN_azure-sdk won’t work without bracket syntax). Consider normalizing/sanitizing $InstallationTokenOwner when composing $variableName (e.g., replace non [A-Za-z0-9_] with _) and document the normalization so callers know which name to reference.

Copilot uses AI. Check for mistakes.
Comment on lines 100 to 108
$SignResultJson = az keyvault key sign `
--vault-name $VaultName `
--name $KeyName `
--algorithm RS256 `
--digest $Base64Value | ConvertFrom-Json

if ($LASTEXITCODE -ne 0) {
throw "Failed to sign JWT with Azure Key Vault. Error: $SignResult"
throw "Failed to sign JWT with Azure Key Vault. Error: $($SignResultJson | ConvertTo-Json -Compress)"
}
Copy link

Copilot AI Feb 27, 2026

Choose a reason for hiding this comment

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

az keyvault key sign ... | ConvertFrom-Json can throw before the $LASTEXITCODE check if the CLI emits non-JSON on failure (common when errors are written to stderr). To make the new error message reliable, capture the raw output/stderr first (e.g., 2>&1), check $LASTEXITCODE, then conditionally ConvertFrom-Json only on success (or wrap ConvertFrom-Json in try/catch and include the raw output in the thrown error).

Copilot uses AI. Check for mistakes.
Comment on lines +44 to +51
# - run: gh pr list --repo Azure/azure-sdk-tools
# env:
# GH_TOKEN: ${{ env.GH_TOKEN_Azure }}
#
# Tokens are exported to GITHUB_ENV so all subsequent steps can reference
# them as ${{ env.GH_TOKEN }} (single owner) or ${{ env.GH_TOKEN_<Owner> }}
# (multiple owners). This matches the Azure DevOps behavior where tokens
# are set as pipeline variables.
Copy link

Copilot AI Feb 27, 2026

Choose a reason for hiding this comment

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

The multi-owner example includes azure-sdk, which would export GH_TOKEN_azure-sdk. That name can’t be referenced via env.GH_TOKEN_azure-sdk in GitHub Actions expressions and is awkward in bash. Either document the required bracket syntax (env['GH_TOKEN_azure-sdk']) or (preferably) ensure the underlying script/action normalizes owner names to a safe env-var identifier (e.g., azure_sdk) and update the docs accordingly.

Suggested change
# - run: gh pr list --repo Azure/azure-sdk-tools
# env:
# GH_TOKEN: ${{ env.GH_TOKEN_Azure }}
#
# Tokens are exported to GITHUB_ENV so all subsequent steps can reference
# them as ${{ env.GH_TOKEN }} (single owner) or ${{ env.GH_TOKEN_<Owner> }}
# (multiple owners). This matches the Azure DevOps behavior where tokens
# are set as pipeline variables.
# # Example: use the token for the "Azure" owner (simple name)
# - run: gh pr list --repo Azure/azure-sdk-tools
# env:
# GH_TOKEN: ${{ env.GH_TOKEN_Azure }}
#
# # Example: use the token for the "azure-sdk" owner (hyphenated name)
# # Note the required bracket syntax because "-" is not valid in
# # GitHub Actions dot-notation identifiers.
# - run: gh pr list --repo azure-sdk/azure-sdk-tools
# env:
# GH_TOKEN: ${{ env['GH_TOKEN_azure-sdk'] }}
#
# Tokens are exported to GITHUB_ENV so all subsequent steps can reference
# them as ${{ env.GH_TOKEN }} (single owner) or ${{ env.GH_TOKEN_<Owner> }}
# (multiple owners). When <Owner> contains characters that are not valid in
# GitHub Actions identifiers (for example, "azure-sdk" with a "-"), you must
# use bracket syntax instead, e.g. ${{ env['GH_TOKEN_azure-sdk'] }}.
# This matches the Azure DevOps behavior where tokens are set as pipeline
# variables, while documenting the correct GitHub Actions expression syntax.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Central-EngSys This issue is owned by the Engineering System team. EngSys This issue is impacting the engineering system.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants