]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
.github/workflow: add diff ceph config action 63136/head
authorNaveen Naidu <naveennaidu479@gmail.com>
Thu, 17 Apr 2025 13:50:57 +0000 (19:20 +0530)
committerNaveen Naidu <naveennaidu479@gmail.com>
Wed, 4 Jun 2025 03:16:12 +0000 (08:46 +0530)
Signed-off-by: Naveen Naidu <naveen.naidu@ibm.com>
.github/labeler.yml
.github/workflows/diff-ceph-config.yml [new file with mode: 0644]
.github/workflows/scripts/config-diff-post-comment.js [new file with mode: 0644]

index 3a3a348dcfe16af308781f38430ae2d8fef8c84e..e60614b95cd04bb54b9bf793a9495b3d234b7344 100644 (file)
@@ -345,3 +345,6 @@ script:
   - src/script/**
   - admin/**
   - doc/scripts/**
+
+config-change:
+  - src/common/options/**
diff --git a/.github/workflows/diff-ceph-config.yml b/.github/workflows/diff-ceph-config.yml
new file mode 100644 (file)
index 0000000..53f15f0
--- /dev/null
@@ -0,0 +1,63 @@
+name: Check ceph config changes
+on:
+  pull_request_target:
+    types:
+      - opened
+      - synchronize
+      - edited
+      - reopened
+
+# The following permissions are needed to write a comment to repo
+permissions:
+    issues: write
+    contents: read
+    pull-requests: write
+
+jobs:
+  pull_request:
+    runs-on: ubuntu-latest
+    steps:
+      - name: checkout ceph.git
+        uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 #v4.2.2
+        with:
+          path: ceph
+          sparse-checkout: |
+            src/script
+            src/common/options
+            .github/workflows
+
+      - name: Setup Python
+        uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 #v5.6.0
+        with:
+          python-version: '3.13'
+
+      - name: Install python packages
+        run: |
+          pip3 install -r ./src/script/config-diff/requirements.txt
+        working-directory: ceph
+
+      - name: execute config diff tool
+        id: diff_tool
+        env:
+          REF_REPO: ${{ github.event.pull_request.base.repo.clone_url }}
+          REF_BRANCH: ${{ github.event.pull_request.base.ref }}
+          REMOTE_REPO: ${{ github.event.pull_request.head.repo.clone_url }}
+          REMOTE_BRANCH: ${{ github.event.pull_request.head.ref }}
+        run:  |
+          {
+            echo 'DIFF_JSON<<EOF'
+            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
+            echo EOF
+          } >> "$GITHUB_OUTPUT"
+        working-directory: ceph
+
+      - name: Post output as a comment
+        uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea #v7.0.1
+        env:
+          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+          DIFF_JSON_OUTPUT: ${{ steps.diff_tool.outputs.DIFF_JSON }}
+        with:
+          script: |
+            const configDiff = process.env.DIFF_JSON_OUTPUT;
+            const postComment = require('./ceph/.github/workflows/scripts/config-diff-post-comment.js');
+            postComment({ github, context, core, configDiff });
\ No newline at end of file
diff --git a/.github/workflows/scripts/config-diff-post-comment.js b/.github/workflows/scripts/config-diff-post-comment.js
new file mode 100644 (file)
index 0000000..23e551f
--- /dev/null
@@ -0,0 +1,89 @@
+module.exports = async ({ github, context, core, configDiff }) => {
+  try {
+      // Do not create comment if there are no configuration changes
+      if (!configDiff) {
+        console.log("No changes detected. Skipping comment creation.");
+        return;
+      }
+
+      const commentBody = `
+### Config Diff Tool Output
+
+\`\`\`diff
+
+${configDiff}
+
+\`\`\`
+
+The above configuration changes are found in the PR. Please update the relevant release documentation if necessary.
+  `;
+
+      core.summary.addRaw(commentBody);
+      await core.summary.write()
+
+      const { owner, repo } = context.repo;
+      const issueNumber = context.payload.pull_request.number;
+
+      // List all files in the pull request
+      core.info("Fetching list of files changed in the pull request...");
+      const files = await github.paginate(
+          github.rest.pulls.listFiles,
+          {
+              owner,
+              repo,
+              pull_number: issueNumber,
+              per_page: 100,
+          }
+      );
+
+      // Annotate YAML files
+      files.forEach(file => {
+        // Only annotate the `yaml.in` files present in `src/common/options` folder
+        if (file.filename.endsWith(".yaml.in") && file.filename.startsWith("src/common/options/")) {
+            core.info(`Annotating file: ${file.filename}`);
+            core.notice(
+                `Configuration changes detected in ${file.filename}. Please update the relevant release documentation if necessary.`,
+                {
+                    title: "Configuration Change Detected",
+                    file: file.filename,
+                    startLine: 1,
+                    endLine: 1,
+                }
+            );
+        }
+    });
+
+      
+      // List all the comments
+      const comments = await github.paginate(
+        github.rest.issues.listComments, {
+          owner,
+          repo,
+          issue_number: issueNumber,
+          per_page: 100,
+        }
+      );
+  
+      const existingComment = comments.find(comment => comment.body.includes("### Config Diff Tool Output"));
+  
+      if (existingComment) {
+        core.info("A config diff comment already exists, deleting it...");
+      } else {
+        core.info("Creating a new config diff comment...");
+        // Create a new comment
+        await github.rest.issues.createComment({
+          issue_number: issueNumber,
+          owner,
+          repo,
+          body: commentBody,
+        });
+
+      }
+  
+      // Set the status as FAILED if any configuration changes are detected
+      core.setFailed("Configuration Changes Detected, Update release documents - if necessary");
+    } catch (error) {
+      core.setFailed(error.message);
+    }
+}
\ No newline at end of file