From: Naveen Naidu Date: Thu, 17 Apr 2025 13:50:57 +0000 (+0530) Subject: .github/workflow: add diff ceph config action X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=dacabbbc02511e6900f3bd4a44b9f04cd62b2c29;p=ceph.git .github/workflow: add diff ceph config action Signed-off-by: Naveen Naidu --- diff --git a/.github/labeler.yml b/.github/labeler.yml index 3a3a348dcfe16..e60614b95cd04 100644 --- a/.github/labeler.yml +++ b/.github/labeler.yml @@ -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 index 0000000000000..53f15f04b71d0 --- /dev/null +++ b/.github/workflows/diff-ceph-config.yml @@ -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<> "$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 index 0000000000000..23e551ffaae27 --- /dev/null +++ b/.github/workflows/scripts/config-diff-post-comment.js @@ -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