-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.yml
120 lines (105 loc) · 3.91 KB
/
action.yml
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
name: Replace tokens action
description: A GitHub action to replace tokens in a file, similar to envsubst
author: Jon LaBelle
branding:
icon: repeat
color: green
inputs:
paths:
description: >-
Replacement file path(s).
Specifies a path to one or more locations.
Specify multiple paths on separate lines using a multiline string `|`.
Wildcards are accepted.
The default location is the current directory (`.`).
Example: `./path/to/my/settings.json`
required: true
style:
description: >-
The style (or format) of the tokens that will be replaced.
Accepted values are `mustache/handlebars` (ex: `{{ VARIABLE }}`), `envsubst` (ex: `${VARIABLE}`), and `make` (ex: `$(VARIABLE)`).
The default token style is `mustache`.
required: false
default: 'mustache'
filter:
description: >-
Filter to qualify the `paths` parameter.
Only supports `*` and `?` wildcards.
Example: `*.json`
required: false
exclude:
description: >-
One or more string items or patterns to be matched, and excluded from the results.
Wildcard characters are accepted.
Specify multiple exclusions on separate lines using a multiline string `|`.
Example: `*dev*.json`
required: false
recurse:
description: >-
Whether or not to recurse directories.
The default is `false`, or no directory recursion.
required: false
default: 'false'
depth:
description: >-
Depth of directory recursion.
Only valid if the `recurse` option is enabled.
There default depth is not set.
required: false
default: '0'
follow-symlinks:
description: >-
Whether or not to follow symbolic links.
The default behavior is not to follow symbolic links.
required: false
default: 'false'
encoding:
description: >-
Encoding for file read/write operations.
The default is `utf8`, without the byte order mark (BOM).
Acceptable values are: `utf8`, `utf8BOM`, `ascii`, `ansi`, `bigendianunicode`, `bigendianutf32`, `oem`, `unicode`, `utf32`
required: false
default: 'utf8'
no-newline:
description: >-
Do not insert a newline at the end of the file.
The default behavior is to insert a newline at the end of the file.
required: false
default: 'false'
fail:
description: Fail the step if no tokens were replaced.
required: false
default: 'false'
runs:
using: composite
steps:
- name: Replace tokens
shell: pwsh
run: |
# Split multiline paths
$paths = '${{ inputs.paths }}' -split '\r?\n|\r' | Where-Object {$_.Trim() -ne ''}
$exclude = '${{ inputs.exclude }}' -split '\r?\n|\r' | Where-Object {$_.Trim() -ne ''}
$params = @{
Path = $paths
Filter = '${{ inputs.filter }}'
Recurse = [System.Convert]::ToBoolean('${{ inputs.recurse }}')
Depth = [System.Convert]::ToInt32('${{ inputs.depth }}')
FollowSymlinks = [System.Convert]::ToBoolean('${{ inputs.follow-symlinks }}')
Style = '${{ inputs.style }}'
Encoding = '${{ inputs.encoding }}'
NoNewline = [System.Convert]::ToBoolean('${{ inputs.no-newline }}')
Exclude = $exclude
}
$scriptPath = Join-Path -Path '${{ github.action_path }}' -ChildPath 'action.ps1'
$result = (& $scriptPath @params)
if ($? -eq $false) {
echo "::error title=✘ Failed::Review console output for errors"
exit 1
}
$fail = [System.Convert]::ToBoolean('${{ inputs.fail }}')
if (($fail -eq $true) -and ($result.Count -eq 0)) {
echo "::error title=✘ No operation performed::Ensure your token file paths are correct, and you have defined the appropriate tokens to replace."
exit 1
}
Write-Output -InputObject 'Tokens were replaced in the following file(s):'
Write-Output -InputObject $result