Skip to content

Commit cefb08f

Browse files
chore(release): update to latest octokit and usage (ionic-team#20601)
- rename all references of `tag` to either `gitTag` or `npmTag` based on what they contain since this was confusing throughout - add the code to publish to git as a prerelease if the npm tag is `next` - log the version when asking if the npm tag is correct
1 parent 7187541 commit cefb08f

3 files changed

Lines changed: 29 additions & 26 deletions

File tree

.scripts/common.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ function projectPath(project) {
3636
return path.join(rootDir, project);
3737
}
3838

39-
async function askTag() {
39+
async function askNpmTag(version) {
4040
const prompts = [
4141
{
4242
type: 'list',
43-
name: 'tag',
43+
name: 'npmTag',
4444
message: 'Select npm tag or specify a new tag',
4545
choices: ['latest', 'next', 'v4-lts']
4646
.concat([
@@ -55,13 +55,13 @@ async function askTag() {
5555
type: 'confirm',
5656
name: 'confirm',
5757
message: answers => {
58-
return `Will publish to ${tc.cyan(answers.tag)}. Continue?`;
58+
return `Will publish ${tc.cyan(version)} to ${tc.cyan(answers.npmTag)}. Continue?`;
5959
}
6060
}
6161
];
6262

63-
const { tag, confirm } = await inquirer.prompt(prompts);
64-
return { tag, confirm };
63+
const { npmTag, confirm } = await inquirer.prompt(prompts);
64+
return { npmTag, confirm };
6565
}
6666

6767
function checkGit(tasks) {
@@ -310,7 +310,7 @@ function copyPackageToDist(tasks, packages) {
310310
});
311311
}
312312

313-
function publishPackages(tasks, packages, version, tag = 'latest') {
313+
function publishPackages(tasks, packages, version, npmTag = 'latest') {
314314
// first verify version
315315
packages.forEach(package => {
316316
if (package === 'core') {
@@ -338,9 +338,9 @@ function publishPackages(tasks, packages, version, tag = 'latest') {
338338
}
339339

340340
tasks.push({
341-
title: `${package}: publish to ${tag} tag`,
341+
title: `${package}: publish to ${npmTag} tag`,
342342
task: async () => {
343-
await execa('npm', ['publish', '--tag', tag], { cwd: projectRoot });
343+
await execa('npm', ['publish', '--tag', npmTag], { cwd: projectRoot });
344344
}
345345
});
346346
});
@@ -375,7 +375,7 @@ function copyCDNLoader(tasks, version) {
375375
module.exports = {
376376
checkTestDist,
377377
checkGit,
378-
askTag,
378+
askNpmTag,
379379
isValidVersion,
380380
isVersionGreater,
381381
copyCDNLoader,

.scripts/release.js

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const tc = require('turbocolor');
66
const execa = require('execa');
77
const Listr = require('listr');
88
const path = require('path');
9-
const octokit = require('@octokit/rest')()
9+
const { Octokit } = require('@octokit/rest');
1010
const common = require('./common');
1111
const fs = require('fs-extra');
1212

@@ -28,18 +28,18 @@ async function main() {
2828
// repo must be clean
2929
common.checkGit(tasks);
3030

31-
const { tag, confirm } = await common.askTag();
31+
const { npmTag, confirm } = await common.askNpmTag(version);
3232

3333
if (!confirm) {
3434
return;
3535
}
3636

3737
if(!dryRun) {
3838
// publish each package in NPM
39-
common.publishPackages(tasks, common.packages, version, tag);
39+
common.publishPackages(tasks, common.packages, version, npmTag);
4040

4141
// push tag to git remote
42-
publishGit(tasks, version, changelog);
42+
publishGit(tasks, version, changelog, npmTag);
4343
}
4444

4545
const listr = new Listr(tasks);
@@ -48,10 +48,10 @@ async function main() {
4848
// Dry run doesn't publish to npm or git
4949
if (dryRun) {
5050
console.log(`
51-
\n${tc.yellow('Did not publish. Remove the "--dry-run" flag to publish:')}\n${tc.green(version)} to ${tc.cyan(tag)}\n
51+
\n${tc.yellow('Did not publish. Remove the "--dry-run" flag to publish:')}\n${tc.green(version)} to ${tc.cyan(npmTag)}\n
5252
`);
5353
} else {
54-
console.log(`\nionic ${version} published to ${tag}!! 🎉\n`);
54+
console.log(`\nionic ${version} published to ${npmTag}!! 🎉\n`);
5555
}
5656

5757
} catch (err) {
@@ -70,13 +70,13 @@ function checkProductionRelease() {
7070
}
7171
}
7272

73-
function publishGit(tasks, version, changelog) {
74-
const tag = `v${version}`;
73+
function publishGit(tasks, version, changelog, npmTag) {
74+
const gitTag = `v${version}`;
7575

7676
tasks.push(
7777
{
78-
title: `Tag latest commit ${tc.dim(`(${tag})`)}`,
79-
task: () => execa('git', ['tag', `${tag}`], { cwd: common.rootDir })
78+
title: `Tag latest commit ${tc.dim(`(${gitTag})`)}`,
79+
task: () => execa('git', ['tag', `${gitTag}`], { cwd: common.rootDir })
8080
},
8181
{
8282
title: 'Push branches to remote',
@@ -88,7 +88,7 @@ function publishGit(tasks, version, changelog) {
8888
},
8989
{
9090
title: 'Publish Github release',
91-
task: () => publishGithub(version, tag, changelog)
91+
task: () => publishGithub(version, gitTag, changelog, npmTag)
9292
}
9393
);
9494
}
@@ -116,10 +116,12 @@ function findChangelog() {
116116
return lines.slice(start, end).join('\n').trim();
117117
}
118118

119-
async function publishGithub(version, tag, changelog) {
120-
octokit.authenticate({
121-
type: 'oauth',
122-
token: process.env.GH_TOKEN
119+
async function publishGithub(version, gitTag, changelog, npmTag) {
120+
// If the npm tag is next then publish as a prerelease
121+
const prerelease = npmTag === 'next' ? true : false;
122+
123+
const octokit = new Octokit({
124+
auth: process.env.GH_TOKEN
123125
});
124126

125127
let branch = await execa.stdout('git', ['symbolic-ref', '--short', 'HEAD']);
@@ -132,9 +134,10 @@ async function publishGithub(version, tag, changelog) {
132134
owner: 'ionic-team',
133135
repo: 'ionic',
134136
target_commitish: branch,
135-
tag_name: tag,
137+
tag_name: gitTag,
136138
name: version,
137139
body: changelog,
140+
prerelease: prerelease
138141
});
139142
}
140143

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"changelog": "conventional-changelog -p angular -i ./CHANGELOG.md -k core -s"
1010
},
1111
"devDependencies": {
12-
"@octokit/rest": "^15.2.6",
12+
"@octokit/rest": "^17.0.0",
1313
"conventional-changelog-cli": "^2.0.1",
1414
"execa": "^0.10.0",
1515
"fs-extra": "^7.0.0",

0 commit comments

Comments
 (0)