-
Notifications
You must be signed in to change notification settings - Fork 46
/
auto-release.js
142 lines (122 loc) · 5.21 KB
/
auto-release.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
//////////////////////////////////////////
// The script that is currently used to do Bolt releases, ignore all the pretenders!
//////////////////////////////////////////
const shell = require('shelljs');
const { IncomingWebhook } = require('@slack/webhook');
const chalk = require('chalk');
const semver = require('semver');
const { getLatestDeploy } = require('./scripts/utils');
const { gitSha } = require('./scripts/utils');
const { normalizeUrlAlias } = require('./scripts/utils/normalize-url-alias');
const { branchName } = require('./scripts/utils/branch-name');
const { NOW_TOKEN } = process.env;
const isFullRelease = branchName.startsWith('release');
const lernaConfig = require('./lerna.json');
const currentVersion = lernaConfig.version;
const SLACK_WEBHOOK_URL = process.env.SLACK_WEBHOOK_URL;
// force color output in CLI
// @ts-ignore
process.env.FORCE_COLOR = true;
async function getLernaPackages() {
const packages = shell.exec('lerna ls -pl', {
silent: true,
}).stdout;
const formattedPackages = [];
packages.split('\n').map(packageInfo => {
const [packagePath, name, version] = packageInfo.split(':');
if (packagePath && version) {
formattedPackages.push({ path: packagePath, name, version });
}
});
return formattedPackages;
}
async function init() {
if (isFullRelease) {
const version =
(await shell
.exec(`./node_modules/.bin/auto version --from v${currentVersion}`, {
silent: true,
maxBuffer: 20 * 1024 * 1024,
})
.stdout.trim()) || 'minor';
try {
const nextVersion = await semver.inc(currentVersion, version);
console.log('current version', currentVersion);
console.log('upcoming version type', version);
console.log('next version', nextVersion);
if (!currentVersion || !nextVersion || nextVersion === currentVersion) {
console.error(`Unknown version to publish to!`);
return;
} else {
await shell.exec(`
node scripts/release/update-php-package-versions.js -v ${nextVersion}
git add packages/twig-integration/twig-extensions-shared/composer.json packages/twig-integration/drupal-module/bolt_connect.info.yml packages/twig-integration/drupal-module/composer.json
git commit -m "[skip travis] chore: version bump PHP-related dependencies to v${nextVersion}"
`);
await shell.exec(`
git reset --hard
rm scripts/bolt-design-system-bot.private-key.pem
lerna publish ${version} --yes -m "[skip travis] chore(release): release %s"
`);
await shell.exec(`
./node_modules/.bin/auto release --from v${currentVersion} --use-version v${nextVersion}
`);
// get the version we just published
const releaseVersion = `v${nextVersion}`; // ex. v2.9.0
const branchSpecificUrl = await normalizeUrlAlias(branchName);
const tagSpecificUrl = await normalizeUrlAlias(releaseVersion);
const nowAliases = [];
nowAliases.push(branchSpecificUrl);
nowAliases.push(tagSpecificUrl);
nowAliases.push('www.boltdesignsystem.com');
nowAliases.push('boltdesignsystem.com');
nowAliases.push('www.bolt-design-system.com');
nowAliases.push('bolt-design-system.com');
nowAliases.push(await normalizeUrlAlias('latest'));
await shell.exec(`
npx json -I -f docs-site/.incache -e 'this["bolt-tags"].expiresOn = "2019-06-14T12:30:26.377Z"'
npx json -I -f docs-site/.incache -e 'this["bolt-urls-to-test"].expiresOn = "2019-06-14T12:30:26.377Z"'
npx now alias boltdesignsystem.com ${tagSpecificUrl} --token=${NOW_TOKEN}
npm run build
npx now deploy --meta gitSha='${gitSha}' --token=${NOW_TOKEN}
`);
const latestUrl = await getLatestDeploy();
nowAliases.forEach(alias => {
shell.exec(
`npx now alias ${latestUrl} ${alias} --token=${NOW_TOKEN}`,
);
});
await shell.exec(`
git add docs-site/.incache
git commit -m "[skip travis] chore: update .incache file"
git tag -fa ${releaseVersion} -m ${releaseVersion}
git push --no-verify
git push origin ${releaseVersion} --no-verify --force
git reset --hard HEAD
`);
if (nextVersion && nextVersion !== null && releaseVersion !== 'vnull') {
if (SLACK_WEBHOOK_URL) {
const webhook = new IncomingWebhook(SLACK_WEBHOOK_URL);
await webhook.send({
text: `Bolt \`${releaseVersion}\` has been released! Check out the <https://github.com/boltdesignsystem/bolt/releases/tag/${releaseVersion}|latest release notes> for more details!
- <https://boltdesignsystem.com|Updated Docs Site>`,
});
} else {
console.log(
chalk.yellow(
'Skipped sending Slack notification about upcoming Bolt release -- missing `SLACK_WEBPACK_URL` env variable!',
),
);
}
}
}
} catch (error) {
console.error(error);
}
} else {
console.log(
`Skipping doing an auto-release since the current branch, ${branchName}, isn't master or a release branch!`,
);
}
}
init();