-
Notifications
You must be signed in to change notification settings - Fork 289
Expand file tree
/
Copy pathsecretFiles.ts
More file actions
97 lines (83 loc) · 2.69 KB
/
Copy pathsecretFiles.ts
File metadata and controls
97 lines (83 loc) · 2.69 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
import childProcess from 'child_process'
import fs from 'fs'
import { copySync } from 'fs-extra'
import { join } from 'path'
const argv = process.argv
const mylog = console.log
const _rootProjectDir = join(__dirname, '../')
let _currentPath = __dirname
const baseDir = join(_currentPath, '..')
const githubSshKey = process.env.GITHUB_SSH_KEY ?? join(baseDir, 'id_github')
const filePaths = [
{ file: 'deploy-config.json', path: './' },
{ file: 'env.json', path: './' },
{ file: 'fastlane.json', path: './' },
{ file: 'GoogleService-Info.plist', path: './ios/edge/' },
{ file: 'google-services.json', path: './android/app/' }
]
async function main() {
if (argv.length < 4) {
mylog(
'Usage: node -r sucrase/register secretFiles.ts [branch] [secret files path]'
)
mylog(' branch options: master, develop, beta')
}
const repoBranch = argv[2] // master or develop
const filesArg = argv[3] // edge or some other app
let filesDir: string
if (filesArg.startsWith('git@') && filesArg.endsWith('.git')) {
// Specified a git repo so clone into a local dir
filesDir = './jenkins-files'
chdir(baseDir)
fs.rmSync(filesDir, { recursive: true, force: true })
call(
`GIT_SSH_COMMAND="ssh -i ${githubSshKey}" git clone --depth 1 ${filesArg} ${filesDir}`
)
} else {
filesDir = filesArg
}
if (repoBranch.length < 3) throw new Error(`Invalid branch ${repoBranch}`)
if (filesDir.length < 3) throw new Error(`Invalid filesDir ${filesDir}`)
const copyFiles = (branch: string) => {
filePaths.forEach(filePath => {
const src = join(filesDir, branch, filePath.file)
const dest = join(_rootProjectDir, filePath.path, filePath.file)
quietCopy(src, dest)
})
// Copy keystores directory
const keystoreSrc = join(filesDir, branch, 'keystores')
if (fs.existsSync(keystoreSrc)) {
copySync(keystoreSrc, join(_rootProjectDir, 'keystores'))
}
}
// Always copy the files for the master branch first
copyFiles('master')
// Then copy the files for actual branch to overwrite those of master
if (repoBranch !== 'master') {
copyFiles(repoBranch)
}
}
// Copies a file if it exists and overwrites destination
function quietCopy(src: string, dest: string) {
if (fs.existsSync(src)) {
console.log(`Copying ${src} > ${dest}`)
fs.copyFileSync(src, dest)
}
}
function chdir(path: string) {
console.log('chdir: ' + path)
_currentPath = path
}
function call(cmdstring: string) {
console.log('call: ' + cmdstring)
childProcess.execSync(cmdstring, {
encoding: 'utf8',
timeout: 3600000,
stdio: 'inherit',
cwd: _currentPath,
killSignal: 'SIGKILL'
})
}
main().catch(e => {
console.log(e.message)
})