diff --git a/README.md b/README.md index 3f4401b..92c24fe 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,8 @@ See [action.yml](action.yml) # Can be 'space-delimited', 'csv', or 'json'. # Default: 'space-delimited' format: '' + # Filter files using a regex + filter: '*' ``` # Scenarios @@ -36,6 +38,8 @@ Consider using one of the other formats if that's the case. ```yaml - id: files uses: jitterbit/get-changed-files@v1 + with: + filter: '*.php' - run: | for changed_file in ${{ steps.files.outputs.all }}; do echo "Do something with this ${changed_file}." diff --git a/dist/index.js b/dist/index.js index 72c1662..85fc9d6 100644 --- a/dist/index.js +++ b/dist/index.js @@ -3517,6 +3517,7 @@ function run() { // Create GitHub client with the API token. const client = new github_1.GitHub(core.getInput('token', { required: true })); const format = core.getInput('format', { required: true }); + const filter = core.getInput('filter', { required: true }) || '*'; // Ensure that the format parameter is set properly. if (format !== 'space-delimited' && format !== 'csv' && format !== 'json') { core.setFailed(`Format must be one of 'string-delimited', 'csv', or 'json', got '${format}'.`); @@ -3570,8 +3571,9 @@ function run() { core.setFailed(`The head commit for this ${github_1.context.eventName} event is not ahead of the base commit. ` + "Please submit an issue on this action's GitHub repo."); } + const regex = new RegExp(`/${filter}\\b`, 'g'); // Get the changed files from the response payload. - const files = response.data.files; + const files = response.data.files.filter(file => file.filename.match(regex)); const all = [], added = [], modified = [], removed = [], renamed = [], addedModified = []; for (const file of files) { const filename = file.filename; diff --git a/src/main.ts b/src/main.ts index 0f0fdd6..c37750a 100644 --- a/src/main.ts +++ b/src/main.ts @@ -9,6 +9,7 @@ async function run(): Promise { // Create GitHub client with the API token. const client = new GitHub(core.getInput('token', {required: true})) const format = core.getInput('format', {required: true}) as Format + const filter = core.getInput('filter', {required: true}) || '*' // Ensure that the format parameter is set properly. if (format !== 'space-delimited' && format !== 'csv' && format !== 'json') { @@ -82,8 +83,9 @@ async function run(): Promise { ) } + const regex = new RegExp(`/${filter}\\b`, 'g') // Get the changed files from the response payload. - const files = response.data.files + const files = response.data.files.filter(file => file.filename.match(regex)) const all = [] as string[], added = [] as string[], modified = [] as string[],