Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: verify changes to Maintainers.yaml made by the bot #750

Merged
merged 45 commits into from
Aug 9, 2023
Merged
Changes from 12 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
2062642
added new workflow to validate maintainers
14Richa Jun 15, 2023
514aa22
added msg body when PR is raised by human
14Richa Jun 16, 2023
f77acfc
changed maintainers.yaml caps also declared new var PATH
14Richa Jun 20, 2023
7688bdd
changed file name and workflow file name
14Richa Jun 27, 2023
4fc28ad
Merge branch 'master' into 14Richa/validate-maintainers
14Richa Jun 27, 2023
65bea9f
added script
14Richa Jun 28, 2023
0b074bb
added close pr and comment on pr functionality
14Richa Jun 28, 2023
c224cb1
minor fix in maintainers file name
14Richa Jun 28, 2023
cb4acd2
updated the version
14Richa Jun 28, 2023
7f21761
updated the verify maintainer workflw
14Richa Jun 29, 2023
61ffea8
deleted the script
14Richa Jun 29, 2023
e1dbd58
minor fix related to file name
14Richa Jun 30, 2023
5ebc520
minor fix added errormessage array
14Richa Jul 3, 2023
3e3de3f
Merge branch 'master' into 14Richa/validate-maintainers
14Richa Jul 4, 2023
1d181b6
Update .github/workflows/verify-maintainers.yaml
14Richa Jul 4, 2023
514489e
Update .github/workflows/verify-maintainers.yaml
14Richa Jul 4, 2023
0df6a07
Update .github/workflows/verify-maintainers.yaml
14Richa Jul 4, 2023
9c788f7
Update .github/workflows/verify-maintainers.yaml
14Richa Jul 4, 2023
a1cdb43
fixed error messages
14Richa Jul 4, 2023
682ac24
added comment
14Richa Jul 4, 2023
8dfe2fb
removed a function createComment
14Richa Jul 4, 2023
5f63633
used toString method
14Richa Jul 4, 2023
20cef78
added comments in the script
14Richa Jul 4, 2023
cc5fc18
minor fix
14Richa Jul 5, 2023
1608a1f
Update .github/workflows/verify-maintainers.yaml
14Richa Jul 5, 2023
9835e3d
added conditon on pr open
14Richa Jul 5, 2023
5da2a91
added a new check to repo list added
14Richa Jul 10, 2023
b496dd5
Update .github/workflows/verify-maintainers.yaml
14Richa Jul 11, 2023
0ff69b1
Update .github/workflows/verify-maintainers.yaml
14Richa Jul 11, 2023
39bdae7
Update .github/workflows/verify-maintainers.yaml
14Richa Jul 11, 2023
4fd66a2
Update .github/workflows/verify-maintainers.yaml
14Richa Jul 11, 2023
8dcd297
Update .github/workflows/verify-maintainers.yaml
14Richa Jul 11, 2023
d0e5fc9
Update .github/workflows/verify-maintainers.yaml
14Richa Jul 11, 2023
6e936d7
added remove code in repo condition
14Richa Jul 11, 2023
7b9104a
Merge branch '14Richa/validate-maintainers' of github.com:14Richa/com…
14Richa Jul 11, 2023
4f52673
Update .github/workflows/verify-maintainers.yaml
14Richa Jul 12, 2023
a4ea5db
minor fix in msg
14Richa Jul 13, 2023
601e49c
Merge branch '14Richa/validate-maintainers' of github.com:14Richa/com…
14Richa Jul 13, 2023
6ae39fe
Merge branch 'master' into 14Richa/validate-maintainers
derberg Jul 31, 2023
63b19b0
made changes in verify maintainer changes
14Richa Aug 1, 2023
d816f22
Merge branch '14Richa/validate-maintainers' of github.com:14Richa/com…
14Richa Aug 1, 2023
b9cf2b1
syntax fix
14Richa Aug 3, 2023
24de526
update the workflow divided the workflow in jobs
14Richa Aug 3, 2023
9d2a42c
update the token name
14Richa Aug 3, 2023
3e03b9a
Merge branch 'master' into 14Richa/validate-maintainers
derberg Aug 8, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 81 additions & 0 deletions .github/workflows/verify-maintainers.yaml
14Richa marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
name: Verify Maintainers Changes
14Richa marked this conversation as resolved.
Show resolved Hide resolved

on:
pull_request:
types: [synchronize, opened]
14Richa marked this conversation as resolved.
Show resolved Hide resolved
paths:
- "MAINTAINERS.yaml"

jobs:
verify-changes:
14Richa marked this conversation as resolved.
Show resolved Hide resolved
runs-on: ubuntu-latest
steps:
- name: Checkout main branch
uses: actions/checkout@v3
with:
ref: master
path: community-main

- name: Checkout PR branch
uses: actions/checkout@v3
with:
ref: ${{ github.head_ref }}
path: pr-branch

- name: Install Dependencies
run: npm install yaml

- name: Verify changes in MAINTAINERS.yaml
id: verify-changes
uses: actions/github-script@v5
14Richa marked this conversation as resolved.
Show resolved Hide resolved
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const yaml = require("yaml");
const fs = require("fs");

const mainFile = yaml.parse(fs.readFileSync("./community-main/MAINTAINERS.yaml", "utf8"));
const prFile = yaml.parse(fs.readFileSync("./pr-branch/MAINTAINERS.yaml", "utf8"));

const beforeMaintainers = new Map(mainFile.map((maintainer) => [maintainer.name, {github: maintainer.github, repos: maintainer.repos || []}]));
let isCriticalChangeDetected = false;

const owner = "${{ github.repository_owner }}";
const repo = "${{ github.event.repository.name }}";
const pull_number = "${{ github.event.pull_request.number }}";

if (prFile.length < mainFile.length) {
14Richa marked this conversation as resolved.
Show resolved Hide resolved
core.error(`Critical changes have been made to Maintainers.yaml. A maintainer has been removed. Please review.`);
isCriticalChangeDetected = true;
}

for (const maintainer of prFile) {
const previousData = beforeMaintainers.get(maintainer.name);
if (!previousData) {
14Richa marked this conversation as resolved.
Show resolved Hide resolved
core.error(`Critical changes have been made to Maintainers.yaml by ${maintainer.name}. A new maintainer has been added. Please review.`);
isCriticalChangeDetected = true;
break;
} else {
14Richa marked this conversation as resolved.
Show resolved Hide resolved
const previousGithub = previousData.github;
const previousRepos = previousData.repos;

if (previousGithub !== maintainer.github || JSON.stringify(previousRepos) !== JSON.stringify(maintainer.repos || [])) {
core.error(`Critical changes have been made to Maintainers.yaml by ${maintainer.name}. GitHub key or repos list has been modified. Please review.`);
isCriticalChangeDetected = true;
break;
}
}
}

// If critical change is detected, create a comment on the PR and close it.
if (isCriticalChangeDetected) {
github.rest.issues.createComment({ owner, repo, issue_number: pull_number, body: 'Critical changes detected in Maintainers.yaml. A maintainer has been added, removed, or had their GitHub key or repos list modified. Please review.' });
14Richa marked this conversation as resolved.
Show resolved Hide resolved

// Close the PR
github.rest.pulls.update({
owner,
repo,
pull_number,
state: 'closed'
});
}