Skip to content

Commit 5d78bbe

Browse files
author
azure-pipelines-bot
committed
Modernize release scripts with package updates and compatibility fixes
- Update all npm dependencies to latest versions: * @octokit/rest: v16.43.2 β†’ v22.0.0 * @octokit/graphql: v7.1.1 β†’ v9.0.1 * azure-devops-node-api: v12.0.0 β†’ v15.1.1 * azure-pipelines-task-lib: v4.3.1 β†’ v5.2.1 * node-getopt: v0.2.3 β†’ v0.3.2 - Fix createReleaseBranch.js compatibility with new @octokit versions: * Remove fetch parameter from GraphQL configuration * Implement selective dry-run mode (execute git operations except push) * Improve writeAgentVersionFile to always write file - Optimize createAdoPrs.js dependencies and functionality: * Replace got v14 with Node.js native fetch API * Remove got and node-fetch dependencies completely * Fix Azure DevOps API calls to respect dry-run mode properly - Enhance util.js error handling: * Add graceful handling for missing _hashes directory * Provide informative warnings for missing hash files - Comprehensive testing of all release scripts: * Verified fillReleaseNotesTemplate.js functionality * Tested rollrelease.js with GitHub PAT authentication * Validated createAdoPrs.js with improved dry-run behavior * Fixed npm audit security vulnerabilities All scripts now work correctly with updated dependencies and proper dry-run modes for safe testing.
1 parent 349341c commit 5d78bbe

File tree

5 files changed

+403
-2149
lines changed

5 files changed

+403
-2149
lines changed

β€Žrelease/createAdoPrs.jsβ€Ž

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ const fs = require('fs');
33
const path = require('path');
44
const tl = require('azure-pipelines-task-lib/task');
55
const util = require('./util');
6-
const got = require('got');
76

87
const INTEGRATION_DIR = path.join(__dirname, '..', '_layout', 'integrations');
98
const GIT = 'git';
@@ -121,6 +120,11 @@ async function openPR(repo, project, sourceBranch, targetBranch, commitMessage,
121120

122121
const pullRequest = { ...refs, title, description };
123122

123+
if (dryrun) {
124+
console.log('Dry run: Skipping Azure DevOps API calls for PR creation');
125+
return [-1, 'test']; // return without creating PR for test runs
126+
}
127+
124128
console.log('Getting Git API');
125129
const gitApi = await connection.getGitApi();
126130

@@ -129,8 +133,6 @@ async function openPR(repo, project, sourceBranch, targetBranch, commitMessage,
129133

130134
if (PR) {
131135
console.log('PR already exists');
132-
} else if (dryrun) {
133-
return [-1, 'test']; // return without creating PR for test runs
134136
} else {
135137
console.log('PR does not exist; creating PR');
136138
PR = await gitApi.createPullRequest(pullRequest, repo, project);
@@ -149,8 +151,9 @@ async function openPR(repo, project, sourceBranch, targetBranch, commitMessage,
149151
* @returns current sprint version
150152
*/
151153
async function getCurrentSprint() {
152-
const response = await got.get('https://whatsprintis.it/?json', { responseType: 'json' });
153-
const sprint = response.body.sprint;
154+
const response = await fetch('https://whatsprintis.it/?json');
155+
const data = await response.json();
156+
const sprint = data.sprint;
154157
if (!/^\d\d\d$/.test(sprint)) {
155158
throw new Error(`Sprint must be a three-digit number; received: ${sprint}`);
156159
}

β€Žrelease/createReleaseBranch.jsβ€Ž

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,14 @@ const util = require('./util');
66

77
const { Octokit } = require("@octokit/rest");
88
const { graphql } = require("@octokit/graphql");
9-
const fetch = require('node-fetch');
109

1110
const OWNER = 'microsoft';
1211
const REPO = 'azure-pipelines-agent';
1312
const GIT = 'git';
1413
const VALID_RELEASE_RE = /^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$/;
1514
const octokit = new Octokit({}); // only read-only operations, no need to auth
1615

17-
const graphqlWithFetch = graphql.defaults({ // Create a reusable GraphQL instance with fetch
18-
request: {
19-
fetch,
20-
},
16+
const graphqlWithAuth = graphql.defaults({
2117
headers: {
2218
authorization: process.env.PAT ? `token ${process.env.PAT}` : undefined,
2319
}
@@ -63,9 +59,8 @@ async function verifyNewReleaseTagOk(newRelease) {
6359

6460
function writeAgentVersionFile(newRelease) {
6561
console.log('Writing agent version file')
66-
if (!opt.options.dryrun) {
67-
fs.writeFileSync(path.join(__dirname, '..', 'src', 'agentversion'), `${newRelease}\n`);
68-
}
62+
// Always write the agent version file, even in dry-run mode
63+
fs.writeFileSync(path.join(__dirname, '..', 'src', 'agentversion'), `${newRelease}\n`);
6964
return newRelease;
7065
}
7166

@@ -102,7 +97,7 @@ async function fetchPRsForSHAsGraphQL(commitSHAs) {
10297
`;
10398

10499
try {
105-
var response = await graphqlWithFetch(fullQuery, {
100+
var response = await graphqlWithAuth(fullQuery, {
106101
repo: REPO,
107102
owner: OWNER,
108103
});
@@ -293,17 +288,17 @@ function editReleaseNotesFile(body) {
293288
}
294289

295290
function commitAndPush(directory, release, branch) {
296-
util.execInForeground(GIT + " checkout -b " + branch, directory, opt.options.dryrun);
297-
util.execInForeground(`${GIT} commit -m "Agent Release ${release}" `, directory, opt.options.dryrun);
298-
util.execInForeground(`${GIT} -c credential.helper='!f() { echo "username=pat"; echo "password=$PAT"; };f' push --set-upstream origin ${branch}`, directory, opt.options.dryrun);
291+
util.execInForeground(GIT + " checkout -b " + branch, directory, false); // Always execute checkout
292+
util.execInForeground(`${GIT} commit -m "Agent Release ${release}" `, directory, false); // Always execute commit
293+
util.execInForeground(`${GIT} -c credential.helper='!f() { echo "username=pat"; echo "password=$PAT"; };f' push --set-upstream origin ${branch}`, directory, opt.options.dryrun); // Only push respects dryrun
299294
}
300295

301296
function commitAgentChanges(directory, release) {
302297
var newBranch = `releases/${release}`;
303-
util.execInForeground(`${GIT} add ${path.join('src', 'agentversion')}`, directory, opt.options.dryrun);
304-
util.execInForeground(`${GIT} add releaseNote.md`, directory, opt.options.dryrun);
305-
util.execInForeground(`${GIT} config --global user.email "[email protected]"`, null, opt.options.dryrun);
306-
util.execInForeground(`${GIT} config --global user.name "azure-pipelines-bot"`, null, opt.options.dryrun);
298+
util.execInForeground(`${GIT} add ${path.join('src', 'agentversion')}`, directory, false); // Always execute add
299+
util.execInForeground(`${GIT} add releaseNote.md`, directory, false); // Always execute add
300+
util.execInForeground(`${GIT} config --global user.email "[email protected]"`, null, false); // Always execute config
301+
util.execInForeground(`${GIT} config --global user.name "azure-pipelines-bot"`, null, false); // Always execute config
307302
commitAndPush(directory, release, newBranch);
308303
}
309304

0 commit comments

Comments
Β (0)