Skip to content

Commit

Permalink
🏗 Fix make release bug for release tagger (ampproject#35947)
Browse files Browse the repository at this point in the history
* get ref instead of release

* release note tweaks
  • Loading branch information
estherkim authored and Mahir committed Sep 9, 2021
1 parent 479a9b2 commit 71396b2
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 22 deletions.
15 changes: 8 additions & 7 deletions build-system/release-tagger/make-release.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const dedent = require('dedent');
const {
createRelease,
getPullRequestsBetweenCommits,
getRelease,
getRef,
} = require('./utils');
const {getExtensions, getSemver} = require('../npm-publish/utils');
const {GraphQlQueryResponseData} = require('@octokit/graphql'); //eslint-disable-line no-unused-vars
Expand Down Expand Up @@ -174,12 +174,13 @@ function _createBody(head, base, prs) {
${components.join('')}\
`;

const patched = head.slice(0, -3) + '000';
const cherrypickHeader = head.endsWith('0')
? ''
: dedent`\
<h2>🌸 Cherry-picked release 🌸</h2>
<a href="https://github.com/ampproject/amphtml/releases/tag/${base}">\
${base}</a> was patched and published as <b>${head}</b>. Refer to the \
<a href="https://github.com/ampproject/amphtml/releases/tag/${patched}">\
${patched}</a> was patched and published as <b>${head}</b>. Refer to the \
<a href="https://amp-release-calendar.appspot.com">release calendar</a> \
for additional channel information.\n\n`;
return cherrypickHeader + template;
Expand All @@ -193,12 +194,12 @@ function _createBody(head, base, prs) {
* @return {Promise<Object>}
*/
async function makeRelease(head, base, channel) {
const {'target_commitish': headCommit} = await getRelease(head);
const {'target_commitish': baseCommit} = await getRelease(base);
const prs = await getPullRequestsBetweenCommits(headCommit, baseCommit);
const {object: headRef} = await getRef(head);
const {object: baseRef} = await getRef(base);
const prs = await getPullRequestsBetweenCommits(headRef.sha, baseRef.sha);
const body = _createBody(head, base, prs);
const prerelease = prereleaseConfig[channel];
return await createRelease(head, headCommit, body, prerelease);
return await createRelease(head, headRef.sha, body, prerelease);
}

module.exports = {makeRelease};
30 changes: 15 additions & 15 deletions build-system/release-tagger/test/make-release.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@ test('create', async (t) => {
const packages = getExtensions().map((e) => e.extension);

const rest = nock('https://api.github.com')
// https://docs.github.com/en/rest/reference/repos#get-a-release-by-tag-name
.get('/repos/ampproject/amphtml/releases/tags/2107280123000')
// https://docs.github.com/en/rest/reference/git#get-a-reference
.get('/repos/ampproject/amphtml/git/ref/tags%2F2107280123000')
.reply(200, {
id: 2,
'target_commitish': '3abcdef',
object: {sha: '3abcdef'},
})
// https://docs.github.com/en/rest/reference/repos#get-a-release-by-tag-name
.get('/repos/ampproject/amphtml/releases/tags/2107210123000')
// https://docs.github.com/en/rest/reference/git#get-a-reference
.get('/repos/ampproject/amphtml/git/ref/tags%2F2107210123000')
.reply(200, {
id: 1,
'target_commitish': '1abcdef',
object: {sha: '1abcdef'},
})
// https://docs.github.com/en/rest/reference/repos#compare-two-commits
.get('/repos/ampproject/amphtml/compare/1abcdef...3abcdef')
Expand Down Expand Up @@ -189,17 +189,17 @@ test('cherry-pick', async (t) => {
const packages = getExtensions().map((e) => e.extension);

const rest = nock('https://api.github.com')
// https://docs.github.com/en/rest/reference/repos#get-a-release-by-tag-name
.get('/repos/ampproject/amphtml/releases/tags/2107280123001')
// https://docs.github.com/en/rest/reference/git#get-a-reference
.get('/repos/ampproject/amphtml/git/ref/tags%2F2107280123001')
.reply(200, {
id: 2,
'target_commitish': '2abcdef',
object: {sha: '2abcdef'},
})
// https://docs.github.com/en/rest/reference/repos#get-a-release-by-tag-name
.get('/repos/ampproject/amphtml/releases/tags/2107280123000')
// https://docs.github.com/en/rest/reference/git#get-a-reference
.get('/repos/ampproject/amphtml/git/ref/tags%2F2107210123000')
.reply(200, {
id: 1,
'target_commitish': '1abcdef',
object: {sha: '1abcdef'},
})
// https://docs.github.com/en/rest/reference/repos#compare-two-commits
.get('/repos/ampproject/amphtml/compare/1abcdef...2abcdef')
Expand All @@ -220,8 +220,8 @@ test('cherry-pick', async (t) => {
'release calendar</a> for additional channel information.\n\n' +
'<h2>Changelog</h2>\n<p>\n' +
'<a href="https://github.com/ampproject/amphtml/compare/' +
'2107280123000...2107280123001">\n' +
'<code>2107280123000...2107280123001</code>\n</a>\n</p>\n\n' +
'2107210123000...2107280123001">\n' +
'<code>2107210123000...2107280123001</code>\n</a>\n</p>\n\n' +
'<h2>npm packages @ 1.2107280123.1</h2>\n\n\n' +
`<b>Packages not changed:</b> <i>${packages.join(', ')}</i>\n\n` +
'<h2>Changes by component</h2>\n' +
Expand Down Expand Up @@ -272,7 +272,7 @@ test('cherry-pick', async (t) => {
},
});

await makeRelease('2107280123001', '2107280123000', 'stable');
await makeRelease('2107280123001', '2107210123000', 'stable');
t.true(rest.isDone());
t.true(graphql.isDone());
});
15 changes: 15 additions & 0 deletions build-system/release-tagger/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,20 @@ async function unlabelPullRequests(prs, labelId) {
return await _runQueryInBatches('mutation', mutations);
}

/**
* Get a git ref
* @param {string} tag
* @return {Promise<Object>}
*/
async function getRef(tag) {
const {data} = await octokit.rest.git.getRef({
owner,
repo,
ref: `tags/${tag}`,
});
return data;
}

module.exports = {
createRelease,
getLabel,
Expand All @@ -209,4 +223,5 @@ module.exports = {
labelPullRequests,
unlabelPullRequests,
updateRelease,
getRef,
};

0 comments on commit 71396b2

Please sign in to comment.