Repository: chanzuckerberg/fogg
Pull request #719 (2022-09-01 20:30:25)

fix: don't list nested dirs in modules folders ci
This PR fixes a bug where modules have next folders failing CICD checks.

### Summary
A description of changes or issues addressed by this PR. Provide links to relevant PRs if any.

### Test Plan
Say unittests, or list out steps to verify changes.

### References
(Optional) Additional links to provide more context.



Patch:
diff --git a/templates/templates/.github/workflows/fogg_ci.yml.tmpl b/templates/templates/.github/workflows/fogg_ci.yml.tmpl
index 5faa5198..f6c2a911 100644
--- a/templates/templates/.github/workflows/fogg_ci.yml.tmpl
+++ b/templates/templates/.github/workflows/fogg_ci.yml.tmpl
@@ -56,7 +56,7 @@ jobs:
             const changedFiles = {{`${{ steps.filter.outputs.changed_files }}`}}
             const changedDirs = changedFiles.map(f => path.dirname(f))
             console.log(`Found the following changed dirs: ${JSON.stringify(changedDirs, null, 2)}\n OG: ${JSON.stringify(changedFiles, null, 2)} `)
-            const changedModules = [... new Set(changedDirs.filter(d => d.indexOf("modules") !== -1))]
+            const changedModules = [... new Set(changedDirs.filter(d => d.indexOf("modules") !== -1 && d.split("/").length === 3))]
             const changedAccounts = [... new Set(changedDirs.filter(d => d.indexOf("accounts") !== -1 && d.split("/").length === 3))]
             const changedEnvs = [... new Set(changedDirs.filter(d => d.indexOf("envs") !== -1 && d.split("/").length === 4))]
             const allChanges = [...changedAccounts,...changedEnvs, ...changedModules]


Test patch:
diff --git a/testdata/github_actions/.github/workflows/fogg_ci.yml b/testdata/github_actions/.github/workflows/fogg_ci.yml
index 558fb4e6..4438e755 100644
--- a/testdata/github_actions/.github/workflows/fogg_ci.yml
+++ b/testdata/github_actions/.github/workflows/fogg_ci.yml
@@ -56,7 +56,7 @@ jobs:
             const changedFiles = ${{ steps.filter.outputs.changed_files }}
             const changedDirs = changedFiles.map(f => path.dirname(f))
             console.log(`Found the following changed dirs: ${JSON.stringify(changedDirs, null, 2)}\n OG: ${JSON.stringify(changedFiles, null, 2)} `)
-            const changedModules = [... new Set(changedDirs.filter(d => d.indexOf("modules") !== -1))]
+            const changedModules = [... new Set(changedDirs.filter(d => d.indexOf("modules") !== -1 && d.split("/").length === 3))]
             const changedAccounts = [... new Set(changedDirs.filter(d => d.indexOf("accounts") !== -1 && d.split("/").length === 3))]
             const changedEnvs = [... new Set(changedDirs.filter(d => d.indexOf("envs") !== -1 && d.split("/").length === 4))]
             const allChanges = [...changedAccounts,...changedEnvs, ...changedModules]
diff --git a/testdata/v2_full_yaml/.github/workflows/fogg_ci.yml b/testdata/v2_full_yaml/.github/workflows/fogg_ci.yml
index 558fb4e6..4438e755 100644
--- a/testdata/v2_full_yaml/.github/workflows/fogg_ci.yml
+++ b/testdata/v2_full_yaml/.github/workflows/fogg_ci.yml
@@ -56,7 +56,7 @@ jobs:
             const changedFiles = ${{ steps.filter.outputs.changed_files }}
             const changedDirs = changedFiles.map(f => path.dirname(f))
             console.log(`Found the following changed dirs: ${JSON.stringify(changedDirs, null, 2)}\n OG: ${JSON.stringify(changedFiles, null, 2)} `)
-            const changedModules = [... new Set(changedDirs.filter(d => d.indexOf("modules") !== -1))]
+            const changedModules = [... new Set(changedDirs.filter(d => d.indexOf("modules") !== -1 && d.split("/").length === 3))]
             const changedAccounts = [... new Set(changedDirs.filter(d => d.indexOf("accounts") !== -1 && d.split("/").length === 3))]
             const changedEnvs = [... new Set(changedDirs.filter(d => d.indexOf("envs") !== -1 && d.split("/").length === 4))]
             const allChanges = [...changedAccounts,...changedEnvs, ...changedModules]