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

feat: Trigger warning for PRs likely requiring updates to management-plane-charts #2219

Open
wants to merge 31 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
e84d05f
Add GH workflow for detecting changes under config directory
medmes Jan 30, 2025
38d368a
Enhance the workflow for checking manifests changes as well.
medmes Jan 30, 2025
fe9a0bc
Test the workflow
medmes Jan 30, 2025
4bab3ad
Test the workflow- pull request target
medmes Jan 30, 2025
974263a
Add permission token.
medmes Jan 30, 2025
c124fd3
Change to pull_request_target
medmes Jan 30, 2025
ec56411
remove pull_request_target types
medmes Jan 30, 2025
57b6fa3
changed to PR to test on upstream
medmes Jan 30, 2025
fc47bf8
remove envs after testing
medmes Jan 30, 2025
baa1e06
Rename Job name
medmes Jan 30, 2025
c25021a
Changes on the CRD part.
medmes Jan 30, 2025
6d15458
Fail and comment
medmes Jan 30, 2025
3d01f0c
Revert "Fail and comment"
medmes Jan 30, 2025
1608059
Add fail condition on PR comment
medmes Jan 30, 2025
9742436
Add fail condition on PR comment
medmes Jan 30, 2025
d3c0d9e
Add fail condition on PR comment
medmes Jan 30, 2025
e1b8293
revert back and keep only Github Actions Workflow yaml file.
medmes Jan 30, 2025
45a38c8
revert back and keep only Github Actions Workflow yaml file.
medmes Jan 30, 2025
e60f1d9
Merge branch 'main' into trigger_warning_job_on_pr
medmes Jan 31, 2025
a836812
Draft Commit
medmes Jan 31, 2025
b0e45ae
Merge remote-tracking branch 'origin/trigger_warning_job_on_pr' into …
medmes Jan 31, 2025
a00d234
Merge branch 'main' into trigger_warning_job_on_pr
medmes Jan 31, 2025
dd2146d
Splitted jobs and added the possibility to remove label if the manife…
medmes Feb 3, 2025
f77d9ce
Merge branch 'main' into trigger_warning_job_on_pr
medmes Feb 3, 2025
6dc46d6
Merge branch 'main' of github.com:medmes/lifecycle-manager into trigg…
medmes Feb 3, 2025
4adb7df
Merge remote-tracking branch 'origin/trigger_warning_job_on_pr' into …
medmes Feb 3, 2025
4120aac
rename workflow name
medmes Feb 3, 2025
033c5af
changed into $GITHUB_OUTPUT instead of using env vars: $GITHUB_ENV
medmes Feb 3, 2025
e19d8bc
Refactoring
medmes Feb 3, 2025
d981bc5
Refactoring
medmes Feb 3, 2025
acf9f86
Refactoring
medmes Feb 3, 2025
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
70 changes: 70 additions & 0 deletions .github/workflows/check-configs-changes.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
name: "Check Config Changes"

on:
pull_request:
types: [opened, synchronize, reopened, labeled, unlabeled]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Labeled and unlabeled were needed on the previous approach but not here. Let's remove them. And since opened, synchronize and reopened are the default types, I think we should omit it entirely.


jobs:
check-configs-changes:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 2

- name: Install Dependencies
run: |
sudo apt update
sudo apt install -y make
Comment on lines +16 to +19
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure we need to install it explicitly? https://github.com/actions/runner-images/blob/main/images/ubuntu/Ubuntu2404-Readme.md#installed-apt-packages

Also looks like we are not even using make in this action? Is it a leftover from testing?


- 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(','));
Comment on lines +21 to +32
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is still targeting the config/ folder. These are the sources for generating the manifest output via make dry-run-control-plane. As we already check the output in the other action, I don't think it makes sense to check the sources here. Eventually, we only care about the output, not the sources.

So this one should be replaced with the other files that we care about, but don't have an output. These are:

  • .github/actions (if we change an action, we should make sure it still works in the other repos where we import these)
  • .github/workflows (if we change a workflow, we should check whether we also need to change the same in management-plane-charts)
  • ./tests/scripts (those are used by the actions, so again we should check if it still works in the other repos)
  • versions.yaml (we should check if our tooling version changes still work in the other repos)

The workflow then also needs to be renamed. Maybe something like "check-pipeline-changes`

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The rest of this workflow looks good. Maybe update the descriptions to be more general and not only about /config files


- name: Evaluate Config Changes
id: eval-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_OUTPUT
else
echo "✅ No changes in config directory."
echo "config_changed=false" >> $GITHUB_OUTPUT
fi

- name: Add Warning if Config Files Changed
if: steps.eval-changes.outputs.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 folder changes detected!** Please review if manifest updates are necessary."
});

- name: Add PR Label for Config Changes
if: steps.eval-changes.outputs.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: ["configs-changed"]
});

128 changes: 128 additions & 0 deletions .github/workflows/check-manifests-changes.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
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]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above, I would remove the default types


jobs:
create-pr-manifests:
runs-on: ubuntu-latest
steps:
- name: Checkout PR branch
uses: actions/checkout@v4

- 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@v3
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 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@v3
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 from cache
uses: actions/cache@v3
with:
path: ./cache/pr/
key: ${{ env.PR_CACHE_KEY }}

- 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!"
echo "$DIFF_OUTPUT"
echo "outdated_manifests=true" >> $GITHUB_OUTPUT
exit $EXIT_CODE
fi
echo "✅ No diff in manifests, all good."
echo "outdated_manifests=false" >> $GITHUB_OUTPUT

- name: Add PR Comment if Manifests Are Outdated
if: steps.compare-manifests.outputs.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."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is also not entirely true anymore. See my other comment for this block. I would propose that we ignore the make manifests case for now and add that with a separate PR.

});
github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.payload.pull_request.number,
labels: ["outdated-manifests"]
});
Comment on lines +83 to +99
Copy link
Contributor

@c-pius c-pius Feb 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The check above (compare-manifests) doesn't determine if the manifests are "outdated". It determines if there is a diff between main and PR which may be an intended thing. Please adjust the descriptions and variable names accordingly.


- name: Remove 'outdated-manifests' Label if Fixed
if: steps.compare-manifests.outputs.outdated_manifests == 'false'
uses: actions/github-script@v7
with:
script: |
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,
});
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: steps.compare-manifests.outputs.outdated_manifests == 'true'
run: |
echo "❌ Manifests are outdated! Run 'make manifests' and commit changes."
exit 1
Loading