-
Notifications
You must be signed in to change notification settings - Fork 30
128 lines (114 loc) · 4.17 KB
/
check-manifests-changes.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
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]
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."
});
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: 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