Skip to content

Commit 2259d3d

Browse files
committed
ci: add git user and email, plus proper logger
1 parent 999bab0 commit 2259d3d

File tree

1 file changed

+36
-7
lines changed

1 file changed

+36
-7
lines changed

scripts/snapshots.ts

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { execSync } from 'child_process';
1010
import * as fs from 'fs';
1111
import * as os from 'os';
1212
import * as path from 'path';
13+
import { Writable } from 'stream';
1314
import { packages } from '../lib/packages';
1415
import build from './build';
1516

@@ -31,6 +32,28 @@ function _copy(from: string, to: string) {
3132
}
3233

3334

35+
function _exec(command: string, opts: { cwd?: string }, logger: logging.Logger) {
36+
const infoLoggerStream = new Writable({
37+
write(chunk, _encoding, callback) {
38+
logger.info(chunk.toString());
39+
callback();
40+
},
41+
});
42+
const errorLoggerStream = new Writable({
43+
write(chunk, _encoding, callback) {
44+
logger.error(chunk.toString());
45+
callback();
46+
},
47+
});
48+
49+
logger.debug(`Running command "${JSON.stringify(command)}"...`);
50+
execSync(command, {
51+
...opts,
52+
stdio: [0, infoLoggerStream, errorLoggerStream],
53+
});
54+
}
55+
56+
3457
export interface SnapshotsOptions {
3558
force?: boolean;
3659
githubTokenFile: string;
@@ -48,6 +71,11 @@ export default function(opts: SnapshotsOptions, logger: logging.Logger) {
4871

4972
const githubToken = fs.readFileSync(opts.githubTokenFile, 'utf-8');
5073

74+
logger.info('Setting up global git name.');
75+
_exec(`git config --global user.email "[email protected]"`, {}, logger);
76+
_exec(`git config --global user.name "Angular Builds"`, {}, logger);
77+
78+
5179
// Run build.
5280
logger.info('Building...');
5381
build({ snapshot: true }, logger.createChild('build'));
@@ -66,22 +94,23 @@ export default function(opts: SnapshotsOptions, logger: logging.Logger) {
6694
publishLogger.debug('Temporary directory: ' + root);
6795

6896
const url = `https://github.com/${pkg.snapshotRepo}.git`;
69-
execSync(`git clone ${JSON.stringify(url)}`, { cwd: root });
97+
_exec(`git clone ${JSON.stringify(url)}`, { cwd: root }, publishLogger);
7098

7199
const destPath = path.join(root, path.basename(pkg.snapshotRepo));
72100
_copy(pkg.dist, destPath);
73101

74-
execSync(`git config credential.helper "store --file=.git/credentials"`, { cwd: destPath });
102+
_exec(`git config credential.helper "store --file=.git/credentials"`, { cwd: destPath },
103+
publishLogger);
75104
fs.writeFileSync(path.join(destPath, '.git/credentials'), `https://${githubToken}@github.com`);
76105

77106
// Make sure that every snapshots is unique.
78107
fs.writeFileSync(path.join(destPath, 'uniqueId'), '' + new Date());
79108

80109
// Commit and push.
81-
execSync(`git add -A`, { cwd: destPath });
82-
execSync(`git commit -am ${JSON.stringify(message)}`, { cwd: destPath });
83-
execSync(`git tag ${pkg.snapshotHash}`, { cwd: destPath });
84-
execSync(`git push origin`, { cwd: destPath });
85-
execSync(`git push --tags origin`, { cwd: destPath });
110+
_exec(`git add -A`, { cwd: destPath }, publishLogger);
111+
_exec(`git commit -am ${JSON.stringify(message)}`, { cwd: destPath }, publishLogger);
112+
_exec(`git tag ${pkg.snapshotHash}`, { cwd: destPath }, publishLogger);
113+
_exec(`git push origin`, { cwd: destPath }, publishLogger);
114+
_exec(`git push --tags origin`, { cwd: destPath }, publishLogger);
86115
}
87116
}

0 commit comments

Comments
 (0)