From 2b11abbc051dd341e15acc2fb04b3643d4242f53 Mon Sep 17 00:00:00 2001 From: Naka Masato Date: Fri, 5 Jan 2024 09:58:23 +0900 Subject: [PATCH 01/19] chore: update changed-files.yml --- .github/workflows/changed-files.yml | 34 ++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/.github/workflows/changed-files.yml b/.github/workflows/changed-files.yml index 3b0dacecf..6d0cf1856 100644 --- a/.github/workflows/changed-files.yml +++ b/.github/workflows/changed-files.yml @@ -3,12 +3,13 @@ on: pull_request: 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: | @@ -28,6 +29,7 @@ jobs: files_yaml: | test: - 'test-*' + - name: output change run: | { @@ -35,3 +37,33 @@ jobs: 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/app + json: true + files: 'check-change/**' + + 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) }} + needs: + - get-changed-dirs + steps: + - uses: actions/checkout@v3 + - run: echo "do sth on changed dir ${{ matrix.dir }}" From 258e4088e0119495eb8a16dbc378930c889484c3 Mon Sep 17 00:00:00 2001 From: Naka Masato Date: Fri, 5 Jan 2024 09:59:43 +0900 Subject: [PATCH 02/19] Update changed-files.yml --- .github/workflows/changed-files.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/changed-files.yml b/.github/workflows/changed-files.yml index 6d0cf1856..0ef405bed 100644 --- a/.github/workflows/changed-files.yml +++ b/.github/workflows/changed-files.yml @@ -60,7 +60,7 @@ jobs: 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: + matrix: dir: ${{ fromJson(needs.get-changed-dirs.outputs.changed_dirs) }} needs: - get-changed-dirs From 614b61c048f4654ae0c5ad88bf83cb43384dd166 Mon Sep 17 00:00:00 2001 From: Naka Masato Date: Fri, 5 Jan 2024 10:03:09 +0900 Subject: [PATCH 03/19] Update changed-files.yml --- .github/workflows/changed-files.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/changed-files.yml b/.github/workflows/changed-files.yml index 0ef405bed..142803fbc 100644 --- a/.github/workflows/changed-files.yml +++ b/.github/workflows/changed-files.yml @@ -56,6 +56,10 @@ jobs: json: true files: 'check-change/**' + - name: check output + run: | + echo "changed_dirs: ${{ steps.changed-files.outputs.all_changed_files }}" + 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. From 1462fd9974a84850e40602af0ff1305d8297c1d7 Mon Sep 17 00:00:00 2001 From: Naka Masato Date: Fri, 5 Jan 2024 10:08:11 +0900 Subject: [PATCH 04/19] fix if condition --- .github/workflows/changed-files.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/changed-files.yml b/.github/workflows/changed-files.yml index 142803fbc..edc95e79a 100644 --- a/.github/workflows/changed-files.yml +++ b/.github/workflows/changed-files.yml @@ -62,7 +62,7 @@ jobs: 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. + 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) }} From a2dff3f9db263423822040659c2b0cc568efd5c2 Mon Sep 17 00:00:00 2001 From: Naka Masato Date: Fri, 5 Jan 2024 10:10:01 +0900 Subject: [PATCH 05/19] Create test.csv --- check-change/test.csv | 1 + 1 file changed, 1 insertion(+) create mode 100644 check-change/test.csv diff --git a/check-change/test.csv b/check-change/test.csv new file mode 100644 index 000000000..136b09299 --- /dev/null +++ b/check-change/test.csv @@ -0,0 +1 @@ +test,test From 86b856280960b5e0a67fe63f6de4793317eccfca Mon Sep 17 00:00:00 2001 From: Naka Masato Date: Fri, 5 Jan 2024 10:10:30 +0900 Subject: [PATCH 06/19] Create test.txt --- check-change/test-2/test.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 check-change/test-2/test.txt diff --git a/check-change/test-2/test.txt b/check-change/test-2/test.txt new file mode 100644 index 000000000..9daeafb98 --- /dev/null +++ b/check-change/test-2/test.txt @@ -0,0 +1 @@ +test From bb59f57450117a2beb1b249bfc8353a192b8bdee Mon Sep 17 00:00:00 2001 From: Naka Masato Date: Fri, 5 Jan 2024 10:10:48 +0900 Subject: [PATCH 07/19] Create README.md --- check-change/test-2/README.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 check-change/test-2/README.md diff --git a/check-change/test-2/README.md b/check-change/test-2/README.md new file mode 100644 index 000000000..6a307c8cc --- /dev/null +++ b/check-change/test-2/README.md @@ -0,0 +1 @@ +# test-2 From 8128b8955d7c97ea9a7417dcc6eb2e25a02669ae Mon Sep 17 00:00:00 2001 From: Naka Masato Date: Fri, 5 Jan 2024 10:11:57 +0900 Subject: [PATCH 08/19] Update changed-files.yml --- .github/workflows/changed-files.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/changed-files.yml b/.github/workflows/changed-files.yml index edc95e79a..92e70d487 100644 --- a/.github/workflows/changed-files.yml +++ b/.github/workflows/changed-files.yml @@ -55,6 +55,7 @@ jobs: dir_names_max_depth: 2 # e.g. check-change/app json: true files: 'check-change/**' + files_ignore: 'README.md' - name: check output run: | From 6ce2ba9a357dc8d5131d65e8ad3be9705630f992 Mon Sep 17 00:00:00 2001 From: Naka Masato Date: Fri, 5 Jan 2024 10:15:51 +0900 Subject: [PATCH 09/19] write step summary --- .github/workflows/changed-files.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/changed-files.yml b/.github/workflows/changed-files.yml index 92e70d487..789240a7a 100644 --- a/.github/workflows/changed-files.yml +++ b/.github/workflows/changed-files.yml @@ -59,7 +59,7 @@ jobs: - name: check output run: | - echo "changed_dirs: ${{ steps.changed-files.outputs.all_changed_files }}" + echo "changed_dirs: ${{ steps.changed-files.outputs.all_changed_files }}" >> "$GITHUB_STEP_SUMMARY" do-sth-on-changed-dirs: runs-on: ubuntu-latest From 0381b78f5ff53465ef0a959991e277b19dd4c239 Mon Sep 17 00:00:00 2001 From: Naka Masato Date: Fri, 5 Jan 2024 10:16:51 +0900 Subject: [PATCH 10/19] ignore all readme --- .github/workflows/changed-files.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/changed-files.yml b/.github/workflows/changed-files.yml index 789240a7a..1ab008f08 100644 --- a/.github/workflows/changed-files.yml +++ b/.github/workflows/changed-files.yml @@ -55,7 +55,7 @@ jobs: dir_names_max_depth: 2 # e.g. check-change/app json: true files: 'check-change/**' - files_ignore: 'README.md' + files_ignore: '**/README.md' - name: check output run: | From 38f87108598adc0157e68e8c5ab27b304fbbe074 Mon Sep 17 00:00:00 2001 From: Naka Masato Date: Fri, 5 Jan 2024 10:17:36 +0900 Subject: [PATCH 11/19] Update and rename test.csv to README.md --- check-change/README.md | 1 + check-change/test.csv | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) create mode 100644 check-change/README.md delete mode 100644 check-change/test.csv diff --git a/check-change/README.md b/check-change/README.md new file mode 100644 index 000000000..a2506cd1e --- /dev/null +++ b/check-change/README.md @@ -0,0 +1 @@ +# check-change diff --git a/check-change/test.csv b/check-change/test.csv deleted file mode 100644 index 136b09299..000000000 --- a/check-change/test.csv +++ /dev/null @@ -1 +0,0 @@ -test,test From 1db2ec08e4aa6a81263c98abdce61b7782e64771 Mon Sep 17 00:00:00 2001 From: Naka Masato Date: Fri, 5 Jan 2024 10:19:34 +0900 Subject: [PATCH 12/19] remove fromJson --- .github/workflows/changed-files.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/changed-files.yml b/.github/workflows/changed-files.yml index 1ab008f08..2dd8526ed 100644 --- a/.github/workflows/changed-files.yml +++ b/.github/workflows/changed-files.yml @@ -66,7 +66,7 @@ jobs: 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) }} + dir: ${{ needs.get-changed-dirs.outputs.changed_dirs }} needs: - get-changed-dirs steps: From 0ead9535ba3f67dce8ff022ac0427f17eed7f552 Mon Sep 17 00:00:00 2001 From: Naka Masato Date: Fri, 5 Jan 2024 10:28:42 +0900 Subject: [PATCH 13/19] hardcode test --- .github/workflows/changed-files.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/changed-files.yml b/.github/workflows/changed-files.yml index 2dd8526ed..f9b2c38fd 100644 --- a/.github/workflows/changed-files.yml +++ b/.github/workflows/changed-files.yml @@ -66,7 +66,7 @@ jobs: if: ${{ needs.get-changed-dirs.outputs.changed_dirs != '[]' }} # Without it, the strategy parser will fail if the changed_directories is empty. strategy: matrix: - dir: ${{ needs.get-changed-dirs.outputs.changed_dirs }} + dir: ["check-change/test-2"] # ${{ fromJson(needs.get-changed-dirs.outputs.changed_dirs) }} needs: - get-changed-dirs steps: From db10c32a9a49d5988bbd24ae58702734dfc50e17 Mon Sep 17 00:00:00 2001 From: Naka Masato Date: Fri, 5 Jan 2024 10:30:26 +0900 Subject: [PATCH 14/19] summary --- .github/workflows/changed-files.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/changed-files.yml b/.github/workflows/changed-files.yml index f9b2c38fd..62bd1d8d4 100644 --- a/.github/workflows/changed-files.yml +++ b/.github/workflows/changed-files.yml @@ -71,4 +71,7 @@ jobs: - get-changed-dirs steps: - uses: actions/checkout@v3 - - run: echo "do sth on changed dir ${{ matrix.dir }}" + - run: | + echo "do sth on changed dir ${{ matrix.dir }}" >> "$GITHUB_STEP_SUMMARY" + - run: | + echo "json: ${{ fromJson(needs.get-changed-dirs.outputs.changed_dirs) }}" >> >> "$GITHUB_STEP_SUMMARY" From 4fa90d326aa1a503b86eaf67bab13c84646904e8 Mon Sep 17 00:00:00 2001 From: Naka Masato Date: Fri, 5 Jan 2024 10:34:07 +0900 Subject: [PATCH 15/19] escape_json: false --- .github/workflows/changed-files.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/changed-files.yml b/.github/workflows/changed-files.yml index 62bd1d8d4..57927eed5 100644 --- a/.github/workflows/changed-files.yml +++ b/.github/workflows/changed-files.yml @@ -54,8 +54,10 @@ jobs: dir_names: true dir_names_max_depth: 2 # e.g. check-change/app json: true + escape_json: false files: 'check-change/**' files_ignore: '**/README.md' + # Reference: https://github.com/tj-actions/changed-files/blob/main/.github/workflows/matrix-test.yml - name: check output run: | @@ -66,12 +68,10 @@ jobs: if: ${{ needs.get-changed-dirs.outputs.changed_dirs != '[]' }} # Without it, the strategy parser will fail if the changed_directories is empty. strategy: matrix: - dir: ["check-change/test-2"] # ${{ fromJson(needs.get-changed-dirs.outputs.changed_dirs) }} + dir: ${{ fromJson(needs.get-changed-dirs.outputs.changed_dirs) }} needs: - get-changed-dirs steps: - uses: actions/checkout@v3 - run: | echo "do sth on changed dir ${{ matrix.dir }}" >> "$GITHUB_STEP_SUMMARY" - - run: | - echo "json: ${{ fromJson(needs.get-changed-dirs.outputs.changed_dirs) }}" >> >> "$GITHUB_STEP_SUMMARY" From 9742423dd94ad12a0a64bb015a77825a025301ad Mon Sep 17 00:00:00 2001 From: Naka Masato Date: Fri, 5 Jan 2024 10:45:27 +0900 Subject: [PATCH 16/19] add exclude --- .github/workflows/changed-files.yml | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/.github/workflows/changed-files.yml b/.github/workflows/changed-files.yml index 57927eed5..550d7dfb2 100644 --- a/.github/workflows/changed-files.yml +++ b/.github/workflows/changed-files.yml @@ -2,6 +2,9 @@ name: changed-files on: pull_request: +env: + LOCAL_DIR_FOR_SYNC: check-change + jobs: changes-in-ga-steps: runs-on: ubuntu-latest @@ -52,10 +55,10 @@ jobs: uses: tj-actions/changed-files@v41 with: dir_names: true - dir_names_max_depth: 2 # e.g. check-change/app + dir_names_max_depth: 2 # e.g. check-change/test-2 json: true escape_json: false - files: 'check-change/**' + 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 @@ -69,6 +72,8 @@ jobs: 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: From c0b089e8dc157a0018cab3444545db15b493b97e Mon Sep 17 00:00:00 2001 From: Naka Masato Date: Fri, 5 Jan 2024 10:46:37 +0900 Subject: [PATCH 17/19] Update and rename README.md to file-to-ingnore.json --- check-change/README.md | 1 - check-change/file-to-ingnore.json | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) delete mode 100644 check-change/README.md create mode 100644 check-change/file-to-ingnore.json diff --git a/check-change/README.md b/check-change/README.md deleted file mode 100644 index a2506cd1e..000000000 --- a/check-change/README.md +++ /dev/null @@ -1 +0,0 @@ -# check-change diff --git a/check-change/file-to-ingnore.json b/check-change/file-to-ingnore.json new file mode 100644 index 000000000..7ba1b793e --- /dev/null +++ b/check-change/file-to-ingnore.json @@ -0,0 +1 @@ +{ "key": "value" } From 00ac20fcbc12d8ca8c075a5dbae7840372e11903 Mon Sep 17 00:00:00 2001 From: Naka Masato Date: Fri, 5 Jan 2024 10:48:44 +0900 Subject: [PATCH 18/19] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index c741152ae..ce76248b9 100644 --- a/README.md +++ b/README.md @@ -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 From 16648fb9b9940aef4d71098f03a390a6ad6f3f4b Mon Sep 17 00:00:00 2001 From: Naka Masato Date: Fri, 5 Jan 2024 10:57:41 +0900 Subject: [PATCH 19/19] Update changed-files.yml --- .github/workflows/changed-files.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/changed-files.yml b/.github/workflows/changed-files.yml index 550d7dfb2..d1a114add 100644 --- a/.github/workflows/changed-files.yml +++ b/.github/workflows/changed-files.yml @@ -1,6 +1,12 @@ name: changed-files on: pull_request: + branches: + - main + push: + branches: + - main + env: LOCAL_DIR_FOR_SYNC: check-change