Skip to content

Commit 52b807d

Browse files
committed
feat: get mapped env
1 parent b0c5c1b commit 52b807d

2 files changed

Lines changed: 11 additions & 12 deletions

File tree

.github/workflows/test.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ jobs:
1111
uses: ./
1212
id: test
1313
env:
14-
master: daora
14+
master: prod
15+
staging: stg
1516
with:
16-
string: 'Test {master}'
17+
string: 'Env-{master}-{staging}'
1718
- name: Check equality
1819
run: 'echo ${{ steps.test.outputs.replaced }}'

index.js

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
11
const core = require('@actions/core')
22

33
try {
4-
// {([^}]+){1,}}
5-
// (?<={)(.*)(?=})
6-
const re = /{([^}]+){1,}}/g
4+
const re = /{([^}]+){1,}}/
5+
const globalRe = new RegExp(re, 'g')
76
const string = core.getInput('string')
8-
// const map = core.
9-
const ids = [...string.matchAll(re)].map(match => match[1])
10-
// console.log(map)
11-
console.log(ids)
12-
ids.forEach(id => {
13-
console.log(process.env[id])
7+
const ids = [...string.matchAll(globalRe)].map(match => match.slice(0, 2))
8+
let finalString = string
9+
ids.forEach(([toReplace, id]) => {
10+
const mappedId = process.env[id]
11+
finalString = finalString.replace(toReplace, mappedId || id)
1412
})
1513

16-
core.setOutput('replaced', string)
14+
core.setOutput('replaced', finalString)
1715
} catch (error) {
1816
core.setFailed(error.message)
1917
}

0 commit comments

Comments
 (0)