-
Notifications
You must be signed in to change notification settings - Fork 12
Fix some auth issues with release creation. #218
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
37db8da
Use 1ES PT-provided GITHUB_TOKEN for release creation
iclanton abcb00b
Add shallow checkout to Tag stage so 1ES PT injects GITHUB_TOKEN
iclanton 80d00b8
Add comment explaining why Tag stage needs a checkout
iclanton 55f3f65
Split emit-github-vars-and-tag-build into two actions
iclanton 5bcd4ab
Normalize basic-auth extraheader to token format for GitHub App tokens
iclanton a4f584a
Add unit tests for normalizeGitHubAuthorizationHeader
iclanton 584641d
Log GitHub API error details before re-throwing
iclanton ac473b2
fixup! Log GitHub API error details before re-throwing
iclanton 5c93ebe
Move normalization into getGitAuthorizationHeaderAsync so callers get…
iclanton 7e0c1e9
Rename normalizeGitHubAuthorizationHeader to parseGitHubAuthorization…
iclanton 54c8cc0
Make GitHubTokenActionBase generic so required/optional token is enfo…
iclanton 74fec40
Address PR feedback: import order, documentation strings, newline san…
iclanton 385f23a
Move parseGitHubAuthorizationHeader and IGitHubAuthorizationHeader to…
iclanton File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
tools/repo-toolbox/src/cli/actions/EmitGitHubVarsAction.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. | ||
| // See LICENSE in the project root for license information. | ||
|
|
||
| import type { ITerminal } from '@rushstack/terminal'; | ||
|
|
||
| import { | ||
| type IGitHubAuthorizationHeader, | ||
| parseGitHubAuthorizationHeader | ||
| } from '../../utilities/GitHubClient'; | ||
| import { getGitHubAuthorizationHeaderAsync, getRepoSlugAsync } from '../../utilities/GitUtilities'; | ||
| import { GitHubTokenActionBase } from './GitHubTokenActionBase'; | ||
|
|
||
| /** | ||
| * Emits GitHub-related pipeline output variables for use by downstream stages. | ||
| * | ||
| * Outputs: | ||
| * - GitHubRepoSlug — e.g. "SharePoint/spfx" | ||
| * - GitHubToken — Authorization header value (secret) | ||
| * | ||
| * GitHubToken is read from the GITHUB_TOKEN environment variable if present | ||
| * (injected by the 1ES pipeline template's 'Get GitHub Token' step) and | ||
| * normalized to a full Authorization header value. Falls back to the git | ||
| * credential stored in the checkout extraheader for environments without | ||
| * the 1ES template. | ||
| */ | ||
| export class EmitGitHubVarsAction extends GitHubTokenActionBase<false> { | ||
| private readonly _terminal: ITerminal; | ||
|
|
||
| public constructor(terminal: ITerminal) { | ||
| super({ | ||
| actionName: 'emit-github-vars', | ||
| summary: 'Emits GitHub repo slug and auth token as AzDO output variables.', | ||
| documentation: | ||
| 'Reads the GitHub repository slug from the local git remote and the authorization token ' + | ||
| 'from --github-token / GITHUB_TOKEN (if set) or the git checkout credential, then emits ' + | ||
| 'them as GitHubRepoSlug and GitHubToken AzDO output variables for use by downstream stages.', | ||
| githubTokenRequired: false | ||
| }); | ||
|
|
||
| this._terminal = terminal; | ||
| } | ||
|
|
||
| protected override async onExecuteAsync(): Promise<void> { | ||
| const terminal: ITerminal = this._terminal; | ||
|
iclanton marked this conversation as resolved.
|
||
|
|
||
| const repoSlug: string = await getRepoSlugAsync(terminal); | ||
| terminal.writeLine(`##vso[task.setvariable variable=GitHubRepoSlug;isOutput=true]${repoSlug}`); | ||
| terminal.writeLine(`Emitted GitHubRepoSlug: ${repoSlug}`); | ||
|
|
||
| const { value: rawToken, environmentVariable, longName } = this._githubTokenParameter; | ||
| let authHeader: IGitHubAuthorizationHeader; | ||
| if (rawToken) { | ||
| authHeader = parseGitHubAuthorizationHeader(rawToken); | ||
| terminal.writeLine(`Using ${environmentVariable} from environment or ${longName} as GitHub token`); | ||
| } else { | ||
| authHeader = await getGitHubAuthorizationHeaderAsync(terminal); | ||
| terminal.writeLine('Using git credential extraheader as fallback'); | ||
| } | ||
|
|
||
| terminal.writeLine( | ||
| `##vso[task.setvariable variable=GitHubToken;isSecret=true;isOutput=true]${authHeader.header}` | ||
| ); | ||
| terminal.writeLine('Emitted GitHubToken (secret)'); | ||
| } | ||
| } | ||
57 changes: 0 additions & 57 deletions
57
tools/repo-toolbox/src/cli/actions/EmitGitHubVarsAndTagBuildAction.ts
This file was deleted.
Oops, something went wrong.
44 changes: 44 additions & 0 deletions
44
tools/repo-toolbox/src/cli/actions/GitHubTokenActionBase.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. | ||
| // See LICENSE in the project root for license information. | ||
|
|
||
| import type { | ||
| ICommandLineActionOptions, | ||
| CommandLineStringParameter, | ||
| IRequiredCommandLineStringParameter | ||
| } from '@rushstack/ts-command-line'; | ||
| import { CommandLineAction } from '@rushstack/ts-command-line'; | ||
|
|
||
| export interface IGitHubTokenActionBaseOptions< | ||
| TTokenParameterRequired extends boolean | ||
| > extends ICommandLineActionOptions { | ||
| githubTokenRequired: TTokenParameterRequired; | ||
| } | ||
|
|
||
| /** | ||
| * Base class for actions that need a GitHub token. Defines a `--github-token` parameter | ||
| * backed by the `GITHUB_TOKEN` environment variable (set by the 1ES pipeline template's | ||
| * 'Get GitHub Token' step). Accepts either a raw installation token (e.g. `ghs_xxx`) or a | ||
| * full Authorization header value (e.g. `basic <base64>`). | ||
| */ | ||
| export abstract class GitHubTokenActionBase< | ||
| TTokenParameterRequired extends boolean, | ||
| TTokenParameter extends CommandLineStringParameter = TTokenParameterRequired extends true | ||
|
iclanton marked this conversation as resolved.
|
||
| ? IRequiredCommandLineStringParameter | ||
| : CommandLineStringParameter | ||
| > extends CommandLineAction { | ||
| protected readonly _githubTokenParameter: TTokenParameter; | ||
|
|
||
| protected constructor(options: IGitHubTokenActionBaseOptions<TTokenParameterRequired>) { | ||
| const { githubTokenRequired, ...otherOptions } = options; | ||
| super(otherOptions); | ||
|
|
||
| this._githubTokenParameter = this.defineStringParameter({ | ||
| parameterLongName: '--github-token', | ||
| argumentName: 'TOKEN', | ||
| environmentVariable: 'GITHUB_TOKEN', | ||
| description: | ||
| 'GitHub token. Accepts a raw installation token (e.g. `ghs_xxx`) or a full Authorization header value (e.g. `basic <base64>`).', | ||
| required: githubTokenRequired | ||
| }) as TTokenParameter; | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.