From dd79df252e2f4d6f3c05179208091abb9186706e Mon Sep 17 00:00:00 2001 From: Allen Xu Date: Wed, 25 May 2022 09:56:51 +0800 Subject: [PATCH 1/3] Init signoff check Signed-off-by: Allen Xu --- .github/workflows/signoff-check.yml | 34 +++++++++ .github/workflows/signoff-check/Dockerfile | 22 ++++++ .github/workflows/signoff-check/action.yml | 19 +++++ .github/workflows/signoff-check/signoff-check | 69 +++++++++++++++++++ 4 files changed, 144 insertions(+) create mode 100644 .github/workflows/signoff-check.yml create mode 100644 .github/workflows/signoff-check/Dockerfile create mode 100644 .github/workflows/signoff-check/action.yml create mode 100644 .github/workflows/signoff-check/signoff-check diff --git a/.github/workflows/signoff-check.yml b/.github/workflows/signoff-check.yml new file mode 100644 index 00000000000..4222696202f --- /dev/null +++ b/.github/workflows/signoff-check.yml @@ -0,0 +1,34 @@ +# Copyright (c) 2022, NVIDIA CORPORATION. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# A workflow to check if PR got sign-off +name: signoff check + +on: + pull_request_target: + types: [opened, synchronize, reopened] + +jobs: + signoff-check: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - name: sigoff-check job + uses: ./.github/workflows/signoff-check + env: + OWNER: NVIDIA + REPO_NAME: spark-rapids-ml + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + PULL_NUMBER: ${{ github.event.number }} \ No newline at end of file diff --git a/.github/workflows/signoff-check/Dockerfile b/.github/workflows/signoff-check/Dockerfile new file mode 100644 index 00000000000..72f3ca23f8a --- /dev/null +++ b/.github/workflows/signoff-check/Dockerfile @@ -0,0 +1,22 @@ +# Copyright (c) 2022, NVIDIA CORPORATION. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +FROM python:alpine + +WORKDIR / +COPY signoff-check . +RUN pip install PyGithub && chmod +x /signoff-check + +# require envs: OWNER,REPO_NAME,GITHUB_TOKEN,PULL_NUMBER +ENTRYPOINT ["/signoff-check"] \ No newline at end of file diff --git a/.github/workflows/signoff-check/action.yml b/.github/workflows/signoff-check/action.yml new file mode 100644 index 00000000000..4a9d4fc2650 --- /dev/null +++ b/.github/workflows/signoff-check/action.yml @@ -0,0 +1,19 @@ +# Copyright (c) 2022, NVIDIA CORPORATION. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +name: 'signoff check action' +description: 'check if PR got signed off' +runs: + using: 'docker' + image: 'Dockerfile' \ No newline at end of file diff --git a/.github/workflows/signoff-check/signoff-check b/.github/workflows/signoff-check/signoff-check new file mode 100644 index 00000000000..15464d07f2c --- /dev/null +++ b/.github/workflows/signoff-check/signoff-check @@ -0,0 +1,69 @@ +#!/usr/bin/env python + +# Copyright (c) 2022, NVIDIA CORPORATION. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""A signoff check +The tool checks if any commit got signoff in a pull request. +NOTE: this script is for github actions only, you should not use it anywhere else. +""" +import os +import re +import sys +from argparse import ArgumentParser + +from github import Github + +SIGNOFF_REGEX = re.compile('Signed-off-by:') + + +def signoff(token: str, owner: str, repo_name: str, pull_number: int): + gh = Github(token, per_page=100, user_agent='signoff-check', verify=True) + pr = gh.get_repo(f"{owner}/{repo_name}").get_pull(pull_number) + for c in pr.get_commits(): + if SIGNOFF_REGEX.search(c.commit.message): + print('Found signoff.\n') + print(f"Commit sha:\n{c.commit.sha}") + print(f"Commit message:\n{c.commit.message}") + return True + return False + + +def main(token: str, owner: str, repo_name: str, pull_number: int): + try: + if not signoff(token, owner, repo_name, pull_number): + raise Exception('No commits w/ signoff') + except Exception as e: # pylint: disable=broad-except + print(e) + sys.exit(1) + + +if __name__ == '__main__': + parser = ArgumentParser(description="signoff check") + parser.add_argument("--owner", help="repo owner", default='') + parser.add_argument("--repo_name", help="repo name", default='') + parser.add_argument("--token", help="github token, will use GITHUB_TOKEN if empty", default='') + parser.add_argument("--pull_number", help="pull request number", type=int) + args = parser.parse_args() + + GITHUB_TOKEN = args.token if args.token else os.environ.get('GITHUB_TOKEN') + assert GITHUB_TOKEN, 'env GITHUB_TOKEN should not be empty' + OWNER = args.owner if args.owner else os.environ.get('OWNER') + assert OWNER, 'env OWNER should not be empty' + REPO_NAME = args.repo_name if args.repo_name else os.environ.get('REPO_NAME') + assert REPO_NAME, 'env REPO_NAME should not be empty' + PULL_NUMBER = args.pull_number if args.pull_number else int(os.environ.get('PULL_NUMBER')) + assert PULL_NUMBER, 'env PULL_NUMBER should not be empty' + + main(token=GITHUB_TOKEN, owner=OWNER, repo_name=REPO_NAME, pull_number=PULL_NUMBER) \ No newline at end of file From c4b3fe8b3aec23842e002b7ea2b5234759681c26 Mon Sep 17 00:00:00 2001 From: Allen Xu Date: Wed, 25 May 2022 09:59:57 +0800 Subject: [PATCH 2/3] add new line --- .github/workflows/signoff-check.yml | 2 +- .github/workflows/signoff-check/Dockerfile | 2 +- .github/workflows/signoff-check/action.yml | 2 +- .github/workflows/signoff-check/signoff-check | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/signoff-check.yml b/.github/workflows/signoff-check.yml index 4222696202f..e2064691961 100644 --- a/.github/workflows/signoff-check.yml +++ b/.github/workflows/signoff-check.yml @@ -31,4 +31,4 @@ jobs: OWNER: NVIDIA REPO_NAME: spark-rapids-ml GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - PULL_NUMBER: ${{ github.event.number }} \ No newline at end of file + PULL_NUMBER: ${{ github.event.number }} diff --git a/.github/workflows/signoff-check/Dockerfile b/.github/workflows/signoff-check/Dockerfile index 72f3ca23f8a..726aac4c744 100644 --- a/.github/workflows/signoff-check/Dockerfile +++ b/.github/workflows/signoff-check/Dockerfile @@ -19,4 +19,4 @@ COPY signoff-check . RUN pip install PyGithub && chmod +x /signoff-check # require envs: OWNER,REPO_NAME,GITHUB_TOKEN,PULL_NUMBER -ENTRYPOINT ["/signoff-check"] \ No newline at end of file +ENTRYPOINT ["/signoff-check"] diff --git a/.github/workflows/signoff-check/action.yml b/.github/workflows/signoff-check/action.yml index 4a9d4fc2650..8b608f87170 100644 --- a/.github/workflows/signoff-check/action.yml +++ b/.github/workflows/signoff-check/action.yml @@ -16,4 +16,4 @@ name: 'signoff check action' description: 'check if PR got signed off' runs: using: 'docker' - image: 'Dockerfile' \ No newline at end of file + image: 'Dockerfile' diff --git a/.github/workflows/signoff-check/signoff-check b/.github/workflows/signoff-check/signoff-check index 15464d07f2c..9e55a262198 100644 --- a/.github/workflows/signoff-check/signoff-check +++ b/.github/workflows/signoff-check/signoff-check @@ -66,4 +66,4 @@ if __name__ == '__main__': PULL_NUMBER = args.pull_number if args.pull_number else int(os.environ.get('PULL_NUMBER')) assert PULL_NUMBER, 'env PULL_NUMBER should not be empty' - main(token=GITHUB_TOKEN, owner=OWNER, repo_name=REPO_NAME, pull_number=PULL_NUMBER) \ No newline at end of file + main(token=GITHUB_TOKEN, owner=OWNER, repo_name=REPO_NAME, pull_number=PULL_NUMBER) From cfe6b247ffa833fdca21a445cad30219196eb6d1 Mon Sep 17 00:00:00 2001 From: Allen Xu Date: Thu, 26 May 2022 09:38:10 +0800 Subject: [PATCH 3/3] modify repo name Signed-off-by: Allen Xu --- .github/workflows/signoff-check.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/signoff-check.yml b/.github/workflows/signoff-check.yml index e2064691961..146e33d0928 100644 --- a/.github/workflows/signoff-check.yml +++ b/.github/workflows/signoff-check.yml @@ -29,6 +29,6 @@ jobs: uses: ./.github/workflows/signoff-check env: OWNER: NVIDIA - REPO_NAME: spark-rapids-ml + REPO_NAME: spark-rapids-benchmarks GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} PULL_NUMBER: ${{ github.event.number }}