Skip to content

Commit

Permalink
Migrated commands to github actions (#4701)
Browse files Browse the repository at this point in the history
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 <41779041+alvicsam@users.noreply.github.com>
Co-authored-by: Przemek Rzad <przemek@parity.io>
  • Loading branch information
3 people authored Jun 18, 2024
1 parent e172959 commit 6daa939
Show file tree
Hide file tree
Showing 19 changed files with 1,655 additions and 0 deletions.
36 changes: 36 additions & 0 deletions .github/actions/set-up-gh/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: 'install gh'
description: 'Install the gh cli in a debian based distro and switches to the PR branch.'
inputs:
pr-number:
description: "Number of the PR"
required: true
GH_TOKEN:
description: "GitHub token"
required: true
outputs:
branch:
description: 'Branch name for the PR'
value: ${{ steps.branch.outputs.branch }}
runs:
using: "composite"
steps:
- name: Instal gh cli
shell: bash
# Here it would get the script from previous step
run: |
(type -p wget >/dev/null || (apt update && apt-get install wget -y))
mkdir -p -m 755 /etc/apt/keyrings
wget -qO- https://cli.github.com/packages/githubcli-archive-keyring.gpg | tee /etc/apt/keyrings/githubcli-archive-keyring.gpg > /dev/null
chmod go+r /etc/apt/keyrings/githubcli-archive-keyring.gpg
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
apt update
apt install gh -y
git config --global --add safe.directory '*'
- run: gh pr checkout ${{ inputs.pr-number }}
shell: bash
env:
GITHUB_TOKEN: ${{ inputs.GH_TOKEN }}
- name: Export branch name
shell: bash
run: echo "branch=$(git rev-parse --abbrev-ref HEAD)" >> "$GITHUB_OUTPUT"
id: branch
Binary file added .github/command-screnshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
199 changes: 199 additions & 0 deletions .github/commands-readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
# Running commands

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.

## How to run an action

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.

The current available command actions are:

- [Command FMT](https://github.com/paritytech/polkadot-sdk/actions/workflows/command-fmt.yml)
- [Command Update UI](https://github.com/paritytech/polkadot-sdk/actions/workflows/command-update-ui.yml)
- [Command Bench](https://github.com/paritytech/polkadot-sdk/actions/workflows/command-bench.yml)
- [Command Bench All](https://github.com/paritytech/polkadot-sdk/actions/workflows/command-bench-all.yml)
- [Command Bench Overhead](https://github.com/paritytech/polkadot-sdk/actions/workflows/command-bench-overhead.yml)

You need to select the action, and click on the dropdown that says: `Run workflow`. It is located in the upper right.

If this dropdown is not visible, you may not have permission to run the action. Contact IT for help.

![command screenshot](command-screnshot.png)

Each command will have the same two required values, but it could have more.

GitHub's official documentation: [Manually running a workflow](https://docs.github.com/en/actions/using-workflows/manually-running-a-workflow)

### Number of the Pull Request

The number of the pull request. Required so the action can fetch the correct branch and comment if it fails.

## Action configurations

### Bench

Runs `benchmark pallet` or `benchmark overhead` against your PR and commits back updated weights.

Posible combinations based on the `benchmark` dropdown.

- `substrate-pallet`: Pallet Benchmark for Substrate for specific pallet
- Requires `Subcommand` to be `pallet`
- Requires `Runtime` to be `dev`
- Requires field `Pallet` to have an input that applies to `^([a-z_]+)([:]{2}[a-z_]+)?$`
- Requires `Target Directory` to be `substrate`
- `polkadot-pallet`: Pallet Benchmark for Polkadot for specific pallet
- Requires `Subcommand` to be one of the following:
- `pallet`
- `xcm`
- Requires `Runtime` to be one of the following:
- `rococo`
- `westend`
- Requires field `Pallet` to have an input that applies to `^([a-z_]+)([:]{2}[a-z_]+)?$`
- Requires `Target Directory` to be `polkadot`
- `cumulus-assets`: Pallet Benchmark for Cumulus assets
- Requires `Subcommand` to be one of the following:
- `pallet`
- `xcm`
- Requires `Runtime` to be one of the following:
- `asset-hub-westend`
- `asset-hub-rococo`
- Requires field `Pallet` to have an input that applies to `^([a-z_]+)([:]{2}[a-z_]+)?$`
- Requires `Runtime Dir` to be `assets`
- Requires `Target Directory` to be `cumulus`
- `cumulus-collectives`: Pallet Benchmark for Cumulus collectives
- Requires `Subcommand` to be one of the following:
- `pallet`
- `xcm`
- Requires `Runtime` to be `collectives-westend`
- Requires field `Pallet` to have an input that applies to `^([a-z_]+)([:]{2}[a-z_]+)?$`
- Requires `Runtime Dir` to be `collectives`
- Requires `Target Directory` to be `cumulus`
- `cumulus-coretime`: Pallet Benchmark for Cumulus coretime
- Requires `Subcommand` to be one of the following:
- `pallet`
- `xcm`
- Requires `Runtime` to be one of the following:
- `coretime-rococo`
- `coretime-westend`
- Requires field `Pallet` to have an input that applies to `^([a-z_]+)([:]{2}[a-z_]+)?$`
- Requires `Runtime Dir` to be `coretime`
- Requires `Target Directory` to be `cumulus`
- `cumulus-bridge-hubs`: Pallet Benchmark for Cumulus bridge-hubs
- Requires `Subcommand` to be one of the following:
- `pallet`
- `xcm`
- Requires `Runtime` to be one of the following:
- `bridge-hub-rococo`
- `bridge-hub-westend`
- Requires field `Pallet` to have an input that applies to `^([a-z_]+)([:]{2}[a-z_]+)?$`
- Requires `Runtime Dir` to be `bridge-hub`
- Requires `Target Directory` to be `cumulus`
- `cumulus-contracts`: Pallet Benchmark for Cumulus contracts
- Requires `Subcommand` to be one of the following:
- `pallet`
- `xcm`
- Requires `Runtime` to be one `contracts-rococo`
- Requires field `Pallet` to have an input that applies to `^([a-z_]+)([:]{2}[a-z_]+)?$`
- Requires `Runtime Dir` to be `contracts`
- Requires `Target Directory` to be `cumulus`
- `cumulus-glutton`: Pallet Benchmark for Cumulus glutton
- Requires `Subcommand` to be `pallet`
- Requires `Runtime` to be one of the following:
- `glutton-westend`
- `glutton-westend-dev-1300`
- Requires field `Pallet` to have an input that applies to `^([a-z_]+)([:]{2}[a-z_]+)?$`
- Requires `Runtime Dir` to be `glutton`
- Requires `Target Directory` to be `cumulus`
- `cumulus-starters`: Pallet Benchmark for Cumulus starters
- Requires `Subcommand` to be one of the following:
- `pallet`
- `xcm`
- Requires `Runtime` to be one of the following:
- `seedling`
- `shell`
- Requires field `Pallet` to have an input that applies to `^([a-z_]+)([:]{2}[a-z_]+)?$`
- Requires `Runtime Dir` to be `starters`
- Requires `Target Directory` to be `cumulus`
- `cumulus-people`: Pallet Benchmark for Cumulus people
- Requires `Subcommand` to be one of the following:
- `pallet`
- `xcm`
- Requires `Runtime` to be one of the following:
- `people-westend`
- `people-rococo`
- Requires field `Pallet` to have an input that applies to `^([a-z_]+)([:]{2}[a-z_]+)?$`
- Requires `Runtime Dir` to be `people`
- Requires `Target Directory` to be `cumulus`
- `cumulus-testing`: Pallet Benchmark for Cumulus testing
- Requires `Subcommand` to be one of the following:
- `pallet`
- `xcm`
- Requires `Runtime` to be one of the following:
- `penpal`
- `rococo-parachain`
- Requires field `Pallet` to have an input that applies to `^([a-z_]+)([:]{2}[a-z_]+)?$`
- Requires `Runtime Dir` to be `testing`
- Requires `Target Directory` to be `cumulus`

### Bench-all

This is a wrapper to run `bench` for all pallets.

Posible combinations based on the `benchmark` dropdown.

- `pallet`: Benchmark for Substrate/Polkadot/Cumulus/Trappist for specific pallet
- Requires field `Pallet` to have an input that applies to `^([a-z_]+)([:]{2}[a-z_]+)?$`
- `substrate`: Pallet + Overhead + Machine Benchmark for Substrate for all pallets
- Requires `Target Directory` to be `substrate`
- `polkadot`: Pallet + Overhead Benchmark for Polkadot
- Requires `Runtime` to be one of the following:
- `rococo`
- `westend`
- Requires `Target Directory` to be `polkadot`
- `cumulus`: Pallet Benchmark for Cumulus
- Requires `Runtime` to be one of the following:
- `rococo`
- `westend`
- `asset-hub-kusama`
- `asset-hub-polkadot`
- `asset-hub-rococo`
- `asset-hub-westend`
- `bridge-hub-kusama`
- `bridge-hub-polkadot`
- `bridge-hub-rococo`
- `bridge-hub-westend`
- `collectives-polkadot`
- `collectives-westend`
- `coretime-rococo`
- `coretime-westend`
- `contracts-rococo`
- `glutton-kusama`
- `glutton-westend`
- `people-rococo`
- `people-westend`
- Requires `Target Directory` to be `cumulus`

### Bench-overhead

Run benchmarks overhead and commit back results to PR.

Posible combinations based on the `benchmark` dropdown.

- `default`: Runs `benchmark overhead` and commits back to PR the updated `extrinsic_weights.rs` files
- Requires `Runtime` to be one of the following:
- `rococo`
- `westend`
- Requires `Target directory` to be `polkadot`
- `substrate`: Runs `benchmark overhead` and commits back to PR the updated `extrinsic_weights.rs` files
- Requires `Target directory` to be `substrate`
- `cumulus`: Runs `benchmark overhead` and commits back to PR the updated `extrinsic_weights.rs` files
- Requires `Runtime` to be one of the following:
- `asset-hub-rococo`
- `asset-hub-westend`
- Requires `Target directory` to be `cumulus`

## How to modify an action

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.

This will use a file from a specified branch.
97 changes: 97 additions & 0 deletions .github/workflows/command-bench-all.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
name: Command Bench All

on:
workflow_dispatch:
inputs:
pr:
description: Number of the Pull Request
required: true
benchmark:
description: Pallet benchmark
type: choice
required: true
options:
- pallet
- substrate
- polkadot
- cumulus
pallet:
description: Pallet
required: false
type: string
default: pallet_name
target_dir:
description: Target directory
type: choice
options:
- substrate
- polkadot
- cumulus
runtime:
description: Runtime
type: choice
options:
- rococo
- westend
- asset-hub-kusama
- asset-hub-polkadot
- asset-hub-rococo
- asset-hub-westend
- bridge-hub-kusama
- bridge-hub-polkadot
- bridge-hub-rococo
- bridge-hub-westend
- collectives-polkadot
- collectives-westend
- coretime-rococo
- coretime-westend
- contracts-rococo
- glutton-kusama
- glutton-westend
- people-rococo
- people-westend


jobs:
set-image:
runs-on: ubuntu-latest
outputs:
IMAGE: ${{ steps.set_image.outputs.IMAGE }}
steps:
- name: Checkout
uses: actions/checkout@v4
- id: set_image
run: cat .github/env >> $GITHUB_OUTPUT
cmd-bench-all:
needs: [set-image]
runs-on: arc-runners-polkadot-sdk-benchmark
container:
image: ${{ needs.set-image.outputs.IMAGE }}
steps:
- name: Download repo
uses: actions/checkout@v4
- name: Install gh cli
id: gh
uses: ./.github/actions/set-up-gh
with:
pr-number: ${{ inputs.pr }}
GH_TOKEN: ${{ github.token }}
- name: Run bench all
run: |
"./scripts/bench-all.sh" "${{ inputs.benchmark }}" --runtime "${{ inputs.runtime }}" --pallet "${{ inputs.pallet }}" --target_dir "${{ inputs.target_dir }}"
- name: Report failure
if: ${{ failure() }}
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>."
env:
RUN: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
GH_TOKEN: ${{ github.token }}
- run: git pull --rebase
- uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: cmd-action - ${{ github.workflow }}
branch: ${{ steps.gh.outputs.branch }}
- name: Report succeed
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>."
env:
RUN: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
GH_TOKEN: ${{ github.token }}
Loading

0 comments on commit 6daa939

Please sign in to comment.