-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add fellows check; improve regex; Create running-commands.md
- Loading branch information
Showing
2 changed files
with
83 additions
and
9 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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/[email protected] | ||
|
||
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 | ||
|
@@ -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 }} | ||
|
@@ -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 | ||
|
@@ -74,7 +117,7 @@ jobs: | |
id: get-pr-comment | ||
with: | ||
text: ${{ github.event.comment.body }} | ||
regex: '^(\/cmd )(.*)$' | ||
regex: '^(\/cmd )([\s\w-]+)$' | ||
|
||
- name: Save output of help | ||
id: help | ||
|
@@ -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: | ||
|
@@ -142,7 +185,7 @@ jobs: | |
id: get-pr-comment | ||
with: | ||
text: ${{ github.event.comment.body }} | ||
regex: '^(\/cmd )(.*)$' | ||
regex: '^(\/cmd )([\s\w-]+)$' | ||
|
||
- name: Build workflow link | ||
if: ${{ !contains(github.event.comment.body, '--quiet') }} | ||
|
@@ -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 | ||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# Running Commands in PRs | ||
|
||
You can run commands in PRs by triggering it via comment. It will use the context of your PR and post the results back. | ||
|
||
## Usage | ||
|
||
`/cmd --help` to see all available commands and usage format | ||
|
||
`/cmd <command> --help` to see the usage of a specific command | ||
|
||
|
||
### Commands | ||
|
||
- `/cmd fmt` to format the code in the PR. It commits back with the formatted code (fmt) and configs (taplo). | ||
|
||
- `/cmd bench` to generate weights for a runtime. Read more about [Weight Generation](./weight-generation.md) | ||
|
||
### Flags | ||
|
||
1.`--quiet` to suppress the output of the command in the comments. | ||
By default the Start and End/Failure of the command will be commented with the link to a pipeline. | ||
If you want to avoid, use this flag. Go to [Action Tab](https://github.com/polkadot-fellows/runtimes/actions/workflows/cmd.yml) to see the pipeline status. | ||
|
||
2.`--continue-on-fail` to continue running the command even if something inside of a command (like specific pallet weight generation) are failed. | ||
Basically avoids interruption in the middle with `exit 1` | ||
The pipeline logs will include what is failed (like which runtimes/pallets), then you can re-run them separately or not. | ||
|
||
3.`--clean` to clean up all yours and bot's comments in PR relevant to `/cmd` commands. If you run too many commands, or they keep failing and you're rerunning them again, it's handy to add this flag to keep a PR clean. | ||
|
||
### Adding new Commands | ||
Feel free to add new commands to the workflow, however **_note_** that triggered workflows will use the actions from `main` (default) branch, meaning they will take effect only after the PR with new changes/command is merged. | ||
If you want to test the new command, it's better to test in your fork and local-to-fork PRs, where you control the default branch. |