This repository was archived by the owner on Oct 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathbuild-locally-release.js
More file actions
executable file
·192 lines (151 loc) · 5.08 KB
/
Copy pathbuild-locally-release.js
File metadata and controls
executable file
·192 lines (151 loc) · 5.08 KB
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
#!/usr/bin/env node
// Copyright 2017-2020 @polkadot/dev authors & contributors
// SPDX-License-Identifier: Apache-2.0
const os = require('os');
const path = require('path');
const fs = require('fs');
const rimraf = require('rimraf');
const argv = require('yargs')
.options({
'skip-beta': {
description: 'Do not increment as beta',
type: 'boolean'
}
})
.strict().argv;
const copySync = require('@open-web3/dev-config/scripts/copySync.cjs');
const execSync = require('@open-web3/dev-config/scripts/execSync.cjs');
const repo = `https://${process.env.GH_PAT}@github.com/${process.env.GITHUB_REPOSITORY}.git`;
console.log('$ polkadot-ci-ghact-build', process.argv.slice(2).join(' '));
function runClean() {
execSync('yarn polkadot-dev-clean-build');
}
function runCheck() {
execSync('yarn lint');
}
function runTest() {
execSync('yarn test');
// if [ -f "coverage/lcov.info" ] && [ -n "$COVERALLS_REPO_TOKEN" ]; then
// console.log('*** Submitting to coveralls.io');
// (cat coverage/lcov.info | yarn run coveralls) || true
// fi
}
function runBuild() {
execSync('yarn build');
}
function npmGetVersion() {
return JSON.parse(fs.readFileSync(path.resolve(process.cwd(), 'package.json'), 'utf8')).version;
}
function npmSetup() {
const registry = 'registry.npmjs.org';
fs.writeFileSync(path.join(os.homedir(), '.npmrc'), `//${registry}/:_authToken=${process.env.NPM_TOKEN}`);
}
function npmPublish() {
if (fs.existsSync('.skip-npm')) {
return;
}
rimraf.sync('build/package.json');
['LICENSE', 'README.md', 'package.json'].forEach((file) => copySync(file, 'build'));
console.log('args', process.argv);
process.chdir('build');
const tag = npmGetVersion().includes('-') ? '--tag beta' : '';
let count = 1;
while (true) {
try {
execSync(`npm publish --access public ${tag}`);
break;
} catch (error) {
console.error(error);
if (count < 5) {
const end = Date.now() + 15000;
console.error(`Publish failed on attempt ${count}/5. Retrying in 15s`);
count++;
while (Date.now() < end) {
// just spin our wheels
}
}
}
}
process.chdir('..');
}
function gitSetup() {
execSync('git config push.default simple');
execSync('git config merge.ours.driver true');
execSync('git config user.name "Github Actions"');
execSync('git config user.email "action@github.com"');
execSync('git checkout master');
}
function gitBump() {
const currentVersion = npmGetVersion();
const [version, tag] = currentVersion.split('-');
const [, , patch] = version.split('.');
console.log(`currentVersion ${currentVersion} -<<>>-,version ${version} , tag ${tag} , patch ${patch}`);
if (tag) {
// if we have a beta version, just continue the stream of betas
execSync(`${path.join(__dirname, 'update-version.js')} prerelease`);
} else if (argv['skip-beta']) {
// don't allow beta versions
execSync(`${path.join(__dirname, 'update-version.js')} patch`);
} else if (patch === '0') {
// patch is .0, so publish this as an actual release (surely we did our job on beta)
execSync(`${path.join(__dirname, 'update-version.js')} patch`);
} else if (patch === '1') {
// continue with first new minor as beta
execSync(`${path.join(__dirname, 'update-version.js')} prerelease`);
} else {
// manual setting of version, make some changes so we can commit
fs.appendFileSync(path.join(process.cwd(), '.123trigger'), currentVersion);
}
execSync('git add --all .');
}
function gitPush() {
const version = npmGetVersion();
const doGHRelease = false;
// if (process.env.GH_RELEASE_GITHUB_API_TOKEN) {
// const changes = fs.readFileSync('CHANGELOG.md', 'utf8');
// if (changes.includes(`## ${version}`)) {
// doGHRelease = true;
// } else if (version.endsWith('.1')) {
// throw new Error(`Unable to release, no CHANGELOG entry for ${version}`);
// }
// }
execSync('git add --all .');
if (fs.existsSync('docs/README.md')) {
execSync('git add --all -f docs');
}
// add the skip checks for GitHub ...
execSync(`git commit --no-status --quiet -m "[CI Skip] release/${version.includes('-') ? 'beta' : 'stable'} ${version}
skip-checks: true"`);
execSync(`git push ${repo} HEAD:${process.env.GITHUB_REF}`, true);
if (doGHRelease) {
const files = process.env.GH_RELEASE_FILES ? `--assets ${process.env.GH_RELEASE_FILES}` : '';
execSync(`yarn polkadot-exec-ghrelease --draft ${files} --yes`);
}
}
function loopFunc(fn) {
if (fs.existsSync('packages')) {
fs.readdirSync('packages')
.filter((dir) => {
const pkgDir = path.join(process.cwd(), 'packages', dir);
return (
fs.statSync(pkgDir).isDirectory() &&
fs.existsSync(path.join(pkgDir, 'package.json')) &&
fs.existsSync(path.join(pkgDir, 'build'))
);
})
.forEach((dir) => {
process.chdir(path.join('packages', dir));
fn();
process.chdir('../..');
});
} else {
fn();
}
}
// gitBump();
runClean();
runCheck();
runTest();
runBuild();
// gitPush();
loopFunc(npmPublish);