Skip to content

Commit

Permalink
Draft Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
medmes committed Jan 31, 2025
1 parent 45a38c8 commit a836812
Show file tree
Hide file tree
Showing 2 changed files with 150 additions and 23 deletions.
Original file line number Diff line number Diff line change
@@ -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: |
Expand All @@ -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
Expand All @@ -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
Expand All @@ -79,26 +71,109 @@ 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: |
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."
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
52 changes: 52 additions & 0 deletions .github/workflows/check-configs-manifests-changes.yml
Original file line number Diff line number Diff line change
@@ -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"]
});

0 comments on commit a836812

Please sign in to comment.