Skip to content

Commit dacabbb

Browse files
committed
.github/workflow: add diff ceph config action
Signed-off-by: Naveen Naidu <[email protected]>
1 parent a568ae9 commit dacabbb

File tree

3 files changed

+155
-0
lines changed

3 files changed

+155
-0
lines changed

.github/labeler.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,3 +345,6 @@ script:
345345
- src/script/**
346346
- admin/**
347347
- doc/scripts/**
348+
349+
config-change:
350+
- src/common/options/**
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
name: Check ceph config changes
2+
on:
3+
pull_request_target:
4+
types:
5+
- opened
6+
- synchronize
7+
- edited
8+
- reopened
9+
10+
# The following permissions are needed to write a comment to repo
11+
permissions:
12+
issues: write
13+
contents: read
14+
pull-requests: write
15+
16+
jobs:
17+
pull_request:
18+
runs-on: ubuntu-latest
19+
steps:
20+
- name: checkout ceph.git
21+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 #v4.2.2
22+
with:
23+
path: ceph
24+
sparse-checkout: |
25+
src/script
26+
src/common/options
27+
.github/workflows
28+
29+
- name: Setup Python
30+
uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 #v5.6.0
31+
with:
32+
python-version: '3.13'
33+
34+
- name: Install python packages
35+
run: |
36+
pip3 install -r ./src/script/config-diff/requirements.txt
37+
working-directory: ceph
38+
39+
- name: execute config diff tool
40+
id: diff_tool
41+
env:
42+
REF_REPO: ${{ github.event.pull_request.base.repo.clone_url }}
43+
REF_BRANCH: ${{ github.event.pull_request.base.ref }}
44+
REMOTE_REPO: ${{ github.event.pull_request.head.repo.clone_url }}
45+
REMOTE_BRANCH: ${{ github.event.pull_request.head.ref }}
46+
run: |
47+
{
48+
echo 'DIFF_JSON<<EOF'
49+
python3 ./src/script/config-diff/config_diff.py diff-branch-remote-repo --ref-branch $REF_BRANCH --remote-repo $REMOTE_REPO --cmp-branch $REMOTE_BRANCH --format=posix-diff --skip-clone
50+
echo EOF
51+
} >> "$GITHUB_OUTPUT"
52+
working-directory: ceph
53+
54+
- name: Post output as a comment
55+
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea #v7.0.1
56+
env:
57+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
58+
DIFF_JSON_OUTPUT: ${{ steps.diff_tool.outputs.DIFF_JSON }}
59+
with:
60+
script: |
61+
const configDiff = process.env.DIFF_JSON_OUTPUT;
62+
const postComment = require('./ceph/.github/workflows/scripts/config-diff-post-comment.js');
63+
postComment({ github, context, core, configDiff });
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
module.exports = async ({ github, context, core, configDiff }) => {
2+
try {
3+
// Do not create comment if there are no configuration changes
4+
if (!configDiff) {
5+
console.log("No changes detected. Skipping comment creation.");
6+
return;
7+
}
8+
9+
const commentBody = `
10+
### Config Diff Tool Output
11+
12+
\`\`\`diff
13+
14+
${configDiff}
15+
16+
\`\`\`
17+
18+
19+
The above configuration changes are found in the PR. Please update the relevant release documentation if necessary.
20+
`;
21+
22+
core.summary.addRaw(commentBody);
23+
await core.summary.write()
24+
25+
const { owner, repo } = context.repo;
26+
const issueNumber = context.payload.pull_request.number;
27+
28+
// List all files in the pull request
29+
core.info("Fetching list of files changed in the pull request...");
30+
const files = await github.paginate(
31+
github.rest.pulls.listFiles,
32+
{
33+
owner,
34+
repo,
35+
pull_number: issueNumber,
36+
per_page: 100,
37+
}
38+
);
39+
40+
// Annotate YAML files
41+
files.forEach(file => {
42+
// Only annotate the `yaml.in` files present in `src/common/options` folder
43+
if (file.filename.endsWith(".yaml.in") && file.filename.startsWith("src/common/options/")) {
44+
core.info(`Annotating file: ${file.filename}`);
45+
core.notice(
46+
`Configuration changes detected in ${file.filename}. Please update the relevant release documentation if necessary.`,
47+
{
48+
title: "Configuration Change Detected",
49+
file: file.filename,
50+
startLine: 1,
51+
endLine: 1,
52+
}
53+
);
54+
}
55+
});
56+
57+
58+
// List all the comments
59+
const comments = await github.paginate(
60+
github.rest.issues.listComments, {
61+
owner,
62+
repo,
63+
issue_number: issueNumber,
64+
per_page: 100,
65+
}
66+
);
67+
68+
const existingComment = comments.find(comment => comment.body.includes("### Config Diff Tool Output"));
69+
70+
if (existingComment) {
71+
core.info("A config diff comment already exists, deleting it...");
72+
} else {
73+
core.info("Creating a new config diff comment...");
74+
// Create a new comment
75+
await github.rest.issues.createComment({
76+
issue_number: issueNumber,
77+
owner,
78+
repo,
79+
body: commentBody,
80+
});
81+
82+
}
83+
84+
// Set the status as FAILED if any configuration changes are detected
85+
core.setFailed("Configuration Changes Detected, Update release documents - if necessary");
86+
} catch (error) {
87+
core.setFailed(error.message);
88+
}
89+
}

0 commit comments

Comments
 (0)