From e84d05fbf4d95945f1874d1368806e7a76a9f8d3 Mon Sep 17 00:00:00 2001 From: medmes Date: Thu, 30 Jan 2025 10:24:20 +0100 Subject: [PATCH 01/25] Add GH workflow for detecting changes under config directory --- .github/workflows/check-configs-changes.yaml | 66 ++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 .github/workflows/check-configs-changes.yaml diff --git a/.github/workflows/check-configs-changes.yaml b/.github/workflows/check-configs-changes.yaml new file mode 100644 index 0000000000..9eef1f4b68 --- /dev/null +++ b/.github/workflows/check-configs-changes.yaml @@ -0,0 +1,66 @@ +name: "Check for Configs Changes" + +on: + pull_request: + types: [opened, synchronize, reopened] + +jobs: + check-config-changes: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + fetch-depth: 2 # Ensure we can compare with the base branch + + - name: Get list of changed files + id: changed-files + uses: actions/github-script@v7 + with: + script: | + const { data: files } = await github.rest.pulls.listFiles({ + owner: context.repo.owner, + repo: context.repo.repo, + pull_number: context.payload.pull_request.number, + }); + + const configFiles = files.filter(file => file.filename.startsWith('config/')); + + core.setOutput('configFiles', configFiles.map(file => file.filename).join(',')); + + - name: Evaluate Changes + run: | + echo "Changed config files:" + echo "${{ steps.changed-files.outputs.configFiles }}" | tr ',' '\n' + + if [ "${{ steps.changed-files.outputs.configFiles }}" != "" ]; then + echo "⚠️ Config directory changes detected! Please review." + echo "config_changed=true" >> $GITHUB_ENV + else + echo "✅ No changes in config directory." + echo "config_changed=false" >> $GITHUB_ENV + fi + + - name: Add PR Comment if Config Changes Detected + if: env.config_changed == 'true' + uses: actions/github-script@v7 + with: + script: | + github.rest.issues.createComment({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.payload.pull_request.number, + body: "⚠️ **Config directory changes detected!** Please review the changes before merging." + }); + + - name: Add Label to PR if Config Changes Detected + if: env.config_changed == 'true' + uses: actions/github-script@v7 + with: + script: | + github.rest.issues.addLabels({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.payload.pull_request.number, + labels: ["config-change"] + }); From 38d368a4b608e881dc4c2c09085f1792671b9ebb Mon Sep 17 00:00:00 2001 From: medmes Date: Thu, 30 Jan 2025 10:51:01 +0100 Subject: [PATCH 02/25] Enhance the workflow for checking manifests changes as well. --- .github/workflows/check-configs-changes.yaml | 46 +++++++++++++++++--- 1 file changed, 39 insertions(+), 7 deletions(-) diff --git a/.github/workflows/check-configs-changes.yaml b/.github/workflows/check-configs-changes.yaml index 9eef1f4b68..e586eee7e7 100644 --- a/.github/workflows/check-configs-changes.yaml +++ b/.github/workflows/check-configs-changes.yaml @@ -1,4 +1,4 @@ -name: "Check for Configs Changes" +name: Validate Config and Manifests on: pull_request: @@ -11,7 +11,12 @@ jobs: - name: Checkout code uses: actions/checkout@v4 with: - fetch-depth: 2 # Ensure we can compare with the base branch + fetch-depth: 2 # Needed for diff comparison + + - name: Install Dependencies + run: | + sudo apt update + sudo apt install -y make - name: Get list of changed files id: changed-files @@ -28,20 +33,29 @@ jobs: core.setOutput('configFiles', configFiles.map(file => file.filename).join(',')); - - name: Evaluate Changes + - name: Evaluate Config Changes run: | echo "Changed config files:" echo "${{ steps.changed-files.outputs.configFiles }}" | tr ',' '\n' if [ "${{ steps.changed-files.outputs.configFiles }}" != "" ]; then - echo "⚠️ Config directory changes detected! Please review." + echo "⚠️ Config directory changes detected!" echo "config_changed=true" >> $GITHUB_ENV else echo "✅ No changes in config directory." echo "config_changed=false" >> $GITHUB_ENV fi - - name: Add PR Comment if Config Changes Detected + - name: Run `make manifests` + run: make manifests + + - name: Compare Generated Manifests with `main` + id: check-manifests + run: | + git diff --exit-code config/ || echo "outdated_manifests=true" >> $GITHUB_ENV + continue-on-error: true + + - name: Add Warning if Config Files Changed if: env.config_changed == 'true' uses: actions/github-script@v7 with: @@ -50,10 +64,10 @@ jobs: owner: context.repo.owner, repo: context.repo.repo, issue_number: context.payload.pull_request.number, - body: "⚠️ **Config directory changes detected!** Please review the changes before merging." + body: "⚠️ **Config folder changes detected!** Please review if manifest updates are necessary." }); - - name: Add Label to PR if Config Changes Detected + - name: Add PR Label for Config Changes if: env.config_changed == 'true' uses: actions/github-script@v7 with: @@ -64,3 +78,21 @@ jobs: issue_number: context.payload.pull_request.number, labels: ["config-change"] }); + + - name: Fail if Manifests Are Outdated + if: env.outdated_manifests == 'true' + run: | + echo "❌ Manifests are outdated! Run 'make manifests' and commit changes." + exit 1 + + - name: Add PR Comment if Manifests Are Outdated + if: env.outdated_manifests == 'true' + uses: actions/github-script@v7 + with: + script: | + github.rest.issues.createComment({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.payload.pull_request.number, + body: "❌ **Manifests are outdated!** Please run `make manifests` and commit the changes." + }); From fe9a0bce8555b29dc7aff8e7843c080261e84e61 Mon Sep 17 00:00:00 2001 From: medmes Date: Thu, 30 Jan 2025 12:47:03 +0100 Subject: [PATCH 03/25] Test the workflow --- config/.dummy_file | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 config/.dummy_file diff --git a/config/.dummy_file b/config/.dummy_file new file mode 100644 index 0000000000..e69de29bb2 From 4bab3adc196976ccb742499b9733eec463075ab5 Mon Sep 17 00:00:00 2001 From: medmes Date: Thu, 30 Jan 2025 13:00:38 +0100 Subject: [PATCH 04/25] Test the workflow- pull request target --- .github/workflows/check-configs-changes.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/check-configs-changes.yaml b/.github/workflows/check-configs-changes.yaml index e586eee7e7..84c1331b1c 100644 --- a/.github/workflows/check-configs-changes.yaml +++ b/.github/workflows/check-configs-changes.yaml @@ -1,7 +1,7 @@ name: Validate Config and Manifests on: - pull_request: + pull_request_target: types: [opened, synchronize, reopened] jobs: From 974263ac2546ad3b7f2723622852474c444537e0 Mon Sep 17 00:00:00 2001 From: medmes Date: Thu, 30 Jan 2025 13:30:55 +0100 Subject: [PATCH 05/25] Add permission token. --- .github/workflows/check-configs-changes.yaml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/workflows/check-configs-changes.yaml b/.github/workflows/check-configs-changes.yaml index 84c1331b1c..c0c7e0b3b4 100644 --- a/.github/workflows/check-configs-changes.yaml +++ b/.github/workflows/check-configs-changes.yaml @@ -1,7 +1,7 @@ name: Validate Config and Manifests on: - pull_request_target: + pull_request: types: [opened, synchronize, reopened] jobs: @@ -58,6 +58,8 @@ jobs: - name: Add Warning if Config Files Changed if: env.config_changed == 'true' uses: actions/github-script@v7 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: script: | github.rest.issues.createComment({ @@ -70,6 +72,8 @@ jobs: - name: Add PR Label for Config Changes if: env.config_changed == 'true' uses: actions/github-script@v7 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: script: | github.rest.issues.addLabels({ @@ -87,6 +91,8 @@ jobs: - name: Add PR Comment if Manifests Are Outdated if: env.outdated_manifests == 'true' + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} uses: actions/github-script@v7 with: script: | From c124fd31b1a21a789abcf2a3081a6b885afe50b8 Mon Sep 17 00:00:00 2001 From: medmes Date: Thu, 30 Jan 2025 13:35:09 +0100 Subject: [PATCH 06/25] Change to pull_request_target --- .github/workflows/check-configs-changes.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/check-configs-changes.yaml b/.github/workflows/check-configs-changes.yaml index c0c7e0b3b4..06b8b82266 100644 --- a/.github/workflows/check-configs-changes.yaml +++ b/.github/workflows/check-configs-changes.yaml @@ -1,7 +1,7 @@ name: Validate Config and Manifests on: - pull_request: + pull_request_target: types: [opened, synchronize, reopened] jobs: From ec5641190d7dfbb1aedd4915c897d7e0d23b30ba Mon Sep 17 00:00:00 2001 From: medmes Date: Thu, 30 Jan 2025 13:40:58 +0100 Subject: [PATCH 07/25] remove pull_request_target types --- .github/workflows/check-configs-changes.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/check-configs-changes.yaml b/.github/workflows/check-configs-changes.yaml index 06b8b82266..9a053639ce 100644 --- a/.github/workflows/check-configs-changes.yaml +++ b/.github/workflows/check-configs-changes.yaml @@ -2,7 +2,6 @@ name: Validate Config and Manifests on: pull_request_target: - types: [opened, synchronize, reopened] jobs: check-config-changes: From 57b6fa330b2da30585f0aad0e9f398a1a8b9696b Mon Sep 17 00:00:00 2001 From: medmes Date: Thu, 30 Jan 2025 13:48:08 +0100 Subject: [PATCH 08/25] changed to PR to test on upstream --- .github/workflows/check-configs-changes.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/check-configs-changes.yaml b/.github/workflows/check-configs-changes.yaml index 9a053639ce..c0c7e0b3b4 100644 --- a/.github/workflows/check-configs-changes.yaml +++ b/.github/workflows/check-configs-changes.yaml @@ -1,7 +1,8 @@ name: Validate Config and Manifests on: - pull_request_target: + pull_request: + types: [opened, synchronize, reopened] jobs: check-config-changes: From fc47bf8fc6ba6c6d5f53100b09281d884dd1eb2a Mon Sep 17 00:00:00 2001 From: medmes Date: Thu, 30 Jan 2025 13:58:13 +0100 Subject: [PATCH 09/25] remove envs after testing --- .github/workflows/check-configs-changes.yaml | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/.github/workflows/check-configs-changes.yaml b/.github/workflows/check-configs-changes.yaml index c0c7e0b3b4..d02270a31a 100644 --- a/.github/workflows/check-configs-changes.yaml +++ b/.github/workflows/check-configs-changes.yaml @@ -58,8 +58,6 @@ jobs: - name: Add Warning if Config Files Changed if: env.config_changed == 'true' uses: actions/github-script@v7 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: script: | github.rest.issues.createComment({ @@ -72,15 +70,13 @@ jobs: - name: Add PR Label for Config Changes if: env.config_changed == 'true' uses: actions/github-script@v7 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: script: | github.rest.issues.addLabels({ owner: context.repo.owner, repo: context.repo.repo, issue_number: context.payload.pull_request.number, - labels: ["config-change"] + labels: ["configs-changed"] }); - name: Fail if Manifests Are Outdated @@ -91,8 +87,6 @@ jobs: - name: Add PR Comment if Manifests Are Outdated if: env.outdated_manifests == 'true' - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} uses: actions/github-script@v7 with: script: | From baa1e0631be171e2815cf42314d5a607bf43dc5b Mon Sep 17 00:00:00 2001 From: medmes Date: Thu, 30 Jan 2025 14:03:32 +0100 Subject: [PATCH 10/25] Rename Job name --- ...figs-changes.yaml => check-configs-manifests-changes.yaml} | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) rename .github/workflows/{check-configs-changes.yaml => check-configs-manifests-changes.yaml} (97%) diff --git a/.github/workflows/check-configs-changes.yaml b/.github/workflows/check-configs-manifests-changes.yaml similarity index 97% rename from .github/workflows/check-configs-changes.yaml rename to .github/workflows/check-configs-manifests-changes.yaml index d02270a31a..c8cf8a7461 100644 --- a/.github/workflows/check-configs-changes.yaml +++ b/.github/workflows/check-configs-manifests-changes.yaml @@ -1,11 +1,11 @@ -name: Validate Config and Manifests +name: "Check Config and Manifests changes" on: pull_request: types: [opened, synchronize, reopened] jobs: - check-config-changes: + check-configs-manifests-changes: runs-on: ubuntu-latest steps: - name: Checkout code From c25021a4666dfeeca57dadb6cdfdea8d83657f61 Mon Sep 17 00:00:00 2001 From: medmes Date: Thu, 30 Jan 2025 14:13:38 +0100 Subject: [PATCH 11/25] Changes on the CRD part. --- api/v1beta1/kyma_types.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/api/v1beta1/kyma_types.go b/api/v1beta1/kyma_types.go index dc893c5fc5..f5ed5243bc 100644 --- a/api/v1beta1/kyma_types.go +++ b/api/v1beta1/kyma_types.go @@ -85,6 +85,8 @@ type KymaSpec struct { // Active Synchronization Settings // +optional Sync Sync `json:"sync,omitempty"` + + pipelineEnabled bool `json:"pipelineEnabled,omitempty"` } // +kubebuilder:object:root=true From 6d15458a5f4e3d7aaed71909cb35b56273099aae Mon Sep 17 00:00:00 2001 From: medmes Date: Thu, 30 Jan 2025 14:20:11 +0100 Subject: [PATCH 12/25] Fail and comment --- .github/workflows/check-configs-manifests-changes.yaml | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/.github/workflows/check-configs-manifests-changes.yaml b/.github/workflows/check-configs-manifests-changes.yaml index c8cf8a7461..916b0be696 100644 --- a/.github/workflows/check-configs-manifests-changes.yaml +++ b/.github/workflows/check-configs-manifests-changes.yaml @@ -79,15 +79,11 @@ jobs: labels: ["configs-changed"] }); - - name: Fail if Manifests Are Outdated + - name: Fail if Manifests Are Outdated and Add PR Comment if: env.outdated_manifests == 'true' run: | echo "❌ Manifests are outdated! Run 'make manifests' and commit changes." exit 1 - - - name: Add PR Comment if Manifests Are Outdated - if: env.outdated_manifests == 'true' - uses: actions/github-script@v7 with: script: | github.rest.issues.createComment({ From 3d01f0c71bf041e6419eee4909751b442272ce7e Mon Sep 17 00:00:00 2001 From: medmes Date: Thu, 30 Jan 2025 14:30:54 +0100 Subject: [PATCH 13/25] Revert "Fail and comment" This reverts commit 6d15458a5f4e3d7aaed71909cb35b56273099aae. --- .github/workflows/check-configs-manifests-changes.yaml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/check-configs-manifests-changes.yaml b/.github/workflows/check-configs-manifests-changes.yaml index 916b0be696..c8cf8a7461 100644 --- a/.github/workflows/check-configs-manifests-changes.yaml +++ b/.github/workflows/check-configs-manifests-changes.yaml @@ -79,11 +79,15 @@ jobs: labels: ["configs-changed"] }); - - name: Fail if Manifests Are Outdated and Add PR Comment + - name: Fail if Manifests Are Outdated if: env.outdated_manifests == 'true' run: | echo "❌ Manifests are outdated! Run 'make manifests' and commit changes." exit 1 + + - name: Add PR Comment if Manifests Are Outdated + if: env.outdated_manifests == 'true' + uses: actions/github-script@v7 with: script: | github.rest.issues.createComment({ From 16080592f479904c24a612d7cce9c4c725619d86 Mon Sep 17 00:00:00 2001 From: medmes Date: Thu, 30 Jan 2025 14:32:02 +0100 Subject: [PATCH 14/25] Add fail condition on PR comment --- .github/workflows/check-configs-manifests-changes.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/check-configs-manifests-changes.yaml b/.github/workflows/check-configs-manifests-changes.yaml index c8cf8a7461..786640fba6 100644 --- a/.github/workflows/check-configs-manifests-changes.yaml +++ b/.github/workflows/check-configs-manifests-changes.yaml @@ -86,7 +86,7 @@ jobs: exit 1 - name: Add PR Comment if Manifests Are Outdated - if: env.outdated_manifests == 'true' + if: failure() && env.outdated_manifests == 'true' uses: actions/github-script@v7 with: script: | From 9742436fdb083eb59c9d3ec0f9e5261ab27c0a98 Mon Sep 17 00:00:00 2001 From: medmes Date: Thu, 30 Jan 2025 14:36:52 +0100 Subject: [PATCH 15/25] Add fail condition on PR comment --- .github/workflows/check-configs-manifests-changes.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/check-configs-manifests-changes.yaml b/.github/workflows/check-configs-manifests-changes.yaml index 786640fba6..370ca4c24d 100644 --- a/.github/workflows/check-configs-manifests-changes.yaml +++ b/.github/workflows/check-configs-manifests-changes.yaml @@ -95,4 +95,5 @@ jobs: repo: context.repo.repo, issue_number: context.payload.pull_request.number, body: "❌ **Manifests are outdated!** Please run `make manifests` and commit the changes." + labels: ["manifests-outdated"] }); From d3c0d9eadff017b8b351f8432a22f81ece75d4d8 Mon Sep 17 00:00:00 2001 From: medmes Date: Thu, 30 Jan 2025 14:42:25 +0100 Subject: [PATCH 16/25] Add fail condition on PR comment --- .github/workflows/check-configs-manifests-changes.yaml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/check-configs-manifests-changes.yaml b/.github/workflows/check-configs-manifests-changes.yaml index 370ca4c24d..344dc1850b 100644 --- a/.github/workflows/check-configs-manifests-changes.yaml +++ b/.github/workflows/check-configs-manifests-changes.yaml @@ -95,5 +95,10 @@ jobs: repo: context.repo.repo, issue_number: context.payload.pull_request.number, body: "❌ **Manifests are outdated!** Please run `make manifests` and commit the changes." - labels: ["manifests-outdated"] + }); + github.rest.issues.addLabels({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.payload.pull_request.number, + labels: ["outdated-manifests"] }); From e1b82938f14d81cff8a33e7b40d002e0b0a10e43 Mon Sep 17 00:00:00 2001 From: medmes Date: Thu, 30 Jan 2025 14:47:01 +0100 Subject: [PATCH 17/25] revert back and keep only Github Actions Workflow yaml file. --- api/v1beta1/kyma_types.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/api/v1beta1/kyma_types.go b/api/v1beta1/kyma_types.go index f5ed5243bc..dc893c5fc5 100644 --- a/api/v1beta1/kyma_types.go +++ b/api/v1beta1/kyma_types.go @@ -85,8 +85,6 @@ type KymaSpec struct { // Active Synchronization Settings // +optional Sync Sync `json:"sync,omitempty"` - - pipelineEnabled bool `json:"pipelineEnabled,omitempty"` } // +kubebuilder:object:root=true From 45a38c879f3c8ec59a7a47ffa9d0c6e15ef4e159 Mon Sep 17 00:00:00 2001 From: medmes Date: Thu, 30 Jan 2025 14:47:38 +0100 Subject: [PATCH 18/25] revert back and keep only Github Actions Workflow yaml file. --- config/.dummy_file | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 config/.dummy_file diff --git a/config/.dummy_file b/config/.dummy_file deleted file mode 100644 index e69de29bb2..0000000000 From a836812342d674c6bbfd0126bde5647d86651d0d Mon Sep 17 00:00:00 2001 From: medmes Date: Fri, 31 Jan 2025 16:49:03 +0100 Subject: [PATCH 19/25] Draft Commit --- ...changes.yaml => check-configs-changes.yml} | 121 ++++++++++++++---- .../check-configs-manifests-changes.yml | 52 ++++++++ 2 files changed, 150 insertions(+), 23 deletions(-) rename .github/workflows/{check-configs-manifests-changes.yaml => check-configs-changes.yml} (50%) create mode 100644 .github/workflows/check-configs-manifests-changes.yml diff --git a/.github/workflows/check-configs-manifests-changes.yaml b/.github/workflows/check-configs-changes.yml similarity index 50% rename from .github/workflows/check-configs-manifests-changes.yaml rename to .github/workflows/check-configs-changes.yml index 344dc1850b..6f39b343a9 100644 --- a/.github/workflows/check-configs-manifests-changes.yaml +++ b/.github/workflows/check-configs-changes.yml @@ -1,17 +1,21 @@ -name: "Check Config and Manifests changes" +name: "Check Config and Manifests Changes" + +env: + PR_CACHE_KEY: pr-manifests-${{ github.run_id }}-${{ github.run_attempt }} + MAIN_CACHE_KEY: main-manifests-${{ github.run_id }}-${{ github.run_attempt }} on: pull_request: - types: [opened, synchronize, reopened] + types: [opened, synchronize, reopened, labeled, unlabeled] jobs: - check-configs-manifests-changes: + check-configs-changes: runs-on: ubuntu-latest steps: - name: Checkout code uses: actions/checkout@v4 with: - fetch-depth: 2 # Needed for diff comparison + fetch-depth: 2 - name: Install Dependencies run: | @@ -28,16 +32,13 @@ jobs: repo: context.repo.repo, pull_number: context.payload.pull_request.number, }); - - const configFiles = files.filter(file => file.filename.startsWith('config/')); - + const configFiles = files.filter(file => file.filename.startsWith('config/') || file.filename.startsWith('e2e/')); core.setOutput('configFiles', configFiles.map(file => file.filename).join(',')); - name: Evaluate Config Changes run: | echo "Changed config files:" echo "${{ steps.changed-files.outputs.configFiles }}" | tr ',' '\n' - if [ "${{ steps.changed-files.outputs.configFiles }}" != "" ]; then echo "⚠️ Config directory changes detected!" echo "config_changed=true" >> $GITHUB_ENV @@ -46,15 +47,6 @@ jobs: echo "config_changed=false" >> $GITHUB_ENV fi - - name: Run `make manifests` - run: make manifests - - - name: Compare Generated Manifests with `main` - id: check-manifests - run: | - git diff --exit-code config/ || echo "outdated_manifests=true" >> $GITHUB_ENV - continue-on-error: true - - name: Add Warning if Config Files Changed if: env.config_changed == 'true' uses: actions/github-script@v7 @@ -79,14 +71,79 @@ jobs: labels: ["configs-changed"] }); - - name: Fail if Manifests Are Outdated - if: env.outdated_manifests == 'true' + create-pr-manifests: + runs-on: ubuntu-latest + steps: + - name: Checkout PR branch + uses: actions/checkout@v4 + + - name: Run 'make manifests' run: | - echo "❌ Manifests are outdated! Run 'make manifests' and commit changes." - exit 1 + make dry-run-control-plane + mkdir -p ./cache/pr + mv ./dry-run/manifests.yaml ./cache/pr/manifests.yaml + + - name: Save PR manifests in cache + uses: actions/cache/save@v4 + with: + path: ./cache/pr/ + key: ${{ env.PR_CACHE_KEY }} + + create-main-manifests: + runs-on: ubuntu-latest + steps: + - name: Checkout main branch + uses: actions/checkout@v4 + with: + ref: main + + - name: Run 'make manifests' on main + run: | + make dry-run-control-plane + mkdir -p ./cache/main + mv ./dry-run/manifests.yaml ./cache/main/manifests.yaml + + - name: Save 'main' manifests in cache + uses: actions/cache/save@v4 + with: + path: ./cache/main/ + key: ${{ env.MAIN_CACHE_KEY }} + + diff-manifests: + needs: + - create-pr-manifests + - create-main-manifests + runs-on: ubuntu-latest + steps: + - name: Restore PR manifests cache + uses: actions/cache/restore@v4 + with: + path: ./cache/pr/ + key: ${{ env.PR_CACHE_KEY }} + + - name: Restore 'main' manifests cache + uses: actions/cache/restore@v4 + with: + path: ./cache/main/ + key: ${{ env.MAIN_CACHE_KEY }} + + - name: Compare Manifests + run: | + set +e + DIFF_OUTPUT=$(diff ./cache/pr/manifests.yaml ./cache/main/manifests.yaml) + EXIT_CODE=$? + if [[ $EXIT_CODE != 0 ]]; then + echo "❌ **Detected diff in manifests!** Run 'make manifests' and commit changes." + echo "$DIFF_OUTPUT" + echo "outdated_manifests=true" >> $GITHUB_ENV + exit $EXIT_CODE + fi + set -e + echo "✅ No diff in manifests, all good." + echo "outdated_manifests=false" >> $GITHUB_ENV - name: Add PR Comment if Manifests Are Outdated - if: failure() && env.outdated_manifests == 'true' + if: env.outdated_manifests == 'true' uses: actions/github-script@v7 with: script: | @@ -94,7 +151,7 @@ jobs: owner: context.repo.owner, repo: context.repo.repo, issue_number: context.payload.pull_request.number, - body: "❌ **Manifests are outdated!** Please run `make manifests` and commit the changes." + body: "❌ **Detected diff in manifests!** Run 'make manifests' and commit changes." }); github.rest.issues.addLabels({ owner: context.repo.owner, @@ -102,3 +159,21 @@ jobs: issue_number: context.payload.pull_request.number, labels: ["outdated-manifests"] }); + + - name: Remove 'outdated-manifests' Label if Fixed + if: env.outdated_manifests == 'false' + uses: actions/github-script@v7 + with: + script: | + github.rest.issues.removeLabel({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.payload.pull_request.number, + name: "outdated-manifests" + }); + + - name: Fail if Manifests Are Outdated + if: env.outdated_manifests == 'true' + run: | + echo "❌ Manifests are outdated! Run 'make manifests' and commit changes." + exit 1 diff --git a/.github/workflows/check-configs-manifests-changes.yml b/.github/workflows/check-configs-manifests-changes.yml new file mode 100644 index 0000000000..a6ab012ac6 --- /dev/null +++ b/.github/workflows/check-configs-manifests-changes.yml @@ -0,0 +1,52 @@ +name: "Check if Manifests are Up-to-Date" + +on: + pull_request: + types: [opened, synchronize, reopened] + +jobs: + check-manifests-changes: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + fetch-depth: 2 # Needed for diff comparison + + - name: Install Dependencies + run: | + sudo apt update + sudo apt install -y make + + - name: Generate KLM Manifests from PR + run: make manifests + + - name: Compare Generated Manifests with `main` + id: check-manifests + run: | + git diff --exit-code config/ || echo "outdated_manifests=true" >> $GITHUB_ENV + continue-on-error: true + + - name: Fail if Manifests Are Outdated + if: env.outdated_manifests == 'true' + run: | + echo "❌ Manifests are outdated! Run 'make manifests' and commit changes." + exit 1 + + - name: Add PR Comment if Manifests Are Outdated + if: failure() && env.outdated_manifests == 'true' + uses: actions/github-script@v7 + with: + script: | + github.rest.issues.createComment({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.payload.pull_request.number, + body: "❌ **Manifests are outdated!** Please run `make manifests` and commit the changes." + }); + github.rest.issues.addLabels({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.payload.pull_request.number, + labels: ["outdated-manifests"] + }); From dd2146d6bd7dfacf6b5804d7e9357353151b04e0 Mon Sep 17 00:00:00 2001 From: medmes Date: Mon, 3 Feb 2025 10:46:08 +0100 Subject: [PATCH 20/25] Splitted jobs and added the possibility to remove label if the manifests is fixed. --- .github/workflows/check-configs-changes.yml | 110 ---------------- .../check-configs-manifests-changes.yml | 52 -------- .github/workflows/check-manifests-changes.yml | 117 ++++++++++++++++++ 3 files changed, 117 insertions(+), 162 deletions(-) delete mode 100644 .github/workflows/check-configs-manifests-changes.yml create mode 100644 .github/workflows/check-manifests-changes.yml diff --git a/.github/workflows/check-configs-changes.yml b/.github/workflows/check-configs-changes.yml index 6f39b343a9..1ebd0aaae5 100644 --- a/.github/workflows/check-configs-changes.yml +++ b/.github/workflows/check-configs-changes.yml @@ -1,9 +1,5 @@ name: "Check Config and Manifests Changes" -env: - PR_CACHE_KEY: pr-manifests-${{ github.run_id }}-${{ github.run_attempt }} - MAIN_CACHE_KEY: main-manifests-${{ github.run_id }}-${{ github.run_attempt }} - on: pull_request: types: [opened, synchronize, reopened, labeled, unlabeled] @@ -71,109 +67,3 @@ jobs: labels: ["configs-changed"] }); - create-pr-manifests: - runs-on: ubuntu-latest - steps: - - name: Checkout PR branch - uses: actions/checkout@v4 - - - name: Run 'make manifests' - run: | - make dry-run-control-plane - mkdir -p ./cache/pr - mv ./dry-run/manifests.yaml ./cache/pr/manifests.yaml - - - name: Save PR manifests in cache - uses: actions/cache/save@v4 - with: - path: ./cache/pr/ - key: ${{ env.PR_CACHE_KEY }} - - create-main-manifests: - runs-on: ubuntu-latest - steps: - - name: Checkout main branch - uses: actions/checkout@v4 - with: - ref: main - - - name: Run 'make manifests' on main - run: | - make dry-run-control-plane - mkdir -p ./cache/main - mv ./dry-run/manifests.yaml ./cache/main/manifests.yaml - - - name: Save 'main' manifests in cache - uses: actions/cache/save@v4 - with: - path: ./cache/main/ - key: ${{ env.MAIN_CACHE_KEY }} - - diff-manifests: - needs: - - create-pr-manifests - - create-main-manifests - runs-on: ubuntu-latest - steps: - - name: Restore PR manifests cache - uses: actions/cache/restore@v4 - with: - path: ./cache/pr/ - key: ${{ env.PR_CACHE_KEY }} - - - name: Restore 'main' manifests cache - uses: actions/cache/restore@v4 - with: - path: ./cache/main/ - key: ${{ env.MAIN_CACHE_KEY }} - - - name: Compare Manifests - run: | - set +e - DIFF_OUTPUT=$(diff ./cache/pr/manifests.yaml ./cache/main/manifests.yaml) - EXIT_CODE=$? - if [[ $EXIT_CODE != 0 ]]; then - echo "❌ **Detected diff in manifests!** Run 'make manifests' and commit changes." - echo "$DIFF_OUTPUT" - echo "outdated_manifests=true" >> $GITHUB_ENV - exit $EXIT_CODE - fi - set -e - echo "✅ No diff in manifests, all good." - echo "outdated_manifests=false" >> $GITHUB_ENV - - - name: Add PR Comment if Manifests Are Outdated - if: env.outdated_manifests == 'true' - uses: actions/github-script@v7 - with: - script: | - github.rest.issues.createComment({ - owner: context.repo.owner, - repo: context.repo.repo, - issue_number: context.payload.pull_request.number, - body: "❌ **Detected diff in manifests!** Run 'make manifests' and commit changes." - }); - github.rest.issues.addLabels({ - owner: context.repo.owner, - repo: context.repo.repo, - issue_number: context.payload.pull_request.number, - labels: ["outdated-manifests"] - }); - - - name: Remove 'outdated-manifests' Label if Fixed - if: env.outdated_manifests == 'false' - uses: actions/github-script@v7 - with: - script: | - github.rest.issues.removeLabel({ - owner: context.repo.owner, - repo: context.repo.repo, - issue_number: context.payload.pull_request.number, - name: "outdated-manifests" - }); - - - name: Fail if Manifests Are Outdated - if: env.outdated_manifests == 'true' - run: | - echo "❌ Manifests are outdated! Run 'make manifests' and commit changes." - exit 1 diff --git a/.github/workflows/check-configs-manifests-changes.yml b/.github/workflows/check-configs-manifests-changes.yml deleted file mode 100644 index a6ab012ac6..0000000000 --- a/.github/workflows/check-configs-manifests-changes.yml +++ /dev/null @@ -1,52 +0,0 @@ -name: "Check if Manifests are Up-to-Date" - -on: - pull_request: - types: [opened, synchronize, reopened] - -jobs: - check-manifests-changes: - runs-on: ubuntu-latest - steps: - - name: Checkout code - uses: actions/checkout@v4 - with: - fetch-depth: 2 # Needed for diff comparison - - - name: Install Dependencies - run: | - sudo apt update - sudo apt install -y make - - - name: Generate KLM Manifests from PR - run: make manifests - - - name: Compare Generated Manifests with `main` - id: check-manifests - run: | - git diff --exit-code config/ || echo "outdated_manifests=true" >> $GITHUB_ENV - continue-on-error: true - - - name: Fail if Manifests Are Outdated - if: env.outdated_manifests == 'true' - run: | - echo "❌ Manifests are outdated! Run 'make manifests' and commit changes." - exit 1 - - - name: Add PR Comment if Manifests Are Outdated - if: failure() && env.outdated_manifests == 'true' - uses: actions/github-script@v7 - with: - script: | - github.rest.issues.createComment({ - owner: context.repo.owner, - repo: context.repo.repo, - issue_number: context.payload.pull_request.number, - body: "❌ **Manifests are outdated!** Please run `make manifests` and commit the changes." - }); - github.rest.issues.addLabels({ - owner: context.repo.owner, - repo: context.repo.repo, - issue_number: context.payload.pull_request.number, - labels: ["outdated-manifests"] - }); diff --git a/.github/workflows/check-manifests-changes.yml b/.github/workflows/check-manifests-changes.yml new file mode 100644 index 0000000000..8ec77d8e08 --- /dev/null +++ b/.github/workflows/check-manifests-changes.yml @@ -0,0 +1,117 @@ +name: "Check if Manifests are Up-to-Date" + +env: + PR_CACHE_KEY: pr-manifests-${{ github.run_id }}-${{ github.run_attempt }} + MAIN_CACHE_KEY: main-manifests-${{ github.run_id }}-${{ github.run_attempt }} + +on: + pull_request: + types: [opened, synchronize, reopened] + +jobs: + create-pr-manifests: + runs-on: ubuntu-latest + steps: + - name: Checkout PR branch + uses: actions/checkout@v4 + + - name: Run 'make manifests' + run: | + make dry-run-control-plane + mkdir -p ./cache/pr + mv ./dry-run/manifests.yaml ./cache/pr/manifests.yaml + + - name: Save PR manifests in cache + uses: actions/cache/save@v4 + with: + path: ./cache/pr/ + key: ${{ env.PR_CACHE_KEY }} + + create-main-manifests: + runs-on: ubuntu-latest + steps: + - name: Checkout main branch + uses: actions/checkout@v4 + with: + ref: main + + - name: Run 'make manifests' on main + run: | + make dry-run-control-plane + mkdir -p ./cache/main + mv ./dry-run/manifests.yaml ./cache/main/manifests.yaml + + - name: Save 'main' manifests in cache + uses: actions/cache/save@v4 + with: + path: ./cache/main/ + key: ${{ env.MAIN_CACHE_KEY }} + + diff-manifests: + needs: + - create-pr-manifests + - create-main-manifests + runs-on: ubuntu-latest + steps: + - name: Restore PR manifests cache + uses: actions/cache/restore@v4 + with: + path: ./cache/pr/ + key: ${{ env.PR_CACHE_KEY }} + + - name: Restore 'main' manifests cache + uses: actions/cache/restore@v4 + with: + path: ./cache/main/ + key: ${{ env.MAIN_CACHE_KEY }} + + - name: Compare Manifests + run: | + set +e + DIFF_OUTPUT=$(diff ./cache/pr/manifests.yaml ./cache/main/manifests.yaml) + EXIT_CODE=$? + if [[ $EXIT_CODE != 0 ]]; then + echo "❌ **Detected diff in manifests!** Run 'make manifests' and commit changes." + echo "$DIFF_OUTPUT" + echo "outdated_manifests=true" >> $GITHUB_ENV + exit $EXIT_CODE + fi + set -e + echo "✅ No diff in manifests, all good." + echo "outdated_manifests=false" >> $GITHUB_ENV + + - name: Add PR Comment if Manifests Are Outdated + if: env.outdated_manifests == 'true' + uses: actions/github-script@v7 + with: + script: | + github.rest.issues.createComment({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.payload.pull_request.number, + body: "❌ **Detected diff in manifests!** Run 'make manifests' and commit changes." + }); + github.rest.issues.addLabels({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.payload.pull_request.number, + labels: ["outdated-manifests"] + }); + + - name: Remove 'outdated-manifests' Label if Fixed + if: env.outdated_manifests == 'false' + uses: actions/github-script@v7 + with: + script: | + github.rest.issues.removeLabel({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.payload.pull_request.number, + name: "outdated-manifests" + }); + + - name: Fail if Manifests Are Outdated + if: env.outdated_manifests == 'true' + run: | + echo "❌ Manifests are outdated! Run 'make manifests' and commit changes." + exit 1 From 4120aac7c8d5bccd656e90abfe0c0722954bfd9f Mon Sep 17 00:00:00 2001 From: medmes Date: Mon, 3 Feb 2025 14:02:45 +0100 Subject: [PATCH 21/25] rename workflow name --- .github/workflows/check-configs-changes.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/check-configs-changes.yml b/.github/workflows/check-configs-changes.yml index 1ebd0aaae5..83a09400f7 100644 --- a/.github/workflows/check-configs-changes.yml +++ b/.github/workflows/check-configs-changes.yml @@ -1,4 +1,4 @@ -name: "Check Config and Manifests Changes" +name: "Check Config Changes" on: pull_request: From 033c5af22a13043c2fa9d866e723bfd786790b2a Mon Sep 17 00:00:00 2001 From: medmes Date: Mon, 3 Feb 2025 14:58:33 +0100 Subject: [PATCH 22/25] changed into $GITHUB_OUTPUT instead of using env vars: $GITHUB_ENV --- .github/workflows/check-configs-changes.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/check-configs-changes.yml b/.github/workflows/check-configs-changes.yml index 83a09400f7..e762f92dbf 100644 --- a/.github/workflows/check-configs-changes.yml +++ b/.github/workflows/check-configs-changes.yml @@ -37,14 +37,14 @@ jobs: echo "${{ steps.changed-files.outputs.configFiles }}" | tr ',' '\n' if [ "${{ steps.changed-files.outputs.configFiles }}" != "" ]; then echo "⚠️ Config directory changes detected!" - echo "config_changed=true" >> $GITHUB_ENV + echo "config_changed=true" >> $GITHUB_OUTPUT else echo "✅ No changes in config directory." - echo "config_changed=false" >> $GITHUB_ENV + echo "config_changed=false" >> $GITHUB_OUTPUT fi - name: Add Warning if Config Files Changed - if: env.config_changed == 'true' + if: steps.eval-changes.outputs.config_changed == 'true' uses: actions/github-script@v7 with: script: | @@ -56,7 +56,7 @@ jobs: }); - name: Add PR Label for Config Changes - if: env.config_changed == 'true' + if: steps.eval-changes.outputs.config_changed == 'true' uses: actions/github-script@v7 with: script: | From e19d8bc40ad52710c112005a5db037290a722fe8 Mon Sep 17 00:00:00 2001 From: medmes Date: Mon, 3 Feb 2025 15:18:22 +0100 Subject: [PATCH 23/25] Refactoring --- .github/workflows/check-configs-changes.yml | 7 ++- .github/workflows/check-manifests-changes.yml | 47 ++++++++++++------- 2 files changed, 35 insertions(+), 19 deletions(-) diff --git a/.github/workflows/check-configs-changes.yml b/.github/workflows/check-configs-changes.yml index e762f92dbf..c2fd410466 100644 --- a/.github/workflows/check-configs-changes.yml +++ b/.github/workflows/check-configs-changes.yml @@ -28,10 +28,15 @@ jobs: repo: context.repo.repo, pull_number: context.payload.pull_request.number, }); - const configFiles = files.filter(file => file.filename.startsWith('config/') || file.filename.startsWith('e2e/')); + const configFiles = files.filter(file => + file.filename.startsWith('config/') || + file.filename.startsWith('e2e/') || + file.filename.startsWith('scripts/tests/')); + core.setOutput('configFiles', configFiles.map(file => file.filename).join(',')); - name: Evaluate Config Changes + id: eval-changes run: | echo "Changed config files:" echo "${{ steps.changed-files.outputs.configFiles }}" | tr ',' '\n' diff --git a/.github/workflows/check-manifests-changes.yml b/.github/workflows/check-manifests-changes.yml index 8ec77d8e08..c7c6ac8009 100644 --- a/.github/workflows/check-manifests-changes.yml +++ b/.github/workflows/check-manifests-changes.yml @@ -15,14 +15,14 @@ jobs: - name: Checkout PR branch uses: actions/checkout@v4 - - name: Run 'make manifests' + - name: Run 'make manifests' on PR branch run: | make dry-run-control-plane mkdir -p ./cache/pr mv ./dry-run/manifests.yaml ./cache/pr/manifests.yaml - name: Save PR manifests in cache - uses: actions/cache/save@v4 + uses: actions/cache@v3 with: path: ./cache/pr/ key: ${{ env.PR_CACHE_KEY }} @@ -35,14 +35,14 @@ jobs: with: ref: main - - name: Run 'make manifests' on main + - name: Run 'make manifests' on main branch run: | make dry-run-control-plane mkdir -p ./cache/main mv ./dry-run/manifests.yaml ./cache/main/manifests.yaml - - name: Save 'main' manifests in cache - uses: actions/cache/save@v4 + - name: Save main manifests in cache + uses: actions/cache@v3 with: path: ./cache/main/ key: ${{ env.MAIN_CACHE_KEY }} @@ -53,35 +53,35 @@ jobs: - create-main-manifests runs-on: ubuntu-latest steps: - - name: Restore PR manifests cache - uses: actions/cache/restore@v4 + - name: Restore PR manifests from cache + uses: actions/cache@v3 with: path: ./cache/pr/ key: ${{ env.PR_CACHE_KEY }} - - name: Restore 'main' manifests cache - uses: actions/cache/restore@v4 + - name: Restore main manifests from cache + uses: actions/cache@v3 with: path: ./cache/main/ key: ${{ env.MAIN_CACHE_KEY }} - name: Compare Manifests + id: compare-manifests run: | set +e DIFF_OUTPUT=$(diff ./cache/pr/manifests.yaml ./cache/main/manifests.yaml) EXIT_CODE=$? if [[ $EXIT_CODE != 0 ]]; then - echo "❌ **Detected diff in manifests!** Run 'make manifests' and commit changes." + echo "❌ Detected diff in manifests!" echo "$DIFF_OUTPUT" - echo "outdated_manifests=true" >> $GITHUB_ENV + echo "outdated_manifests=true" >> $GITHUB_OUTPUT exit $EXIT_CODE fi - set -e echo "✅ No diff in manifests, all good." - echo "outdated_manifests=false" >> $GITHUB_ENV + echo "outdated_manifests=false" >> $GITHUB_OUTPUT - name: Add PR Comment if Manifests Are Outdated - if: env.outdated_manifests == 'true' + if: steps.compare-manifests.outputs.outdated_manifests == 'true' uses: actions/github-script@v7 with: script: | @@ -99,19 +99,30 @@ jobs: }); - name: Remove 'outdated-manifests' Label if Fixed - if: env.outdated_manifests == 'false' + if: steps.compare-manifests.outputs.outdated_manifests == 'false' uses: actions/github-script@v7 with: script: | - github.rest.issues.removeLabel({ + const labelName = 'outdated-manifests'; + const { data: labels } = await github.rest.issues.listLabelsOnIssue({ owner: context.repo.owner, repo: context.repo.repo, issue_number: context.payload.pull_request.number, - name: "outdated-manifests" }); + if (labels.some(label => label.name === labelName)) { + console.log(`Label "${labelName}" found, removing it.`); + await github.rest.issues.removeLabel({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.payload.pull_request.number, + name: labelName, + }); + } else { + console.log(`Label "${labelName}" not found, skipping removal.`); + } - name: Fail if Manifests Are Outdated - if: env.outdated_manifests == 'true' + if: steps.compare-manifests.outputs.outdated_manifests == 'true' run: | echo "❌ Manifests are outdated! Run 'make manifests' and commit changes." exit 1 From d981bc53f9b9b38115dbfdcb69777d9d8705c113 Mon Sep 17 00:00:00 2001 From: medmes Date: Mon, 3 Feb 2025 15:21:20 +0100 Subject: [PATCH 24/25] Refactoring --- .github/workflows/check-configs-changes.yml | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/.github/workflows/check-configs-changes.yml b/.github/workflows/check-configs-changes.yml index c2fd410466..188785467f 100644 --- a/.github/workflows/check-configs-changes.yml +++ b/.github/workflows/check-configs-changes.yml @@ -28,11 +28,7 @@ jobs: repo: context.repo.repo, pull_number: context.payload.pull_request.number, }); - const configFiles = files.filter(file => - file.filename.startsWith('config/') || - file.filename.startsWith('e2e/') || - file.filename.startsWith('scripts/tests/')); - + const configFiles = files.filter(file => file.filename.startsWith('config/') || file.filename.startsWith('e2e/')); core.setOutput('configFiles', configFiles.map(file => file.filename).join(',')); - name: Evaluate Config Changes From acf9f86dc7da0933d98a3743ecb8d51fb508d722 Mon Sep 17 00:00:00 2001 From: medmes Date: Mon, 3 Feb 2025 16:39:03 +0100 Subject: [PATCH 25/25] Refactoring --- .github/workflows/check-configs-changes.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/check-configs-changes.yml b/.github/workflows/check-configs-changes.yml index 188785467f..357a06a53a 100644 --- a/.github/workflows/check-configs-changes.yml +++ b/.github/workflows/check-configs-changes.yml @@ -28,7 +28,7 @@ jobs: repo: context.repo.repo, pull_number: context.payload.pull_request.number, }); - const configFiles = files.filter(file => file.filename.startsWith('config/') || file.filename.startsWith('e2e/')); + const configFiles = files.filter(file => file.filename.startsWith('config/')); core.setOutput('configFiles', configFiles.map(file => file.filename).join(',')); - name: Evaluate Config Changes