ci: add upstream folder change check#3431
ci: add upstream folder change check#3431christian-heusel wants to merge 1 commit intokubeflow:masterfrom
Conversation
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
There was a problem hiding this comment.
Pull request overview
This PR adds a GitHub Actions workflow to detect and warn about changes to upstream folders in pull requests. The workflow triggers on pull requests that modify files in any **/upstream/** path and outputs a warning if such changes are detected.
Changes:
- Added
.github/workflows/check_upstream_changes.yamlworkflow that detects modifications to upstream folder structures - Added test string "Test123" to
applications/volumes-web-app/upstream/base/cluster-role-binding.yaml
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| .github/workflows/check_upstream_changes.yaml | New workflow to detect upstream folder changes and emit warnings |
| applications/volumes-web-app/upstream/base/cluster-role-binding.yaml | Unintended test content added |
applications/volumes-web-app/upstream/base/cluster-role-binding.yaml
Outdated
Show resolved
Hide resolved
9800a2b to
b5a84ca
Compare
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Signed-off-by: Christian Heusel <christian@heusel.eu>
b5a84ca to
a3cb231
Compare
|
|
||
| permissions: | ||
| contents: read | ||
| actions: read |
There was a problem hiding this comment.
The workflow uses the Issues Comments API endpoints (e.g., repos/.../issues/.../comments and repos/.../issues/comments/...) but the workflow permissions only grant pull-requests: write. Add issues: write (and keep pull-requests: write only if you also need PR-specific endpoints) so the gh api calls can reliably list/create/update PR comments.
| actions: read | |
| actions: read | |
| issues: write |
| - name: Checkout | ||
| uses: actions/checkout@v5 | ||
| with: | ||
| fetch-depth: 0 | ||
| ref: ${{ github.event.pull_request.head.sha }} | ||
|
|
||
| - name: Fetch master branch | ||
| run: git fetch origin master | ||
|
|
||
| - name: Detect changed upstream paths | ||
| id: upstream_changes | ||
| run: | | ||
| changed=$(git diff-tree -r --no-commit-id --name-only origin/master..HEAD | grep '/upstream/' || true) |
There was a problem hiding this comment.
pull_request_target runs with write-capable tokens in the context of the base repository. Checking out github.event.pull_request.head.sha means this job will fetch and operate on untrusted fork/branch content, and it will also fail for fork PRs unless you explicitly checkout github.event.pull_request.head.repo.full_name (the head SHA typically is not present in the base repo). Consider avoiding checkout entirely and instead use the GitHub API to list changed files; if you must checkout the head, make sure it cannot influence any step that uses the write token.
| - name: Checkout | |
| uses: actions/checkout@v5 | |
| with: | |
| fetch-depth: 0 | |
| ref: ${{ github.event.pull_request.head.sha }} | |
| - name: Fetch master branch | |
| run: git fetch origin master | |
| - name: Detect changed upstream paths | |
| id: upstream_changes | |
| run: | | |
| changed=$(git diff-tree -r --no-commit-id --name-only origin/master..HEAD | grep '/upstream/' || true) | |
| - name: Detect changed upstream paths | |
| id: upstream_changes | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| changed="$( | |
| gh api \ | |
| "repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/files" \ | |
| --paginate \ | |
| --jq '.[] | .filename' | grep '/upstream/' || true | |
| )" |
| - name: Fetch master branch | ||
| run: git fetch origin master | ||
|
|
||
| - name: Detect changed upstream paths | ||
| id: upstream_changes | ||
| run: | | ||
| changed=$(git diff-tree -r --no-commit-id --name-only origin/master..HEAD | grep '/upstream/' || true) |
There was a problem hiding this comment.
This change detection is hard-coded to origin/master..HEAD (two-dot) and a separately fetched master branch. This can produce incorrect results for PRs that are not rebased (and for PRs targeting branches other than master). Prefer diffing the PR base vs head using the PR’s base.sha/base.ref and a merge-base aware comparison (triple-dot) so the changed file list matches what GitHub considers part of the PR.
| - name: Fetch master branch | |
| run: git fetch origin master | |
| - name: Detect changed upstream paths | |
| id: upstream_changes | |
| run: | | |
| changed=$(git diff-tree -r --no-commit-id --name-only origin/master..HEAD | grep '/upstream/' || true) | |
| - name: Fetch pull request base branch | |
| run: git fetch --no-tags --prune --depth=1 origin "${{ github.event.pull_request.base.ref }}" | |
| - name: Detect changed upstream paths | |
| id: upstream_changes | |
| run: | | |
| changed=$(git diff --name-only "${{ github.event.pull_request.base.sha }}...HEAD" | grep '/upstream/' || true) |
| body="${marker} | ||
| ⚠️ **Upstream folder changes detected** | ||
| This PR modifies files inside one or more \`upstream\` folders. Changes to upstream manifests are usually wrong and should be reviewed carefully. | ||
| **Changed upstream files:** | ||
| \`\`\` | ||
| ${{ steps.upstream_changes.outputs.changed_files }} | ||
| \`\`\`" | ||
| existing=$(gh api "repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/comments" \ | ||
| --jq ".[] | select(.body | contains(\"$marker\")) | .id" | head -1) | ||
| if [ -n "$existing" ]; then | ||
| gh api "repos/${{ github.repository }}/issues/comments/$existing" \ | ||
| -X PATCH -f body="$body" | ||
| else | ||
| gh pr comment "${{ github.event.pull_request.number }}" --body "$body" |
There was a problem hiding this comment.
The PR-controlled changed_files output is interpolated directly into a Bash double-quoted string when building body. In Bash, file names containing command substitutions (e.g., $(...) or backticks) would be executed during assignment, which is especially dangerous in a pull_request_target workflow with a write token. Treat the file list as untrusted data: build the comment body using a single-quoted heredoc / --body-file approach (no shell evaluation), or escape $, backticks, and backslashes before embedding.
| body="${marker} | |
| ⚠️ **Upstream folder changes detected** | |
| This PR modifies files inside one or more \`upstream\` folders. Changes to upstream manifests are usually wrong and should be reviewed carefully. | |
| **Changed upstream files:** | |
| \`\`\` | |
| ${{ steps.upstream_changes.outputs.changed_files }} | |
| \`\`\`" | |
| existing=$(gh api "repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/comments" \ | |
| --jq ".[] | select(.body | contains(\"$marker\")) | .id" | head -1) | |
| if [ -n "$existing" ]; then | |
| gh api "repos/${{ github.repository }}/issues/comments/$existing" \ | |
| -X PATCH -f body="$body" | |
| else | |
| gh pr comment "${{ github.event.pull_request.number }}" --body "$body" | |
| comment_body_file="$(mktemp)" | |
| trap 'rm -f "$comment_body_file"' EXIT | |
| cat > "$comment_body_file" <<'EOF' | |
| <!-- upstream-changes-warning --> | |
| ⚠️ **Upstream folder changes detected** | |
| This PR modifies files inside one or more `upstream` folders. Changes to upstream manifests are usually wrong and should be reviewed carefully. | |
| **Changed upstream files:** | |
| ``` | |
| EOF | |
| printf '%s\n' '${{ steps.upstream_changes.outputs.changed_files }}' >> "$comment_body_file" | |
| printf '```\n' >> "$comment_body_file" | |
| existing=$(gh api "repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/comments" \ | |
| --jq ".[] | select(.body | contains(\"$marker\")) | .id" | head -1) | |
| if [ -n "$existing" ]; then | |
| gh api "repos/${{ github.repository }}/issues/comments/$existing" \ | |
| -X PATCH -F "body=@$comment_body_file" | |
| else | |
| gh pr comment "${{ github.event.pull_request.number }}" --body-file "$comment_body_file" |
Pull Request Template for Kubeflow Manifests
✏️ Summary of Changes
This potentially needs a follow-up PR as I was not able to test it properly, since
on: pull_requestactions don't get "write" tokens andon: pull_request_targetactions don't run until commited to the default branch.📦 Dependencies
none
🐛 Related Issues
none
✅ Contributor Checklist