Skip to content

Commit

Permalink
Add case insensitive paths support (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
qetza authored May 1, 2024
1 parent 1347c6a commit 7c77d22
Show file tree
Hide file tree
Showing 7 changed files with 113 additions and 37 deletions.
7 changes: 4 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,22 +90,23 @@ jobs:
id: replace-tokens
with:
sources: |
**/*.json;!**/*.dev.json;!**/vars.json => _tmp/*.json
**/*.json;!**/*.DEV.json;!**/vars.json => _tmp/*.json
**/*.xml;!**.dev.xml => _tmp/*.xml
**/*.yml => _tmp/*.yml
**/*.YML => _tmp/*.yml
variables: >
[
${{ toJSON(vars) }},
${{ toJSON(secrets) }},
{ "var2": "#{INLINE}#value2", "inline": "inline_" },
${{ toJSON(format('@{0}/tests/data/vars.jsonc', github.workspace)) }},
"@**/*.(json|yml);!**/settings*",
"@**/*.(JSON|yml);!**/settings*",
"$ENV_VARS"
]
root: ${{ github.workspace }}/tests
log-level: debug
recursive: true
transforms: true
case-insensitive-paths: true
env:
ENV_VARS: '{ "var4": "env_value4" }'

Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Changelog
## v1.2.0
- Upgrade package `@qetza/replacetokens` to `1.7.0`.
- Add support for case insensitive path matching in _sources_ and _variables_.

## v1.1.2
- Change telemetry provider.
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ Please refer to the [release page](https://github.com/qetza/replacetokens-action
# Optional. Default: false
add-bom: ''

# Enable case-insensitive file path matching in glob patterns (sources and variables).
#
# Optional. Default: false
case-insensitive-paths: ''

# The characters to escape when using 'custom' escape.
#
# Optional.
Expand Down
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ inputs:
add-bom:
description: 'Add BOM when writing files.'
default: 'false'
case-insensitive-paths:
description: 'Enable case-insensitive file path matching in glob patterns (sources and variables).'
default: 'false'
chars-to-escape:
description: 'The characters to escape when using ''custom'' escape.'
encoding:
Expand Down
9 changes: 7 additions & 2 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -63664,6 +63664,9 @@ async function run() {
},
recursive: core.getBooleanInput('recursive'),
root: core.getInput('root'),
sources: {
caseInsensitive: core.getBooleanInput('case-insensitive-paths')
},
token: {
pattern: getChoiceInput('token-pattern', [
rt.TokenPatterns.AzurePipelines,
Expand Down Expand Up @@ -63714,11 +63717,12 @@ async function run() {
};
// load variables
const separator = core.getInput('separator') || rt.Defaults.Separator;
const variables = await getVariables(options.root, separator);
const variables = await getVariables(options.root, separator, options.sources.caseInsensitive);
// set telemetry attributes
telemetryEvent.setAttributes({
sources: sources.length,
'add-bom': options.addBOM,
'case-insensitive-paths': options.sources.caseInsensitive,
'chars-to-escape': options.escape.chars,
encoding: options.encoding,
escape: options.escape.type,
Expand Down Expand Up @@ -63802,11 +63806,12 @@ function getSources() {
var variableFilesCount = 0;
var variablesEnvCount = 0;
var inlineVariablesCount = 0;
async function getVariables(root, separator) {
async function getVariables(root, separator, caseInsensitive) {
const input = core.getInput('variables', { required: true, trimWhitespace: true }) || '';
if (!input)
return {};
return await rt.loadVariables(getVariablesFromJson(input), {
caseInsensitive: caseInsensitive,
normalizeWin32: true,
root: root,
separator: separator
Expand Down
13 changes: 11 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ export async function run(): Promise<void> {
},
recursive: core.getBooleanInput('recursive'),
root: core.getInput('root'),
sources: {
caseInsensitive: core.getBooleanInput('case-insensitive-paths')
},
token: {
pattern:
getChoiceInput('token-pattern', [
Expand Down Expand Up @@ -113,12 +116,13 @@ export async function run(): Promise<void> {

// load variables
const separator = core.getInput('separator') || rt.Defaults.Separator;
const variables = await getVariables(options.root, separator);
const variables = await getVariables(options.root, separator, options.sources!.caseInsensitive);

// set telemetry attributes
telemetryEvent.setAttributes({
sources: sources.length,
'add-bom': options.addBOM,
'case-insensitive-paths': options.sources!.caseInsensitive,
'chars-to-escape': options.escape!.chars,
encoding: options.encoding,
escape: options.escape!.type,
Expand Down Expand Up @@ -212,11 +216,16 @@ function getSources(): string[] {
var variableFilesCount = 0;
var variablesEnvCount = 0;
var inlineVariablesCount = 0;
async function getVariables(root?: string, separator?: string): Promise<{ [key: string]: string }> {
async function getVariables(
root?: string,
separator?: string,
caseInsensitive?: boolean
): Promise<{ [key: string]: string }> {
const input = core.getInput('variables', { required: true, trimWhitespace: true }) || '';
if (!input) return {};

return await rt.loadVariables(getVariablesFromJson(input), {
caseInsensitive: caseInsensitive,
normalizeWin32: true,
root: root,
separator: separator
Expand Down
Loading

0 comments on commit 7c77d22

Please sign in to comment.