Skip to content

Commit 6daa939

Browse files
Bullrichalvicsamrzadp
authored
Migrated commands to github actions (#4701)
Migrated commands individually to work as GitHub actions with a [`workflow_dispatch`](https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#workflow_dispatch) event. This will not disable the command-bot yet, but it's the first step before disabling it. ### Commands migrated - [x] bench-all - [x] bench-overhead - [x] bench - [x] fmt - [x] update-ui Also created an action that will inform users about the new documentation when they comment `bot`. ### Created documentation Created a detailed documentation on how to use this action. Found the documentation [here](https://github.com/paritytech/polkadot-sdk/blob/bullrich/cmd-action/.github/commands-readme.md). --------- Co-authored-by: Alexander Samusev <[email protected]> Co-authored-by: Przemek Rzad <[email protected]>
1 parent e172959 commit 6daa939

19 files changed

+1655
-0
lines changed

.github/actions/set-up-gh/action.yml

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: 'install gh'
2+
description: 'Install the gh cli in a debian based distro and switches to the PR branch.'
3+
inputs:
4+
pr-number:
5+
description: "Number of the PR"
6+
required: true
7+
GH_TOKEN:
8+
description: "GitHub token"
9+
required: true
10+
outputs:
11+
branch:
12+
description: 'Branch name for the PR'
13+
value: ${{ steps.branch.outputs.branch }}
14+
runs:
15+
using: "composite"
16+
steps:
17+
- name: Instal gh cli
18+
shell: bash
19+
# Here it would get the script from previous step
20+
run: |
21+
(type -p wget >/dev/null || (apt update && apt-get install wget -y))
22+
mkdir -p -m 755 /etc/apt/keyrings
23+
wget -qO- https://cli.github.com/packages/githubcli-archive-keyring.gpg | tee /etc/apt/keyrings/githubcli-archive-keyring.gpg > /dev/null
24+
chmod go+r /etc/apt/keyrings/githubcli-archive-keyring.gpg
25+
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | tee /etc/apt/sources.list.d/github-cli.list > /dev/null
26+
apt update
27+
apt install gh -y
28+
git config --global --add safe.directory '*'
29+
- run: gh pr checkout ${{ inputs.pr-number }}
30+
shell: bash
31+
env:
32+
GITHUB_TOKEN: ${{ inputs.GH_TOKEN }}
33+
- name: Export branch name
34+
shell: bash
35+
run: echo "branch=$(git rev-parse --abbrev-ref HEAD)" >> "$GITHUB_OUTPUT"
36+
id: branch

.github/command-screnshot.png

30.8 KB
Loading

.github/commands-readme.md

+199
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,199 @@
1+
# Running commands
2+
3+
Command bot has been migrated, it is no longer a comment parser and now it is a GitHub action that works as a [`workflow_dispatch`](https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#workflow_dispatch) event.
4+
5+
## How to run an action
6+
7+
To run an action, you need to go to the [_actions tab_](https://github.com/paritytech/polkadot-sdk/actions) and pick the one you desire to run.
8+
9+
The current available command actions are:
10+
11+
- [Command FMT](https://github.com/paritytech/polkadot-sdk/actions/workflows/command-fmt.yml)
12+
- [Command Update UI](https://github.com/paritytech/polkadot-sdk/actions/workflows/command-update-ui.yml)
13+
- [Command Bench](https://github.com/paritytech/polkadot-sdk/actions/workflows/command-bench.yml)
14+
- [Command Bench All](https://github.com/paritytech/polkadot-sdk/actions/workflows/command-bench-all.yml)
15+
- [Command Bench Overhead](https://github.com/paritytech/polkadot-sdk/actions/workflows/command-bench-overhead.yml)
16+
17+
You need to select the action, and click on the dropdown that says: `Run workflow`. It is located in the upper right.
18+
19+
If this dropdown is not visible, you may not have permission to run the action. Contact IT for help.
20+
21+
![command screenshot](command-screnshot.png)
22+
23+
Each command will have the same two required values, but it could have more.
24+
25+
GitHub's official documentation: [Manually running a workflow](https://docs.github.com/en/actions/using-workflows/manually-running-a-workflow)
26+
27+
### Number of the Pull Request
28+
29+
The number of the pull request. Required so the action can fetch the correct branch and comment if it fails.
30+
31+
## Action configurations
32+
33+
### Bench
34+
35+
Runs `benchmark pallet` or `benchmark overhead` against your PR and commits back updated weights.
36+
37+
Posible combinations based on the `benchmark` dropdown.
38+
39+
- `substrate-pallet`: Pallet Benchmark for Substrate for specific pallet
40+
- Requires `Subcommand` to be `pallet`
41+
- Requires `Runtime` to be `dev`
42+
- Requires field `Pallet` to have an input that applies to `^([a-z_]+)([:]{2}[a-z_]+)?$`
43+
- Requires `Target Directory` to be `substrate`
44+
- `polkadot-pallet`: Pallet Benchmark for Polkadot for specific pallet
45+
- Requires `Subcommand` to be one of the following:
46+
- `pallet`
47+
- `xcm`
48+
- Requires `Runtime` to be one of the following:
49+
- `rococo`
50+
- `westend`
51+
- Requires field `Pallet` to have an input that applies to `^([a-z_]+)([:]{2}[a-z_]+)?$`
52+
- Requires `Target Directory` to be `polkadot`
53+
- `cumulus-assets`: Pallet Benchmark for Cumulus assets
54+
- Requires `Subcommand` to be one of the following:
55+
- `pallet`
56+
- `xcm`
57+
- Requires `Runtime` to be one of the following:
58+
- `asset-hub-westend`
59+
- `asset-hub-rococo`
60+
- Requires field `Pallet` to have an input that applies to `^([a-z_]+)([:]{2}[a-z_]+)?$`
61+
- Requires `Runtime Dir` to be `assets`
62+
- Requires `Target Directory` to be `cumulus`
63+
- `cumulus-collectives`: Pallet Benchmark for Cumulus collectives
64+
- Requires `Subcommand` to be one of the following:
65+
- `pallet`
66+
- `xcm`
67+
- Requires `Runtime` to be `collectives-westend`
68+
- Requires field `Pallet` to have an input that applies to `^([a-z_]+)([:]{2}[a-z_]+)?$`
69+
- Requires `Runtime Dir` to be `collectives`
70+
- Requires `Target Directory` to be `cumulus`
71+
- `cumulus-coretime`: Pallet Benchmark for Cumulus coretime
72+
- Requires `Subcommand` to be one of the following:
73+
- `pallet`
74+
- `xcm`
75+
- Requires `Runtime` to be one of the following:
76+
- `coretime-rococo`
77+
- `coretime-westend`
78+
- Requires field `Pallet` to have an input that applies to `^([a-z_]+)([:]{2}[a-z_]+)?$`
79+
- Requires `Runtime Dir` to be `coretime`
80+
- Requires `Target Directory` to be `cumulus`
81+
- `cumulus-bridge-hubs`: Pallet Benchmark for Cumulus bridge-hubs
82+
- Requires `Subcommand` to be one of the following:
83+
- `pallet`
84+
- `xcm`
85+
- Requires `Runtime` to be one of the following:
86+
- `bridge-hub-rococo`
87+
- `bridge-hub-westend`
88+
- Requires field `Pallet` to have an input that applies to `^([a-z_]+)([:]{2}[a-z_]+)?$`
89+
- Requires `Runtime Dir` to be `bridge-hub`
90+
- Requires `Target Directory` to be `cumulus`
91+
- `cumulus-contracts`: Pallet Benchmark for Cumulus contracts
92+
- Requires `Subcommand` to be one of the following:
93+
- `pallet`
94+
- `xcm`
95+
- Requires `Runtime` to be one `contracts-rococo`
96+
- Requires field `Pallet` to have an input that applies to `^([a-z_]+)([:]{2}[a-z_]+)?$`
97+
- Requires `Runtime Dir` to be `contracts`
98+
- Requires `Target Directory` to be `cumulus`
99+
- `cumulus-glutton`: Pallet Benchmark for Cumulus glutton
100+
- Requires `Subcommand` to be `pallet`
101+
- Requires `Runtime` to be one of the following:
102+
- `glutton-westend`
103+
- `glutton-westend-dev-1300`
104+
- Requires field `Pallet` to have an input that applies to `^([a-z_]+)([:]{2}[a-z_]+)?$`
105+
- Requires `Runtime Dir` to be `glutton`
106+
- Requires `Target Directory` to be `cumulus`
107+
- `cumulus-starters`: Pallet Benchmark for Cumulus starters
108+
- Requires `Subcommand` to be one of the following:
109+
- `pallet`
110+
- `xcm`
111+
- Requires `Runtime` to be one of the following:
112+
- `seedling`
113+
- `shell`
114+
- Requires field `Pallet` to have an input that applies to `^([a-z_]+)([:]{2}[a-z_]+)?$`
115+
- Requires `Runtime Dir` to be `starters`
116+
- Requires `Target Directory` to be `cumulus`
117+
- `cumulus-people`: Pallet Benchmark for Cumulus people
118+
- Requires `Subcommand` to be one of the following:
119+
- `pallet`
120+
- `xcm`
121+
- Requires `Runtime` to be one of the following:
122+
- `people-westend`
123+
- `people-rococo`
124+
- Requires field `Pallet` to have an input that applies to `^([a-z_]+)([:]{2}[a-z_]+)?$`
125+
- Requires `Runtime Dir` to be `people`
126+
- Requires `Target Directory` to be `cumulus`
127+
- `cumulus-testing`: Pallet Benchmark for Cumulus testing
128+
- Requires `Subcommand` to be one of the following:
129+
- `pallet`
130+
- `xcm`
131+
- Requires `Runtime` to be one of the following:
132+
- `penpal`
133+
- `rococo-parachain`
134+
- Requires field `Pallet` to have an input that applies to `^([a-z_]+)([:]{2}[a-z_]+)?$`
135+
- Requires `Runtime Dir` to be `testing`
136+
- Requires `Target Directory` to be `cumulus`
137+
138+
### Bench-all
139+
140+
This is a wrapper to run `bench` for all pallets.
141+
142+
Posible combinations based on the `benchmark` dropdown.
143+
144+
- `pallet`: Benchmark for Substrate/Polkadot/Cumulus/Trappist for specific pallet
145+
- Requires field `Pallet` to have an input that applies to `^([a-z_]+)([:]{2}[a-z_]+)?$`
146+
- `substrate`: Pallet + Overhead + Machine Benchmark for Substrate for all pallets
147+
- Requires `Target Directory` to be `substrate`
148+
- `polkadot`: Pallet + Overhead Benchmark for Polkadot
149+
- Requires `Runtime` to be one of the following:
150+
- `rococo`
151+
- `westend`
152+
- Requires `Target Directory` to be `polkadot`
153+
- `cumulus`: Pallet Benchmark for Cumulus
154+
- Requires `Runtime` to be one of the following:
155+
- `rococo`
156+
- `westend`
157+
- `asset-hub-kusama`
158+
- `asset-hub-polkadot`
159+
- `asset-hub-rococo`
160+
- `asset-hub-westend`
161+
- `bridge-hub-kusama`
162+
- `bridge-hub-polkadot`
163+
- `bridge-hub-rococo`
164+
- `bridge-hub-westend`
165+
- `collectives-polkadot`
166+
- `collectives-westend`
167+
- `coretime-rococo`
168+
- `coretime-westend`
169+
- `contracts-rococo`
170+
- `glutton-kusama`
171+
- `glutton-westend`
172+
- `people-rococo`
173+
- `people-westend`
174+
- Requires `Target Directory` to be `cumulus`
175+
176+
### Bench-overhead
177+
178+
Run benchmarks overhead and commit back results to PR.
179+
180+
Posible combinations based on the `benchmark` dropdown.
181+
182+
- `default`: Runs `benchmark overhead` and commits back to PR the updated `extrinsic_weights.rs` files
183+
- Requires `Runtime` to be one of the following:
184+
- `rococo`
185+
- `westend`
186+
- Requires `Target directory` to be `polkadot`
187+
- `substrate`: Runs `benchmark overhead` and commits back to PR the updated `extrinsic_weights.rs` files
188+
- Requires `Target directory` to be `substrate`
189+
- `cumulus`: Runs `benchmark overhead` and commits back to PR the updated `extrinsic_weights.rs` files
190+
- Requires `Runtime` to be one of the following:
191+
- `asset-hub-rococo`
192+
- `asset-hub-westend`
193+
- Requires `Target directory` to be `cumulus`
194+
195+
## How to modify an action
196+
197+
If you want to modify an action and test it, you can do by simply pushing your changes and then selecting your branch in the `Use worflow from` option.
198+
199+
This will use a file from a specified branch.
+97
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
name: Command Bench All
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
pr:
7+
description: Number of the Pull Request
8+
required: true
9+
benchmark:
10+
description: Pallet benchmark
11+
type: choice
12+
required: true
13+
options:
14+
- pallet
15+
- substrate
16+
- polkadot
17+
- cumulus
18+
pallet:
19+
description: Pallet
20+
required: false
21+
type: string
22+
default: pallet_name
23+
target_dir:
24+
description: Target directory
25+
type: choice
26+
options:
27+
- substrate
28+
- polkadot
29+
- cumulus
30+
runtime:
31+
description: Runtime
32+
type: choice
33+
options:
34+
- rococo
35+
- westend
36+
- asset-hub-kusama
37+
- asset-hub-polkadot
38+
- asset-hub-rococo
39+
- asset-hub-westend
40+
- bridge-hub-kusama
41+
- bridge-hub-polkadot
42+
- bridge-hub-rococo
43+
- bridge-hub-westend
44+
- collectives-polkadot
45+
- collectives-westend
46+
- coretime-rococo
47+
- coretime-westend
48+
- contracts-rococo
49+
- glutton-kusama
50+
- glutton-westend
51+
- people-rococo
52+
- people-westend
53+
54+
55+
jobs:
56+
set-image:
57+
runs-on: ubuntu-latest
58+
outputs:
59+
IMAGE: ${{ steps.set_image.outputs.IMAGE }}
60+
steps:
61+
- name: Checkout
62+
uses: actions/checkout@v4
63+
- id: set_image
64+
run: cat .github/env >> $GITHUB_OUTPUT
65+
cmd-bench-all:
66+
needs: [set-image]
67+
runs-on: arc-runners-polkadot-sdk-benchmark
68+
container:
69+
image: ${{ needs.set-image.outputs.IMAGE }}
70+
steps:
71+
- name: Download repo
72+
uses: actions/checkout@v4
73+
- name: Install gh cli
74+
id: gh
75+
uses: ./.github/actions/set-up-gh
76+
with:
77+
pr-number: ${{ inputs.pr }}
78+
GH_TOKEN: ${{ github.token }}
79+
- name: Run bench all
80+
run: |
81+
"./scripts/bench-all.sh" "${{ inputs.benchmark }}" --runtime "${{ inputs.runtime }}" --pallet "${{ inputs.pallet }}" --target_dir "${{ inputs.target_dir }}"
82+
- name: Report failure
83+
if: ${{ failure() }}
84+
run: gh pr comment ${{ inputs.pr }} --body "<h2>Command failed ❌</h2> Run by @${{ github.actor }} for <code>${{ github.workflow }}</code> failed. See logs <a href=\"$RUN\">here</a>."
85+
env:
86+
RUN: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
87+
GH_TOKEN: ${{ github.token }}
88+
- run: git pull --rebase
89+
- uses: stefanzweifel/git-auto-commit-action@v5
90+
with:
91+
commit_message: cmd-action - ${{ github.workflow }}
92+
branch: ${{ steps.gh.outputs.branch }}
93+
- name: Report succeed
94+
run: gh pr comment ${{ inputs.pr }} --body "<h2>Action completed 🎉🎉</h2> Run by @${{ github.actor }} for <code>${{ github.workflow }}</code> completed 🎉. See logs <a href=\"$RUN\">here</a>."
95+
env:
96+
RUN: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
97+
GH_TOKEN: ${{ github.token }}

0 commit comments

Comments
 (0)