-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
40 lines (39 loc) · 1.11 KB
/
Copy pathindex.js
File metadata and controls
40 lines (39 loc) · 1.11 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
const core = require('@actions/core')
try {
const file = core.getInput('file')
const secrets = JSON.parse(core.getInput('secrets'))
const fs = require('fs')
fs.readFile(file, {encoding: 'utf8'}, function (readError, data) {
if (readError) {
throw new Error('Error reading file: ' + readError)
}
let result = data
let sortedKeys = []
for (let key in secrets) {
if (secrets[key] === 'SECRET_' + key) continue
sortedKeys.push(key)
}
sortedKeys.sort(function(a,b) {
if (a.length > b.length) return -1
return b.length > a.length
})
for (let key of sortedKeys) {
while (result.indexOf('=SECRET_' + key) >= 0)
result = result.replace('=SECRET_' + key, '=' + secrets[key])
}
const matches = result.matchAll(/=SECRET_.+?\b/g)
const warnings = []
for (m of matches) {
if (warnings.indexOf(m[0]) >= 0) continue
warnings.push(m[0])
console.warn("Warning: Key not found. "+ m[0].substr(1))
}
fs.writeFile(file, result, function (writeError) {
if (writeError) {
console.log('Error writing file: ' + writeError)
}
})
})
} catch (error) {
core.setFailed(error.message)
}