Skip to content

Commit f3e1bf0

Browse files
Added support to ignore a pattern of files and to include a pattern of files (#5)
* Added support to ignore/include a pattern of files - We can control which files from a directory should be ignored or included by using a regex pattern. - This is useful for cases where we want to ignore certain files (e.g., temporary files, logs) or include specific files (e.g., configuration files) based on their names or extensions. * updated README * added the dist so we use this in actions
1 parent 80cbf1f commit f3e1bf0

File tree

4 files changed

+53
-1
lines changed

4 files changed

+53
-1
lines changed

README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,30 @@ user/repo:
195195

196196
> **Note:** the exclude file path is relative to the source path
197197

198+
### Include files that match a specific pattern
199+
200+
Using the includeFilePatterns you can filter the list of files that are synchronized to those that match the regex:
201+
202+
```yml
203+
user/repo:
204+
- source: workflows
205+
dest: .github/workflows/
206+
includeFilePatterns: "*.yml"
207+
```
208+
209+
### Exclude files that match a specific pattern
210+
211+
212+
Using the excludeFilePatterns you can filter out the list of files that are synchronized to those that match the regex:
213+
214+
```yml
215+
user/repo:
216+
- source: workflows
217+
dest: .github/workflows/
218+
excludeFilePatterns: "*.md"
219+
```
220+
221+
198222
### Don't replace existing file(s)
199223

200224
By default if a file already exists in the target repository, it will be replaced. You can change this behaviour by setting the `replace` option to `false`:

dist/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/config.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,8 @@ const parseFiles = (files) => {
195195
template: item.template === undefined ? TEMPLATE_DEFAULT : item.template,
196196
replace: item.replace === undefined ? REPLACE_DEFAULT : item.replace,
197197
deleteOrphaned: item.deleteOrphaned === undefined ? DELETE_ORPHANED_DEFAULT : item.deleteOrphaned,
198+
excludeFilePatterns: item.excludeFilePatterns === undefined ? [] : item.excludeFilePatterns,
199+
includeFilePatterns: item.includeFilePatterns === undefined ? [] : item.includeFilePatterns,
198200
exclude: parseExclude(item.exclude, item.source)
199201
}
200202
}

src/helpers.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,32 @@ export async function copy(src, dest, isDirectory, file) {
126126
return false
127127
}
128128
}
129+
130+
// Check if the file matches any of the excludeFilePatterns
131+
if (file.excludeFilePatterns.length > 0) {
132+
for (const pattern of file.excludeFilePatterns) {
133+
if (srcFile.match(pattern)) {
134+
core.debug(`Excluding file ${ srcFile } since it matches the excludeFilePattern ${ pattern }.`)
135+
return false
136+
}
137+
}
138+
}
139+
140+
// Check if the file matches any of the includeFilePatterns
141+
if (file.includeFilePatterns.length > 0) {
142+
let matches = false
143+
for (const pattern of file.includeFilePatterns) {
144+
if (srcFile.match(pattern)) {
145+
matches = true
146+
break
147+
}
148+
}
149+
150+
if (!matches) {
151+
core.debug(`Excluding file ${ srcFile } since it does not match any of the includeFilePatterns.`)
152+
return false
153+
}
154+
}
129155
return true
130156
}
131157

0 commit comments

Comments
 (0)