Merge pull request #695 from actions/copilot/add-orchestration-id-user-agent
Some checks failed
CodeQL / Analyze (push) Has been cancelled
Check dist/ / check-dist (push) Has been cancelled
CI / ci (push) Has been cancelled
Integration / Integration test: return (push) Has been cancelled
Integration / Integration test: relative-path require (push) Has been cancelled
Integration / Integration test: npm package require (push) Has been cancelled
Integration / Integration test: GraphQL previews option (push) Has been cancelled
Integration / Integration test: user-agent option (push) Has been cancelled
Integration / Integration test: debug option (runner.debug mode disabled) (push) Has been cancelled
Licensed / Check licenses (push) Has been cancelled
Integration / Integration test: debug option (runner.debug mode enabled) (push) Has been cancelled
Integration / Integration test: base-url option (push) Has been cancelled

Add ACTIONS_ORCHESTRATION_ID to user-agent string
This commit is contained in:
Tingluo Huang 2026-01-07 10:23:37 -05:00 committed by GitHub
commit 450193c5ab
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 39 additions and 3 deletions

View file

@ -167,7 +167,7 @@ jobs:
exit 1 exit 1
fi fi
echo "- Validating user-agent set to an empty string" echo "- Validating user-agent set to an empty string"
expected="octokit-core.js/" expected="actions/github-script octokit-core.js/"
if [[ "${{steps.user-agent-empty.outputs.result}}" != "$expected"* ]]; then if [[ "${{steps.user-agent-empty.outputs.result}}" != "$expected"* ]]; then
echo $'::error::\u274C' "Expected user-agent to start with '$expected', got ${{steps.user-agent-empty.outputs.result}}" echo $'::error::\u274C' "Expected user-agent to start with '$expected', got ${{steps.user-agent-empty.outputs.result}}"
exit 1 exit 1

18
dist/index.js vendored
View file

@ -36267,9 +36267,11 @@ async function main() {
const retries = parseInt(core.getInput('retries')); const retries = parseInt(core.getInput('retries'));
const exemptStatusCodes = parseNumberArray(core.getInput('retry-exempt-status-codes')); const exemptStatusCodes = parseNumberArray(core.getInput('retry-exempt-status-codes'));
const [retryOpts, requestOpts] = getRetryOptions(retries, exemptStatusCodes, utils.defaults); const [retryOpts, requestOpts] = getRetryOptions(retries, exemptStatusCodes, utils.defaults);
const baseUserAgent = userAgent || 'actions/github-script';
const finalUserAgent = getUserAgentWithOrchestrationId(baseUserAgent);
const opts = { const opts = {
log: debug ? console : undefined, log: debug ? console : undefined,
userAgent: userAgent || undefined, userAgent: finalUserAgent,
previews: previews ? previews.split(',') : undefined, previews: previews ? previews.split(',') : undefined,
retry: retryOpts, retry: retryOpts,
request: requestOpts request: requestOpts
@ -36313,6 +36315,20 @@ function handleError(err) {
console.error(err); console.error(err);
core.setFailed(`Unhandled error: ${err}`); core.setFailed(`Unhandled error: ${err}`);
} }
/**
* Gets the user agent string with orchestration ID appended if available
* @param userAgent The base user agent string
* @returns The user agent string with orchestration ID appended if ACTIONS_ORCHESTRATION_ID is set
*/
function getUserAgentWithOrchestrationId(userAgent) {
const orchestrationId = process.env['ACTIONS_ORCHESTRATION_ID'];
if (!orchestrationId) {
return userAgent;
}
// Sanitize orchestration ID - replace invalid characters with underscore
const sanitized = orchestrationId.replace(/[^a-zA-Z0-9._-]/g, '_');
return `${userAgent} actions_orchestration_id/${sanitized}`;
}
})(); })();

View file

@ -39,9 +39,12 @@ async function main(): Promise<void> {
defaultGitHubOptions defaultGitHubOptions
) )
const baseUserAgent = userAgent || 'actions/github-script'
const finalUserAgent = getUserAgentWithOrchestrationId(baseUserAgent)
const opts: Options = { const opts: Options = {
log: debug ? console : undefined, log: debug ? console : undefined,
userAgent: userAgent || undefined, userAgent: finalUserAgent,
previews: previews ? previews.split(',') : undefined, previews: previews ? previews.split(',') : undefined,
retry: retryOpts, retry: retryOpts,
request: requestOpts request: requestOpts
@ -96,3 +99,20 @@ function handleError(err: any): void {
console.error(err) console.error(err)
core.setFailed(`Unhandled error: ${err}`) core.setFailed(`Unhandled error: ${err}`)
} }
/**
* Gets the user agent string with orchestration ID appended if available
* @param userAgent The base user agent string
* @returns The user agent string with orchestration ID appended if ACTIONS_ORCHESTRATION_ID is set
*/
function getUserAgentWithOrchestrationId(userAgent: string): string {
const orchestrationId = process.env['ACTIONS_ORCHESTRATION_ID']
if (!orchestrationId) {
return userAgent
}
// Sanitize orchestration ID - replace invalid characters with underscore
const sanitized = orchestrationId.replace(/[^a-zA-Z0-9._-]/g, '_')
return `${userAgent} actions_orchestration_id/${sanitized}`
}