Replace tokens (GitHub action) replaces tokens in the text or code files with replacement values during the execution of the CI/CD process.
files
(Required) - File names (path included), comma-separated for multiple files.- Example:
file1, file2
- Example:
replacements
(Required) - Token (to be replaced) & value comma-separated pairs (TOKEN=value).- Example:
key1=value1, key2=value2
- Note:
- key & value pairs ignore leading & trailing whitespaces. Enclose within
[]
for such expressions. - key (token) cannot have any
=
but value can. Use a different key (token) in such case. - key, value or pairs can be CI/CD variables / secrets.
- key & value pairs ignore leading & trailing whitespaces. Enclose within
- Example:
delimiter
(Optional) - Defines separator/delimiter to be used, default value is comma (,
).- Example:
|
or;
or:
or-
etc. - Note: Ignores whitespaces.
- Example:
-
Example 1: Replace a token in a file.
- name: Replace Tokens uses: abhinavminhas/replace-tokens@main with: files: file replacements: key=value
-
Example 2: Replace multiple tokens in a file.
- name: Replace Tokens uses: abhinavminhas/replace-tokens@main with: files: file replacements: key1=value1, key2=value2
-
Example 3: Replace a token in multiple files.
- name: Replace Tokens uses: abhinavminhas/replace-tokens@main with: files: file1, file2 replacements: key=value
-
Example 4: Replace multiple tokens in multiple files.
- name: Replace Tokens uses: abhinavminhas/replace-tokens@main with: files: file1, file2 replacements: key1=value1, key2=value2
-
Example 5: Use a different separator than comma (
,
).- name: Replace Tokens uses: abhinavminhas/replace-tokens@main with: files: file1 | file2 replacements: key1=value1 | key2=value2 delimiter: '|'
- Note: The delimiter is enclosed within single quotation marks in the above example since yml interprets
|
as "Literal Block Scalar", also required for other reserved keywords.
- Note: The delimiter is enclosed within single quotation marks in the above example since yml interprets
Note: Implementation for above examples can be checked here.