-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
32 lines (31 loc) · 938 Bytes
/
index.js
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
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
for (let key in secrets) {
if (secrets[key] === 'SECRET_' + key) continue
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)
}