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: Add workflow for author approved label #98815

Merged
merged 11 commits into from
Jan 29, 2024
42 changes: 42 additions & 0 deletions .github/workflows/author_approval.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Author Approval Label
on:
issue_comment:
types: [created]

jobs:
label:
permissions:
pull-requests: write
ericphanson marked this conversation as resolved.
Show resolved Hide resolved
ericphanson marked this conversation as resolved.
Show resolved Hide resolved
runs-on: ubuntu-latest
# Run on comments that are:
ericphanson marked this conversation as resolved.
Show resolved Hide resolved
# 1) on PRs, not issues,
# 2) not from bot users and,
ericphanson marked this conversation as resolved.
Show resolved Hide resolved
# 3) include the string "approved"
# If so, we will do the work to check that the commenter is the package author,
# and conditionally apply the author-approved label.
if: ${{ github.event.issue.pull_request && github.event.issue.user.type != 'Bot' && contains(github.event.comment.body, 'approved') }}
ericphanson marked this conversation as resolved.
Show resolved Hide resolved
steps:
- name: Verify package author
id: verify-author
env:
# We use an env variable, not direct interpolation into the script, for security:
# https://docs.github.com/en/actions/security-guides/security-hardening-for-github-actions#using-an-intermediate-environment-variable
PR_BODY: ${{ github.event.issue.body }}
ericphanson marked this conversation as resolved.
Show resolved Hide resolved
COMMENTER: ${{ github.event.comment.user.login }}
shell: julia --compile=min --optimize=0 --color=yes {0}
run: |
m = match(r"Created by: @([^\s]+)", ENV["PR_BODY"])
ericphanson marked this conversation as resolved.
Show resolved Hide resolved
ericphanson marked this conversation as resolved.
Show resolved Hide resolved
verified = !isnothing(m) && m[1] == ENV["COMMENTER"]
println("Matched user: ", m === nothing ? nothing : m[1])
println("Commenter: ", ENV["COMMENTER"])
println("Verified: ", verified)
open(ENV["GITHUB_OUTPUT"], "a") do io
println(io, "verified=$verified")
end
- name: Add label
if: ${{ steps.verify-author.outputs.verified == 'true' }}
env:
PR_NUM: ${{ github.event.issue.number }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
ericphanson marked this conversation as resolved.
Show resolved Hide resolved
GH_REPO: ${{ github.repository }}
run: gh pr edit "$PR_NUM" --add-label "package-author-approved"
ericphanson marked this conversation as resolved.
Show resolved Hide resolved