CodeOwners Review Analysis (cora) #3313
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: "CodeOwners Review Analysis (cora)" | |
on: | |
pull_request: | |
types: | |
- labeled # when adding 'cora' label | |
pull_request_review: | |
types: | |
- submitted | |
- edited | |
- dismissed | |
issue_comment: | |
types: [created] # when commenting .cora | |
jobs: | |
analyze-reviews: | |
name: "analyze" | |
runs-on: ubuntu-latest | |
permissions: | |
actions: read # needed to pull actions run url | |
contents: read # needed to pull codeowners file | |
id-token: write # used to assume aws role | |
pull-requests: write # needed to read pull request and add comments | |
issues: write # needed to add labels on PRs (weirdly) | |
steps: | |
- name: Run Conditions | |
id: run-conditions | |
env: | |
ISSUE_COMMENT: ${{ github.event_name == 'issue_comment' && contains(github.event.comment.body, '.cora') }} | |
PR_LABEL: ${{ contains(github.event.pull_request.labels.*.name, 'cora') }} | |
run: | | |
if [[ "$ISSUE_COMMENT" == "true" ]]; then | |
echo "cora-comment=true" | tee -a "${GITHUB_OUTPUT}" | |
echo "run-cora=true" | tee -a "${GITHUB_OUTPUT}" | |
elif [[ "$PR_LABEL" == "true" ]]; then | |
echo "run-cora=true" | tee -a "${GITHUB_OUTPUT}" | |
else | |
echo "run-cora=false" | tee -a "${GITHUB_OUTPUT}" | |
echo "To run this workflow, comment '.cora' on the PR." | |
echo "Commenting this will add the 'cora' label to the PR, and enable it for future events." | |
echo "Note: Adding the label manually will trigger other workflows, which is why we recommend commenting instead." | |
fi | |
- name: Add 'cora' label on comments | |
if: ${{ steps.run-conditions.outputs.cora-comment == 'true' }} | |
continue-on-error: true | |
env: | |
GITHUB_REPOSITORY: ${{ github.repository }} | |
PULL_REQUEST_NUMBER: ${{ github.event.pull_request.number || github.event.issue.number }} | |
GH_TOKEN: ${{ github.token }} | |
run: | | |
# See: https://docs.github.com/en/rest/issues/labels?apiVersion=2022-11-28#add-labels-to-an-issue | |
gh api \ | |
--method POST \ | |
/repos/${GITHUB_REPOSITORY}/issues/${PULL_REQUEST_NUMBER}/labels \ | |
--input - <<< '{ | |
"labels": [ | |
"cora" | |
] | |
}' | |
- name: Setup github token | |
id: setup-github-token | |
if: ${{ steps.run-conditions.outputs.run-cora == 'true' }} | |
uses: smartcontractkit/.github/actions/setup-github-token@setup-github-token/v1 | |
with: | |
aws-role-arn: ${{ secrets.GATI_CODEOWNERS_IAM_ARN }} | |
aws-lambda-url: ${{ secrets.GATI_CODEOWNERS_LAMBDA_URL }} | |
aws-region: us-west-2 | |
- name: CODEOWNERS Review Analysis | |
if: ${{ steps.run-conditions.outputs.run-cora == 'true' }} | |
uses: smartcontractkit/.github/actions/codeowners-review-analysis@codeowners-review-analysis/v1 | |
env: | |
GITHUB_TOKEN: ${{ github.token }} | |
with: | |
members-read-github-token: ${{ steps.setup-github-token.outputs.access-token }} |