@@ -16,7 +16,8 @@ export async function configAuthentication(
1616 console . log (
1717 `creating ${ SETTINGS_FILE } with server-id: ${ id } , username: ${ username } , and a password`
1818 ) ;
19- const directory : string = path . join ( os . homedir ( ) , M2_DIR ) ;
19+ const home : string = process . env [ 'GITHUB_WORKSPACE' ] || os . homedir ( ) ;
20+ const directory : string = path . join ( home , M2_DIR ) ;
2021 await io . mkdirP ( directory ) ;
2122 core . debug ( `created directory ${ directory } ` ) ;
2223 await write ( directory , generate ( id , username , password ) ) ;
@@ -43,8 +44,17 @@ export function generate(id: string, username: string, password: string) {
4344}
4445
4546async function write ( directory : string , settings : string ) {
46- const options = { encoding : 'utf-8' } ;
47+ const options = { encoding : 'utf-8' , flag : 'wx' } ; // 'wx': Like 'w' but fails if path exists
4748 const location = path . join ( directory , SETTINGS_FILE ) ;
4849 console . log ( `writing ${ location } ` ) ;
49- return fs . writeFileSync ( location , settings , options ) ;
50+ try {
51+ return fs . writeFileSync ( location , settings , options ) ;
52+ } catch ( e ) {
53+ if ( e . code == fs . constants . O_EXCL ) {
54+ console . log ( `overwriting existing file ${ location } ` ) ;
55+ // default flag is 'w'
56+ return fs . writeFileSync ( location , settings , { encoding : 'utf-8' } ) ;
57+ }
58+ throw e ;
59+ }
5060}
0 commit comments