@@ -52,6 +52,7 @@ function _exec(command: string, args: string[], opts: { cwd?: string }, logger:
5252export interface SnapshotsOptions {
5353 force ?: boolean ;
5454 githubTokenFile ?: string ;
55+ githubToken ?: string ;
5556}
5657
5758export default function ( opts : SnapshotsOptions , logger : logging . Logger ) {
@@ -64,13 +65,18 @@ export default function(opts: SnapshotsOptions, logger: logging.Logger) {
6465 const root = fs . mkdtempSync ( path . join ( os . tmpdir ( ) , 'angular-devkit-publish-' ) ) ;
6566 const message = execSync ( `git log --format="%h %s" -n1` ) . toString ( ) . trim ( ) ;
6667
67- const githubToken = opts . githubTokenFile && fs . readFileSync ( opts . githubTokenFile , 'utf-8' ) ;
68+ const githubToken = opts . githubToken ||
69+ ( opts . githubTokenFile && fs . readFileSync ( opts . githubTokenFile , 'utf-8' ) ) ;
6870 logger . info ( 'Setting up global git name.' ) ;
69- if ( opts . githubTokenFile ) {
71+ if ( githubToken ) {
7072 _exec ( 'git' , [ 'config' , '--global' , 'user.email' , '[email protected] ' ] , { } , logger ) ; 7173 _exec ( 'git' , [ 'config' , '--global' , 'user.name' , 'Angular Builds' ] , { } , logger ) ;
74+ _exec ( 'git' , [ 'config' , '--global' , 'push.default' , 'simple' ] , { } , logger ) ;
7275 }
7376
77+ const gitCredentials = path . join ( process . env [ 'HOME' ] , '.git-credentials' ) ;
78+ fs . writeFileSync ( gitCredentials , `https://${ githubToken } @github.com` ) ;
79+
7480 // Run build.
7581 logger . info ( 'Building...' ) ;
7682 build ( { snapshot : true } , logger . createChild ( 'build' ) ) ;
@@ -95,12 +101,8 @@ export default function(opts: SnapshotsOptions, logger: logging.Logger) {
95101 _copy ( pkg . dist , destPath ) ;
96102
97103 if ( githubToken ) {
98- _exec ( 'git' , [ 'config' , 'credential.helper' , 'store --file=.git/credentials' ] ,
99- { cwd : destPath } , publishLogger ) ;
100104 _exec ( 'git' , [ 'config' , 'commit.gpgSign' , 'false' ] , { cwd : destPath } , publishLogger ) ;
101-
102- fs . writeFileSync ( path . join ( destPath , '.git/credentials' ) ,
103- `https://${ githubToken } @github.com` ) ;
105+ _exec ( 'git' , [ 'config' , 'credential.helper' , 'store' ] , { cwd : destPath } , publishLogger ) ;
104106 }
105107
106108 // Make sure that every snapshots is unique.
0 commit comments