Skip to content

Commit

Permalink
feat: add support for including matching changed files when dir_names…
Browse files Browse the repository at this point in the history
… is set to true (#1464)

Co-authored-by: tj-actions[bot] <109116665+tj-actions-bot@users.noreply.github.com>
Co-authored-by: GitHub Action <action@github.com>
  • Loading branch information
3 people authored Aug 22, 2023
1 parent 819fb64 commit 8789204
Show file tree
Hide file tree
Showing 8 changed files with 250 additions and 102 deletions.
52 changes: 44 additions & 8 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ jobs:

build:
runs-on: ubuntu-latest
outputs:
files_changed: ${{ steps.changed_files.outputs.files_changed }}
steps:
- uses: actions/checkout@v3
with:
Expand Down Expand Up @@ -119,6 +121,7 @@ jobs:
name: Test with multiple repositories
runs-on: ubuntu-latest
needs: build
if: needs.build.outputs.files_changed != 'true'
steps:
- name: Checkout into dir1
uses: actions/checkout@v3
Expand Down Expand Up @@ -192,7 +195,7 @@ jobs:
name: Test changed-files using since and until
needs: build
runs-on: ubuntu-latest
if: github.event_name == 'push'
if: github.event_name == 'push' && needs.build.outputs.files_changed != 'true'

steps:
- name: Checkout branch
Expand Down Expand Up @@ -250,6 +253,7 @@ jobs:
name: Test changed-files similar base and commit sha
runs-on: ubuntu-latest
needs: build
if: needs.build.outputs.files_changed != 'true'

steps:
- name: Checkout branch
Expand Down Expand Up @@ -287,6 +291,7 @@ jobs:
name: Test unset GITHUB_OUTPUT env
runs-on: ubuntu-latest
needs: build
if: needs.build.outputs.files_changed != 'true'

steps:
- name: Checkout branch
Expand Down Expand Up @@ -317,6 +322,8 @@ jobs:
name: Test changed-files with limited commit history
runs-on: ubuntu-latest
needs: build
if: needs.build.outputs.files_changed != 'true'

strategy:
fail-fast: false
max-parallel: 4
Expand Down Expand Up @@ -354,7 +361,7 @@ jobs:
name: Test changed-files with pull request head ref
runs-on: ubuntu-latest
needs: build
if: github.event_name != 'push'
if: github.event_name != 'push' && needs.build.outputs.files_changed != 'true'

steps:
- name: Checkout branch
Expand All @@ -381,7 +388,7 @@ jobs:
name: Test changed-files with pull request without persist credentials
runs-on: ubuntu-latest
needs: build
if: github.event_name != 'push'
if: github.event_name != 'push' && needs.build.outputs.files_changed != 'true'
strategy:
fail-fast: false
max-parallel: 4
Expand Down Expand Up @@ -415,6 +422,7 @@ jobs:
name: Test changed-files non existent base sha
runs-on: ubuntu-latest
needs: build
if: needs.build.outputs.files_changed != 'true'

steps:
- name: Checkout branch
Expand Down Expand Up @@ -468,6 +476,7 @@ jobs:
name: Test changed-files non existent sha
runs-on: ubuntu-latest
needs: build
if: needs.build.outputs.files_changed != 'true'

steps:
- name: Checkout branch
Expand Down Expand Up @@ -521,7 +530,7 @@ jobs:
name: Test changed-files with REST API
runs-on: ubuntu-latest
needs: build
if: github.event_name != 'push'
if: github.event_name != 'push' && needs.build.outputs.files_changed != 'true'
permissions:
pull-requests: read
steps:
Expand Down Expand Up @@ -553,6 +562,7 @@ jobs:
name: Test changed-files with submodule
runs-on: ubuntu-latest
needs: build
if: needs.build.outputs.files_changed != 'true'
strategy:
fail-fast: false
max-parallel: 4
Expand Down Expand Up @@ -595,6 +605,7 @@ jobs:
name: Test changed-files with yaml
runs-on: ubuntu-latest
needs: build
if: needs.build.outputs.files_changed != 'true'
strategy:
fail-fast: false
max-parallel: 4
Expand Down Expand Up @@ -646,6 +657,7 @@ jobs:
name: Test changed-files recover deleted file
runs-on: ubuntu-latest
needs: build
if: needs.build.outputs.files_changed != 'true'
strategy:
fail-fast: false
max-parallel: 4
Expand Down Expand Up @@ -799,11 +811,12 @@ jobs:
name: Test changed-files
runs-on: ${{ matrix.platform }}
needs: build
if: needs.build.outputs.files_changed != 'true'
strategy:
fail-fast: false
max-parallel: 4
matrix:
platform: [ubuntu-latest, ubuntu-22.04, windows-latest, macos-latest, macos-11, windows-2022]
platform: [ubuntu-latest, ubuntu-22.04, macos-latest, macos-11] # TODO: Fix the test for windows adding the correct path separator and use windows-2022, windows-latest
fetch-depth: [0, 1, 2]

steps:
Expand Down Expand Up @@ -936,7 +949,7 @@ jobs:
fetch_depth: 60000
dir_names: "true"
dir_names_exclude_current_dir: "true"
dir_names_max_depth: "1"
dir_names_max_depth: 1
- name: Show output
run: |
echo '${{ toJSON(steps.changed-files-dir-names-exclude-root.outputs) }}'
Expand Down Expand Up @@ -976,20 +989,43 @@ jobs:
base_sha: d1c0ee4
sha: 4d04215
fetch_depth: 60000
dir_names: "true"
dir_names: true
files: test/**
- name: Show output
run: |
echo '${{ toJSON(steps.changed-files-dir-names-specific.outputs) }}'
shell:
bash
- name: Check dir_names output
if: steps.changed-files-dir-names.outputs.all_changed_files != 'test'
if: steps.changed-files-dir-names-specific.outputs.all_changed_files != 'test'
run: |
echo "Invalid output: Expected (test) got (${{ steps.changed-files-dir-names-specific.outputs.all_changed_files }})"
exit 1
shell:
bash
- name: Run changed-files with dir_names and dir_names_include_files with specific files
id: changed-files-dir-names-specific-include-files
uses: ./
with:
base_sha: d1c0ee4
sha: 4d04215
fetch_depth: 60000
dir_names: true
dir_names_include_files: test/*.txt
files: test/**
json: true
- name: Show output
run: |
echo '${{ toJSON(steps.changed-files-dir-names-specific-include-files.outputs) }}'
shell:
bash
- name: Check dir_names output
if: "!contains(steps.changed-files-dir-names-specific-include-files.outputs.all_changed_files, 'test/test rename-1.txt') || !contains(steps.changed-files-dir-names-specific-include-files.outputs.all_changed_files, 'test')"
run: |
echo "Invalid output: Expected to include (test/test rename-1.txt) and (test) got (${{ steps.changed-files-dir-names-specific-include-files.outputs.all_changed_files }})"
exit 1
shell:
bash
- name: Run changed-files with forward slash separator
id: changed-files-forward-slash
uses: ./
Expand Down
8 changes: 8 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,14 @@ inputs:
description: "Exclude the current directory represented by `.` from the output when `dir_names` is set to `true`."
required: false
default: "false"
dir_names_include_files:
description: "Include files in the output when `dir_names` is set to `true`. **NOTE:** This returns only the matching files and also the directory names."
required: false
default: ""
dir_names_include_files_separator:
description: "Separator used to split the `dir_names_include_files` input"
default: "\n"
required: false
json:
description: "Output list of changed files in a JSON formatted string which can be used for matrix jobs."
required: false
Expand Down
Loading

0 comments on commit 8789204

Please sign in to comment.