-
Notifications
You must be signed in to change notification settings - Fork 309
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update release script to also create pr (#4880)
- Loading branch information
Showing
5 changed files
with
174 additions
and
65 deletions.
There are no files selected for viewing
This file contains 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 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 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,85 @@ | ||
'use strict' | ||
|
||
/* eslint-disable max-len */ | ||
|
||
const { capture, fatal } = require('./terminal') | ||
|
||
const requiredScopes = ['public_repo', 'read:org'] | ||
|
||
// Check that the `git` CLI is installed. | ||
function checkGit () { | ||
try { | ||
capture('git --version') | ||
} catch (e) { | ||
fatal( | ||
'The "git" CLI could not be found.', | ||
'Please visit https://git-scm.com/downloads for instructions to install.' | ||
) | ||
} | ||
} | ||
|
||
// Check that the `branch-diff` CLI is installed. | ||
function checkBranchDiff () { | ||
try { | ||
capture('branch-diff --version') | ||
} catch (e) { | ||
const link = [ | ||
'https://datadoghq.atlassian.net/wiki/spaces/DL/pages/3125511269/Node.js+Tracer+Release+Process', | ||
'#Install-and-Configure-branch-diff-to-automate-some-operations' | ||
].join('') | ||
fatal( | ||
'The "branch-diff" CLI could not be found.', | ||
`Please visit ${link} for instructions to install.` | ||
) | ||
} | ||
} | ||
|
||
// Check that the `gh` CLI is installed and authenticated. | ||
function checkGitHub () { | ||
if (!process.env.GITHUB_TOKEN && !process.env.GH_TOKEN) { | ||
const link = 'https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens#creating-a-personal-access-token-classic' | ||
|
||
fatal( | ||
'The GITHUB_TOKEN environment variable is missing.', | ||
`Please visit ${link} for instructions to generate a personal access token.`, | ||
`The following scopes are required when generating the token: ${requiredScopes.join(', ')}` | ||
) | ||
} | ||
|
||
try { | ||
capture('gh --version') | ||
} catch (e) { | ||
fatal( | ||
'The "gh" CLI could not be found.', | ||
'Please visit https://github.com/cli/cli#installation for instructions to install.' | ||
) | ||
} | ||
|
||
checkGitHubScopes() | ||
} | ||
|
||
// Check that the active GITHUB_TOKEN has the required scopes. | ||
function checkGitHubScopes () { | ||
const url = 'https://api.github.com' | ||
const headers = [ | ||
'Accept: application/vnd.github.v3+json', | ||
`Authorization: Bearer ${process.env.GITHUB_TOKEN || process.env.GH_TOKEN}`, | ||
'X-GitHub-Api-Version: 2022-11-28' | ||
].map(h => `-H "${h}"`).join(' ') | ||
|
||
const lines = capture(`curl -sS -I ${headers} ${url}`).trim().split(/\r?\n/g) | ||
const scopeLine = lines.find(line => line.startsWith('x-oauth-scopes:')) || '' | ||
const scopes = scopeLine.replace('x-oauth-scopes:', '').trim().split(', ') | ||
const link = 'https://github.com/settings/tokens' | ||
|
||
for (const req of requiredScopes) { | ||
if (!scopes.includes(req)) { | ||
fatal( | ||
`Missing "${req}" scope for GITHUB_TOKEN.`, | ||
`Please visit ${link} and make sure the following scopes are enabled: ${requiredScopes.join(' ,')}.` | ||
) | ||
} | ||
} | ||
} | ||
|
||
module.exports = { checkBranchDiff, checkGitHub, checkGit } |
This file contains 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,51 @@ | ||
'use strict' | ||
|
||
/* eslint-disable no-console */ | ||
|
||
const { execSync, spawnSync } = require('child_process') | ||
|
||
// Helpers for colored output. | ||
const log = (...msgs) => msgs.forEach(msg => console.log(msg)) | ||
const success = (...msgs) => msgs.forEach(msg => console.log(`\x1b[32m${msg}\x1b[0m`)) | ||
const error = (...msgs) => msgs.forEach(msg => console.log(`\x1b[31m${msg}\x1b[0m`)) | ||
const whisper = (...msgs) => msgs.forEach(msg => console.log(`\x1b[90m${msg}\x1b[0m`)) | ||
|
||
// Helpers for exiting with a message. | ||
const exit = (...msgs) => log(...msgs) || process.exit(0) | ||
const fatal = (...msgs) => error(...msgs) || process.exit(1) | ||
|
||
// Output a command to the terminal and execute it. | ||
function run (cmd) { | ||
whisper(`> ${cmd}`) | ||
|
||
const output = execSync(cmd, {}).toString() | ||
|
||
log(output) | ||
} | ||
|
||
// Ask a question in terminal and return the response. | ||
function prompt (question) { | ||
process.stdout.write(`${question} `) | ||
|
||
const child = spawnSync('bash', ['-c', 'read answer && echo $answer'], { | ||
stdio: ['inherit'] | ||
}) | ||
|
||
return child.stdout.toString() | ||
} | ||
|
||
// Ask whether to continue and otherwise exit the process. | ||
function checkpoint (question) { | ||
const answer = prompt(`${question} [Y/n]`).trim() | ||
|
||
if (answer && answer.toLowerCase() !== 'y') { | ||
process.exit(0) | ||
} | ||
} | ||
|
||
// Run a command and capture its output to return it to the caller. | ||
function capture (cmd) { | ||
return execSync(cmd, {}).toString() | ||
} | ||
|
||
module.exports = { capture, checkpoint, error, exit, fatal, log, success, run, whisper } |
This file contains 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