Skip to content

Commit 01d0528

Browse files
committed
ci: fix publishing script
1 parent d57e3e9 commit 01d0528

1 file changed

Lines changed: 24 additions & 15 deletions

File tree

scripts/snapshots.ts

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -32,23 +32,26 @@ function _copy(from: string, to: string) {
3232

3333

3434
function _exec(command: string, args: string[], opts: { cwd?: string }, logger: logging.Logger) {
35-
logger.debug(`Running command "${JSON.stringify(command)}"...`);
36-
const { stdout, stderr, status, error } = spawnSync(command, args, {
37-
...opts,
38-
});
35+
logger.debug(`Running command ${JSON.stringify(command)} ${
36+
args.map(x => JSON.stringify(x)).join(' ')}...`);
37+
const { stdout, stderr, status, error } = spawnSync(command, args, { ...opts });
3938

40-
logger.error(stderr.toString());
39+
if (stderr.length) {
40+
logger.error(stderr.toString());
41+
}
4142
if (status != 0) {
4243
logger.fatal(error.message);
4344
throw error;
4445
}
45-
logger.info(stdout.toString());
46+
if (stdout.length) {
47+
logger.info(stdout.toString());
48+
}
4649
}
4750

4851

4952
export interface SnapshotsOptions {
5053
force?: boolean;
51-
githubTokenFile: string;
54+
githubTokenFile?: string;
5255
}
5356

5457
export default function(opts: SnapshotsOptions, logger: logging.Logger) {
@@ -61,11 +64,12 @@ export default function(opts: SnapshotsOptions, logger: logging.Logger) {
6164
const root = fs.mkdtempSync(path.join(os.tmpdir(), 'angular-devkit-publish-'));
6265
const message = execSync(`git log --format="%h %s" -n1`).toString().trim();
6366

64-
const githubToken = fs.readFileSync(opts.githubTokenFile, 'utf-8');
67+
const githubToken = opts.githubTokenFile && fs.readFileSync(opts.githubTokenFile, 'utf-8');
6568
logger.info('Setting up global git name.');
66-
_exec('git', ['config', '--global', 'user.email', '[email protected]'], {}, logger);
67-
_exec('git', ['config', '--global', 'user.name', 'Angular Builds'], {}, logger);
68-
69+
if (opts.githubTokenFile) {
70+
_exec('git', ['config', '--global', 'user.email', '[email protected]'], {}, logger);
71+
_exec('git', ['config', '--global', 'user.name', 'Angular Builds'], {}, logger);
72+
}
6973

7074
// Run build.
7175
logger.info('Building...');
@@ -90,16 +94,21 @@ export default function(opts: SnapshotsOptions, logger: logging.Logger) {
9094
const destPath = path.join(root, path.basename(pkg.snapshotRepo));
9195
_copy(pkg.dist, destPath);
9296

93-
_exec('git', ['config', 'credential.helper', 'store --file=.git/credentials'],
94-
{ cwd: root }, publishLogger);
95-
fs.writeFileSync(path.join(destPath, '.git/credentials'), `https://${githubToken}@github.com`);
97+
if (githubToken) {
98+
_exec('git', ['config', 'credential.helper', 'store --file=.git/credentials'],
99+
{ cwd: destPath }, publishLogger);
100+
_exec('git', ['config', 'commit.gpgSign', 'false'], { cwd: destPath }, publishLogger);
101+
102+
fs.writeFileSync(path.join(destPath, '.git/credentials'),
103+
`https://${githubToken}@github.com`);
104+
}
96105

97106
// Make sure that every snapshots is unique.
98107
fs.writeFileSync(path.join(destPath, 'uniqueId'), '' + new Date());
99108

100109
// Commit and push.
101110
_exec('git', ['add', '.'], { cwd: destPath }, publishLogger);
102-
_exec('git', ['commit', '-am', message], { cwd: destPath }, publishLogger);
111+
_exec('git', ['commit', '-a', '-m', message], { cwd: destPath }, publishLogger);
103112
_exec('git', ['tag', pkg.snapshotHash], { cwd: destPath }, publishLogger);
104113
_exec('git', ['push', 'origin'], { cwd: destPath }, publishLogger);
105114
_exec('git', ['push', '--tags', 'origin'], { cwd: destPath }, publishLogger);

0 commit comments

Comments
 (0)