Skip to content
This repository was archived by the owner on Aug 19, 2024. It is now read-only.

Commit a7c9d99

Browse files
rm3ljianrongzhang89gazarenkovnickboldtGennady Azarenkov
authored
Auto-push bundle manifests changes to PR branch if needed (#195)
* Make PR checks fail if bundle or manifests are not up-to-date This is so that PR authors do not forget to regenerate those manifests. * Update developer guide * Save diff as patch file, so it can be downloaded and applied with Git * Fix step names in PR Validation job * Apply suggestions from code review Co-authored-by: Jianrong Zhang <jianrzha@redhat.com> * Do not error out if bundle manifests are outdated Display warnings instead. Also comment on the PR so that authors/reviewers are aware of that fact. Co-authored-by: Gennady Azarenkov <gazarenkov@gmail.com> * Update .github/workflows/pr.yaml Co-authored-by: Nick Boldt <nboldt@redhat.com> * Revert "Do not error out if bundle manifests are outdated" This reverts commit ab2c12a. * Auto-push any changes to the bundle manifests This will alleviate the burden on contributors and maintainers. * Run bundle diff checker in separate workflow triggered on 'pull_request_target' events This is required to be able to write to fork PR branches Similar to what we do already with the pull_request_target workflows, we also require manual authorization for unknown external forks, to prevent PWN requests * Update PR template to think about eventually updating the rhdh-operator.csv.yaml file * Update .github/workflows/pr-bundle-diff-checks.yaml * Update docs/developer.md Co-authored-by: Gennady Azarenkov <gazarenkov@redhat.com> --------- Co-authored-by: Jianrong Zhang <jianrzha@redhat.com> Co-authored-by: Gennady Azarenkov <gazarenkov@gmail.com> Co-authored-by: Nick Boldt <nboldt@redhat.com> Co-authored-by: Gennady Azarenkov <gazarenkov@redhat.com>
1 parent 24bb6a9 commit a7c9d99

File tree

3 files changed

+103
-3
lines changed

3 files changed

+103
-3
lines changed

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Please explain the changes you made here.
1515

1616
- [ ] Tests
1717
- [ ] Documentation
18+
- [ ] If the bundle manifests have been updated, make sure to review the [`rhdh-operator.csv.yaml`](../.rhdh/bundle/manifests/rhdh-operator.csv.yaml) file accordingly
1819

1920
## How to test changes / Special notes to the reviewer
2021
<!--
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
# Copyright 2024 The Janus IDP Authors
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
name: PR Bundle Manifests Validator
16+
17+
on:
18+
# pull_request_target needed to be able to commit and push bundle diffs to external fork PRs.
19+
# But we included a manual authorization safeguard to prevent PWN requests. See the 'authorize' job below.
20+
pull_request_target:
21+
branches:
22+
- main
23+
- rhdh-1.[0-9]+
24+
- 1.[0-9]+.x
25+
26+
concurrency:
27+
group: ${{ github.workflow }}-${{ github.event.number }}
28+
cancel-in-progress: true
29+
30+
jobs:
31+
authorize:
32+
# The 'external' environment is configured with the maintainers team as required reviewers.
33+
# All the subsequent jobs in this workflow 'need' this job, which will require manual approval for PRs coming from external forks.
34+
# see list of approvers in OWNERS file
35+
environment:
36+
${{ (github.event.pull_request.head.repo.full_name == github.repository ||
37+
contains(fromJSON('["gazarenkov","jianrongzhang89","kadel","nickboldt","rm3l"]'), github.actor)) && 'internal' || 'external' }}
38+
runs-on: ubuntu-latest
39+
steps:
40+
- name: approved
41+
run: echo "✓"
42+
43+
pr-bundle-diff-checks:
44+
name: PR Bundle Diff
45+
runs-on: ubuntu-latest
46+
needs: authorize
47+
permissions:
48+
contents: read
49+
pull-requests: write
50+
steps:
51+
- name: Checkout
52+
uses: actions/checkout@v4
53+
with:
54+
fetch-depth: 0
55+
repository: ${{github.event.pull_request.head.repo.full_name}}
56+
ref: ${{ github.event.pull_request.head.ref }}
57+
58+
- name: Setup Go
59+
uses: actions/setup-go@v5
60+
with:
61+
go-version-file: 'go.mod'
62+
63+
- name: Check for outdated bundle
64+
id: bundle-diff-checker
65+
run: |
66+
make bundle
67+
git status --porcelain
68+
# Since operator-sdk 1.26.0, `make bundle` changes the `createdAt` field from the bundle every time we run it.
69+
# The `git diff` below checks if only the createdAt field has changed. If is the only change, it is ignored.
70+
# Inspired from https://github.com/operator-framework/operator-sdk/issues/6285#issuecomment-1415350333
71+
echo "MANIFESTS_CHANGED=$(if git diff --quiet -I'^ createdAt: ' bundle; then echo "false"; else echo "true"; fi)" >> $GITHUB_OUTPUT
72+
73+
- name: Commit any manifest changes
74+
if: ${{ steps.bundle-diff-checker.outputs.MANIFESTS_CHANGED == 'true' }}
75+
run: |
76+
git config user.name 'github-actions[bot]'
77+
git config user.email 'github-actions[bot]@users.noreply.github.com'
78+
git fetch --prune
79+
git pull --rebase --autostash
80+
git add -A .
81+
git commit \
82+
-m "Regenerate bundle manifests" \
83+
-m "Co-authored-by: $GITHUB_ACTOR <$GITHUB_ACTOR@users.noreply.github.com>"
84+
git push
85+
86+
- name: Comment on PR if bundle manifests were updated
87+
uses: actions/github-script@v7
88+
if: ${{ !cancelled() && steps.bundle-diff-checker.outputs.MANIFESTS_CHANGED == 'true' }}
89+
continue-on-error: true
90+
with:
91+
script: |
92+
await github.rest.issues.createComment({
93+
issue_number: context.issue.number,
94+
owner: context.repo.owner,
95+
repo: context.repo.repo,
96+
body: '⚠️ <b>Files changed in bundle generation<b>!<br/><br/>Those changes to the operator bundle manifests should have been pushed automatically to your PR branch.<br/>You might also need to manually update the [`.rhdh/bundle/manifests/rhdh-operator.csv.yaml`](.rhdh/bundle/manifests/rhdh-operator.csv.yaml) CSV file accordingly.'
97+
})

docs/developer.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,13 @@ make deploy-openshift [IMAGE_TAG_BASE=<your-registry>/backstage-operator]
104104
```
105105

106106
### Modifying the API definitions
107-
If you are editing the API definitions, generate the manifests such as CRs or CRDs using:
107+
If you are editing the API definitions, make sure you:
108+
- run `make install` before deploying the operator with `make deploy`
109+
- regenerate the manifests and bundle if you plan to deploy the operator with OLM using:
108110
```sh
109-
make manifests
111+
make manifests bundle
110112
```
111-
**NOTE:** Run `make --help` for more information on all potential `make` targets
113+
**NOTE:** Run `make help` for more information on all potential `make` targets
112114

113115
More information can be found via the [Kubebuilder Documentation](https://book.kubebuilder.io/introduction.html)
114116

0 commit comments

Comments
 (0)