Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: update changed-files.yml #981

Merged
merged 21 commits into from
Jan 5, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
54 changes: 53 additions & 1 deletion .github/workflows/changed-files.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
name: changed-files
on:
pull_request:
branches:
- main
push:
branches:
- main


env:
LOCAL_DIR_FOR_SYNC: check-change

jobs:
change-on-branch:
changes-in-ga-steps:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4
with:
fetch-depth: 0 # OR "2" -> To retrieve the preceding commit.

- name: add test.txt file
id: add-file
run: |
Expand All @@ -28,10 +38,52 @@ jobs:
files_yaml: |
test:
- 'test-*'

- name: output change
run: |
{
echo "any_changed: ${{ steps.changed-files-yaml.outputs.test_any_changed }}";
echo "all_changed_files: ${{ steps.changed-files-yaml.outputs.test_all_changed_files }}";
echo "add-file: ${{ steps.add-file.outputs.changed }}";
} >> "$GITHUB_STEP_SUMMARY"

get-changed-dirs:
runs-on: [ubuntu-latest]
outputs:
changed_dirs: ${{ steps.changed-files.outputs.all_changed_files }}
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0 # OR "2" -> To retrieve the preceding commit.

- name: get all changes
id: changed-files
uses: tj-actions/changed-files@v41
with:
dir_names: true
dir_names_max_depth: 2 # e.g. check-change/test-2
json: true
escape_json: false
files: "${{ env.LOCAL_DIR_FOR_SYNC }}/**"
files_ignore: '**/README.md'
# Reference: https://github.com/tj-actions/changed-files/blob/main/.github/workflows/matrix-test.yml

- name: check output
run: |
echo "changed_dirs: ${{ steps.changed-files.outputs.all_changed_files }}" >> "$GITHUB_STEP_SUMMARY"

do-sth-on-changed-dirs:
runs-on: ubuntu-latest
if: ${{ needs.get-changed-dirs.outputs.changed_dirs != '[]' }} # Without it, the strategy parser will fail if the changed_directories is empty.
strategy:
matrix:
dir: ${{ fromJson(needs.get-changed-dirs.outputs.changed_dirs) }}
exclude: # https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstrategymatrixexclude
- dir: check-change # exclude the parent dir (you can't use ${{ env.LOCAL_DIR_FOR_SYNC }} in matrix)
needs:
- get-changed-dirs
steps:
- uses: actions/checkout@v3
- name: "do sth on changed dir ${{ matrix.dir }}"
run: |
echo "do sth on changed dir ${{ matrix.dir }}" >> "$GITHUB_STEP_SUMMARY"
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
|[pre-commit](.github/workflows/pre-commit.yml)|pull_request|Run `pre-commit`.|
|[s3-local](.github/workflows/s3-local.yml)|pull_request|Use `minio` for s3 mock in GitHub Actions. **This workflow is broken❌.**|
|[terrraform-fmt](.github/workflows/terraform-fmt.yml)|pull_request|Run `terraform fmt` for `**.tf`.|
|[changed-files](.github/workflows/changed-files.yml)|pull_request|do sth for changed files/dir using https://github.com/tj-actions/changed-files|

### 2. release

Expand Down
1 change: 1 addition & 0 deletions check-change/file-to-ingnore.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ "key": "value" }
1 change: 1 addition & 0 deletions check-change/test-2/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# test-2
1 change: 1 addition & 0 deletions check-change/test-2/test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test
Loading