Skip to content

Remove ACLs for automated testing dispatch targets #672

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

Merged
merged 1 commit into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
43 changes: 43 additions & 0 deletions .github/actions/check-permissions/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Check current actor permissions
description: |
Checks whether the current actor has the specified permssions
inputs:
minimum-permission:
description: |
The minimum required permission. One of: read, write, admin
required: true
outputs:
has-permission:
description: "Whether the actor had the minimum required permission"
value: ${{ steps.check-permission.outputs.has-permission }}

runs:
using: composite
steps:
- uses: actions/github-script@v7
id: check-permission
with:
script: |
// Valid permissions are none, read, write, admin (legacy base permissions)
const permissionsRanking = ["none", "read", "write", "admin"];

const minimumPermission = core.getInput('minimum-permission');
if (!permissionsRanking.includes(minimumPermission)) {
core.setFailed(`Invalid minimum permission: ${minimumPermission}`);
return;
}

const { data : { permission : actorPermission } } = await github.rest.repos.getCollaboratorPermissionLevel({
owner: context.repo.owner,
repo: context.repo.repo,
username: tools.context.actor
});

// Confirm whether the actor permission is at least the selected permission
const hasPermission = permissionsRanking.indexOf(minimumPermission) <= permissionsRanking.indexOf(actorPermission) ? "1" : "";
core.setOutput('has-permission', hasPermission);
if (!hasPermission) {
core.info(`Current actor (${tools.context.actor}) does not have the minimum required permission '${minimumPermission}' (has '${actorPermission}')`);
} else {
core.info(`Current actor (${tools.context.actor}) has the minimum required permission '${minimumPermission}' (has '${actorPermission}')`);
}
13 changes: 7 additions & 6 deletions .github/workflows/dispatch-matrix-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@ jobs:
dispatch-matrix-check:
runs-on: ubuntu-22.04
steps:
- name: Test Variables
shell: pwsh
run: |
Write-Host "Running as: ${{github.actor}}"
- name: Check permission
id: check-write-permission
uses: ./.github/actions/check-permissions
with:
minimum-permission: "write"

- name: Dispatch Matrix Testing Job
if: ${{ contains(fromJSON('["mbaluda", "lcartey", "rvermeulen", "ravikprasad", "jeongsoolee09", "hohn", "knewbury01", "nicolaswill"]'), github.actor) }}
if: steps.check-write-permission.outputs.has-permission
uses: peter-evans/repository-dispatch@v2
with:
token: ${{ secrets.RELEASE_ENGINEERING_TOKEN }}
Expand All @@ -26,7 +27,7 @@ jobs:
client-payload: '{"pr": "${{ github.event.number }}"}'

- uses: actions/github-script@v6
if: ${{ contains(fromJSON('["mbaluda", "lcartey", "rvermeulen", "ravikprasad", "jeongsoolee09", "hohn", "knewbury01", "nicolaswill"]'), github.actor) }}
if: steps.check-write-permission.outputs.has-permission
with:
script: |
github.rest.issues.createComment({
Expand Down
25 changes: 7 additions & 18 deletions .github/workflows/dispatch-matrix-test-on-comment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,19 @@ name: 🤖 Run Matrix Check (On Comment)
on:
issue_comment:
types: [created]
branches:
- main
- "rc/**"
- next

jobs:
dispatch-matrix-check:
runs-on: ubuntu-22.04
steps:
- name: Test Variables
shell: pwsh
run: |
Write-Host "Running as: ${{github.actor}}"

$actor = "${{github.actor}}"

$acl = @("mbaluda", "lcartey", "rvermeulen", "ravikprasad", "jeongsoolee09", "hohn", "knewbury01", "nicolaswill")

if(-not ($actor -in $acl)){
throw "Refusing to run workflow for user not in acl."
}
- name: Check permission
id: check-write-permission
uses: ./.github/actions/check-permissions
with:
minimum-permission: "write"

- name: Dispatch Matrix Testing Job
if: ${{ github.event.issue.pull_request && contains(github.event.comment.body, '/test-matrix') }}
if: ${{ github.event.issue.pull_request && contains(github.event.comment.body, '/test-matrix') && steps.check-write-permission.outputs.has-permission }}
uses: peter-evans/repository-dispatch@v2
with:
token: ${{ secrets.RELEASE_ENGINEERING_TOKEN }}
Expand All @@ -35,7 +24,7 @@ jobs:
client-payload: '{"pr": "${{ github.event.issue.number }}"}'

- uses: actions/github-script@v6
if: ${{ github.event.issue.pull_request && contains(github.event.comment.body, '/test-matrix') }}
if: ${{ github.event.issue.pull_request && contains(github.event.comment.body, '/test-matrix') && steps.check-write-permission.outputs.has-permission }}
with:
script: |
github.rest.issues.createComment({
Expand Down
25 changes: 7 additions & 18 deletions .github/workflows/dispatch-release-performance-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,19 @@ name: 🏁 Run Release Performance Check
on:
issue_comment:
types: [created]
branches:
- main
- "rc/**"
- next

jobs:
dispatch-matrix-check:
runs-on: ubuntu-22.04
steps:
- name: Test Variables
shell: pwsh
run: |
Write-Host "Running as: ${{github.actor}}"

$actor = "${{github.actor}}"

$acl = @("mbaluda", "lcartey", "rvermeulen", "ravikprasad", "jeongsoolee09", "hohn", "knewbury01", "nicolaswill")

if(-not ($actor -in $acl)){
throw "Refusing to run workflow for user not in acl."
}
- name: Check permission
id: check-write-permission
uses: ./.github/actions/check-permissions
with:
minimum-permission: "write"

- name: Dispatch Performance Testing Job
if: ${{ github.event.issue.pull_request && contains(github.event.comment.body, '/test-performance') }}
if: ${{ github.event.issue.pull_request && contains(github.event.comment.body, '/test-performance') && steps.check-write-permission.outputs.has-permission }}
uses: peter-evans/repository-dispatch@v2
with:
token: ${{ secrets.RELEASE_ENGINEERING_TOKEN }}
Expand All @@ -35,7 +24,7 @@ jobs:
client-payload: '{"pr": "${{ github.event.issue.number }}"}'

- uses: actions/github-script@v6
if: ${{ github.event.issue.pull_request && contains(github.event.comment.body, '/test-performance') }}
if: ${{ github.event.issue.pull_request && contains(github.event.comment.body, '/test-performance') && steps.check-write-permission.outputs.has-permission }}
with:
script: |
github.rest.issues.createComment({
Expand Down
Loading