File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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 }}'
Original file line number Diff line number Diff line change 11const core = require ( '@actions/core' )
22
33try {
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}
You can’t perform that action at this time.
0 commit comments