Skip to content

Commit

Permalink
add fellows check; improve regex
Browse files Browse the repository at this point in the history
  • Loading branch information
mordamax committed Aug 1, 2024
1 parent 6c3ff52 commit 0bed466
Showing 1 changed file with 51 additions and 9 deletions.
60 changes: 51 additions & 9 deletions .github/workflows/cmd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,50 @@ permissions: # allow the action to comment on the PR
actions: read

jobs:
fellows:
runs-on: ubuntu-latest
outputs:
github-handles: ${{ steps.load-fellows.outputs.github-handles }}
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Load fellows
id: load-fellows
uses: paritytech/get-fellows-action@v1.2.0

reject-non-fellows:
needs: fellows
if: ${{ startsWith(github.event.comment.body, '/cmd') && !contains(needs.fellows.outputs.github-handles, github.event.sender.login) }}
runs-on: ubuntu-latest
steps:
- name: Add reaction to rejected comment
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
github.rest.reactions.createForIssueComment({
comment_id: ${{ github.event.comment.id }},
owner: context.repo.owner,
repo: context.repo.repo,
content: 'confused'
})
- name: Comment PR (Rejected)
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `Sorry, only fellows can run commands.`
})
acknowledge:
if: ${{ startsWith(github.event.comment.body, '/cmd') }}
needs: fellows
if: ${{ startsWith(github.event.comment.body, '/cmd') && contains(needs.fellows.outputs.github-handles, github.event.sender.login) }}
runs-on: ubuntu-latest
steps:
- name: Add reaction to triggered comment
Expand All @@ -28,13 +70,14 @@ jobs:
})
clean:
needs: fellows
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Clean previous comments
if: ${{ startsWith(github.event.comment.body, '/cmd') && contains(github.event.comment.body, '--clean') }}
if: ${{ startsWith(github.event.comment.body, '/cmd') && contains(github.event.comment.body, '--clean') && contains(needs.fellows.outputs.github-handles, github.event.sender.login) }}
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
Expand Down Expand Up @@ -62,8 +105,8 @@ jobs:
}
})
help:
needs: clean
if: ${{ startsWith(github.event.comment.body, '/cmd') && contains(github.event.comment.body, '--help') }}
needs: [clean, fellows]
if: ${{ startsWith(github.event.comment.body, '/cmd') && contains(github.event.comment.body, '--help') && contains(needs.fellows.outputs.github-handles, github.event.sender.login) }}
runs-on: ubuntu-latest
steps:
- name: Checkout
Expand All @@ -74,7 +117,7 @@ jobs:
id: get-pr-comment
with:
text: ${{ github.event.comment.body }}
regex: '^(\/cmd )(.*)$'
regex: '^(\/cmd )([\s\w-]+)\n'

- name: Save output of help
id: help
Expand Down Expand Up @@ -124,10 +167,10 @@ jobs:
})
cmd:
needs: clean
needs: [clean, fellows]
env:
JOB_NAME: 'cmd'
if: ${{ startsWith(github.event.comment.body, '/cmd') && !contains(github.event.comment.body, '--help') }}
if: ${{ startsWith(github.event.comment.body, '/cmd') && !contains(github.event.comment.body, '--help') && contains(needs.fellows.outputs.github-handles, github.event.sender.login) }}
# TODO: replace runner for bench, when it's ready
runs-on: ${{ startsWith(github.event.comment.body, '/cmd bench') && 'ubuntu-22.04' || 'ubuntu-22.04' }}
steps:
Expand All @@ -142,7 +185,7 @@ jobs:
id: get-pr-comment
with:
text: ${{ github.event.comment.body }}
regex: '^(\/cmd )(.*)$'
regex: '^(\/cmd )([\s\w-]+)\n'

- name: Build workflow link
if: ${{ !contains(github.event.comment.body, '--quiet') }}
Expand Down Expand Up @@ -216,7 +259,6 @@ jobs:
run: |
echo "Running command: $CMD"
git remote -v
# TODO: uncomment
python3 .github/scripts/cmd/cmd.py $CMD
git status
git diff
Expand Down

0 comments on commit 0bed466

Please sign in to comment.