Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,30 @@ user/repo:

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

### Include files that match a specific pattern

Using the includeFilePatterns you can filter the list of files that are synchronized to those that match the regex:

```yml
user/repo:
- source: workflows
dest: .github/workflows/
includeFilePatterns: "*.yml"
```

### Exclude files that match a specific pattern


Using the excludeFilePatterns you can filter out the list of files that are synchronized to those that match the regex:

```yml
user/repo:
- source: workflows
dest: .github/workflows/
excludeFilePatterns: "*.md"
```


### Don't replace existing file(s)

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`:
Expand Down
2 changes: 2 additions & 0 deletions src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,8 @@ const parseFiles = (files) => {
template: item.template === undefined ? TEMPLATE_DEFAULT : item.template,
replace: item.replace === undefined ? REPLACE_DEFAULT : item.replace,
deleteOrphaned: item.deleteOrphaned === undefined ? DELETE_ORPHANED_DEFAULT : item.deleteOrphaned,
excludeFilePatterns: item.excludeFilePatterns === undefined ? [] : item.excludeFilePatterns,
includeFilePatterns: item.includeFilePatterns === undefined ? [] : item.includeFilePatterns,
exclude: parseExclude(item.exclude, item.source)
}
}
Expand Down
26 changes: 26 additions & 0 deletions src/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,32 @@ export async function copy(src, dest, isDirectory, file) {
return false
}
}

// Check if the file matches any of the excludeFilePatterns
if (file.excludeFilePatterns.length > 0) {
for (const pattern of file.excludeFilePatterns) {
if (srcFile.match(pattern)) {
core.debug(`Excluding file ${ srcFile } since it matches the excludeFilePattern ${ pattern }.`)
return false
}
}
}

// Check if the file matches any of the includeFilePatterns
if (file.includeFilePatterns.length > 0) {
let matches = false
for (const pattern of file.includeFilePatterns) {
if (srcFile.match(pattern)) {
matches = true
break
}
}

if (!matches) {
core.debug(`Excluding file ${ srcFile } since it does not match any of the includeFilePatterns.`)
return false
}
}
return true
}

Expand Down