diff --git a/.github/workflows/checks_secure.yml b/.github/workflows/checks_secure.yml deleted file mode 100644 index 1d754dad3a..0000000000 --- a/.github/workflows/checks_secure.yml +++ /dev/null @@ -1,54 +0,0 @@ -name: Checks (secure) -# These are run on base branch with read/write access. - -on: - # This trigger is only safe-ish to use if steps are gated behind the - # "Check user permission" step below. - # zizmor: ignore[dangerous-triggers] - pull_request_target: - types: [synchronize] - -permissions: write-all - -concurrency: - group: ${{ github.workflow }}-${{ github.head_ref || github.ref }} - cancel-in-progress: true - -jobs: - dismiss_stale_approvals: - # Dismiss stale approvals for users without write access, or if this PR comes from a fork. - runs-on: ubuntu-22.04 - # Only if another commit was added to the PR. - steps: - - name: Check user permission - id: check - # This step sets outputs.has-permission to '1' or '' - env: - GH_TOKEN: ${{ github.token }} - ACTOR: ${{ github.actor }} - run: | - permission=$(gh api "repos/${GITHUB_REPOSITORY}/collaborators/${ACTOR}/permission" --jq '.permission' || echo "none") - echo "User ${ACTOR} has permission: ${permission}" - if [[ "${permission}" == "write" || "${permission}" == "admin" ]]; then - echo "has-permission=1" >> "$GITHUB_OUTPUT" - else - echo "has-permission=" >> "$GITHUB_OUTPUT" - fi - - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # ratchet:actions/checkout@v7 - if: steps.check.outputs.has-permission != 1 || github.event.pull_request.head.repo.full_name != github.repository - with: - persist-credentials: true # zizmor: ignore[artipacked] - submodules: false - - name: Setup python - if: steps.check.outputs.has-permission != 1 || github.event.pull_request.head.repo.full_name != github.repository - uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # ratchet:actions/setup-python@v7 - with: - python-version: 3.9 - - name: Install prerequisites - if: steps.check.outputs.has-permission != 1 || github.event.pull_request.head.repo.full_name != github.repository - run: pip install -r scripts/gha/python_requirements.txt - - name: Dismiss reviews - if: steps.check.outputs.has-permission != 1 || github.event.pull_request.head.repo.full_name != github.repository - shell: bash - run: | - python scripts/gha/dismiss_reviews.py --token ${{github.token}} --pull_number ${{github.event.pull_request.number}} --review_state=APPROVED --message "🍞 Dismissed stale approval on external PR." diff --git a/scripts/gha/dismiss_reviews.py b/scripts/gha/dismiss_reviews.py deleted file mode 100644 index 4e98a11e2a..0000000000 --- a/scripts/gha/dismiss_reviews.py +++ /dev/null @@ -1,85 +0,0 @@ -# Copyright 2021 Google LLC -# -# 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 utility to dismiss PR reviews. - -USAGE: - python3 scripts/gha/dismiss_reviews.py \ - --token ${{github.token}} \ - --pull_number ${{needs.check_trigger.outputs.pr_number}} \ - [--message 'Message to be posted on the dismissal.'] \ - [--reviewer github_username] \ - [--review_state ANY|APPROVED|CHANGES_REQUESTED|COMMENTED|PENDING] -""" - -import datetime -import shutil - -from absl import app -from absl import flags -from absl import logging - -import firebase_github - -FLAGS = flags.FLAGS -_DEFAULT_MESSAGE = "Dismissing stale review." - -flags.DEFINE_string( - "token", None, - "github.token: A token to authenticate on your repository.") - -flags.DEFINE_string( - "pull_number", None, - "Github's pull request #.") - -flags.DEFINE_string( - "message", _DEFAULT_MESSAGE, - "Message to post on dismissed reviews") - -flags.DEFINE_string( - "reviewer", None, - "Reviewer to dismiss (by username). If unspecified, dismiss all reviews.") - -flags.DEFINE_enum( - "review_state", "ANY", ["ANY", "APPROVED", "CHANGES_REQUESTED", "COMMENTED", - "PENDING"], - "Only dismiss reviews in this state. Specify ANY for any state.") - -def main(argv): - if len(argv) > 1: - raise app.UsageError("Too many command-line arguments.") - # Get list of reviews from PR. - reviews = firebase_github.get_reviews(FLAGS.token, FLAGS.pull_number) - logging.debug("Found %d reviews", len(reviews)) - - # Filter out already-dismissed reviews. - reviews = [r for r in reviews if r['state'] != 'DISMISSED'] - # Filter by review_state if specified. - if FLAGS.review_state != 'ANY': - reviews = [r for r in reviews if r['state'] == FLAGS.review_state] - # Filter by reviewer's username, if specified. - if FLAGS.reviewer: - reviews = [r for r in reviews if r['user']['login'] == FLAGS.reviewer] - - if reviews: - review_ids = [r['id'] for r in reviews] - logging.debug("Dismissing reviews: %s", review_ids) - for review_id in review_ids: - firebase_github.dismiss_review(FLAGS.token, FLAGS.pull_number, - review_id, FLAGS.message) - -if __name__ == "__main__": - flags.mark_flag_as_required("token") - flags.mark_flag_as_required("pull_number") - app.run(main)