-
Notifications
You must be signed in to change notification settings - Fork 839
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
210 additions
and
0 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
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,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: ubuntu-latest | ||
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 | ||
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 }} |
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,16 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -eu -o pipefail | ||
shopt -s inherit_errexit | ||
shopt -s globstar | ||
|
||
. "$(realpath "$(dirname "${BASH_SOURCE[0]}")/command-utils.sh")" | ||
|
||
get_arg optional --pallet "$@" | ||
PALLET="${out:-""}" | ||
|
||
if [[ ! -z "$PALLET" ]]; then | ||
. "$(dirname "${BASH_SOURCE[0]}")/lib/bench-all-pallet.sh" "$@" | ||
else | ||
. "$(dirname "${BASH_SOURCE[0]}")/bench.sh" --subcommand=all "$@" | ||
fi |
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,96 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -eu -o pipefail | ||
shopt -s inherit_errexit | ||
shopt -s globstar | ||
|
||
. "$(dirname "${BASH_SOURCE[0]}")/../command-utils.sh" | ||
|
||
get_arg required --pallet "$@" | ||
PALLET="${out:-""}" | ||
|
||
REPO_NAME="$(basename "$PWD")" | ||
BASE_COMMAND="$(dirname "${BASH_SOURCE[0]}")/../../bench/bench.sh --noexit=true --subcommand=pallet" | ||
|
||
WEIGHT_FILE_PATHS=( $(find . -type f -name "${PALLET}.rs" -path "**/weights/*" | sed 's|^\./||g') ) | ||
|
||
# convert pallet_ranked_collective to ranked-collective | ||
CLEAN_PALLET=$(echo $PALLET | sed 's/pallet_//g' | sed 's/_/-/g') | ||
|
||
# add substrate pallet weights to a list | ||
SUBSTRATE_PALLET_PATH=$(ls substrate/frame/$CLEAN_PALLET/src/weights.rs || :) | ||
if [ ! -z "${SUBSTRATE_PALLET_PATH}" ]; then | ||
WEIGHT_FILE_PATHS+=("$SUBSTRATE_PALLET_PATH") | ||
fi | ||
|
||
# add trappist pallet weights to a list | ||
TRAPPIST_PALLET_PATH=$(ls pallet/$CLEAN_PALLET/src/weights.rs || :) | ||
if [ ! -z "${TRAPPIST_PALLET_PATH}" ]; then | ||
WEIGHT_FILE_PATHS+=("$TRAPPIST_PALLET_PATH") | ||
fi | ||
|
||
COMMANDS=() | ||
|
||
if [ "${#WEIGHT_FILE_PATHS[@]}" -eq 0 ]; then | ||
echo "No weights files found for pallet: $PALLET" | ||
exit 1 | ||
else | ||
echo "Found weights files for pallet: $PALLET" | ||
fi | ||
|
||
for f in ${WEIGHT_FILE_PATHS[@]}; do | ||
echo "- $f" | ||
# f examples: | ||
# cumulus/parachains/runtimes/assets/asset-hub-rococo/src/weights/pallet_balances.rs | ||
# polkadot/runtime/rococo/src/weights/pallet_balances.rs | ||
# runtime/trappist/src/weights/pallet_assets.rs | ||
TARGET_DIR=$(echo $f | cut -d'/' -f 1) | ||
|
||
if [ "$REPO_NAME" == "polkadot-sdk" ]; then | ||
case $TARGET_DIR in | ||
cumulus) | ||
TYPE=$(echo $f | cut -d'/' -f 2) | ||
# Example: cumulus/parachains/runtimes/assets/asset-hub-rococo/src/weights/pallet_balances.rs | ||
if [ "$TYPE" == "parachains" ]; then | ||
RUNTIME=$(echo $f | cut -d'/' -f 5) | ||
RUNTIME_DIR=$(echo $f | cut -d'/' -f 4) | ||
COMMANDS+=("$BASE_COMMAND --runtime=$RUNTIME --runtime_dir=$RUNTIME_DIR --target_dir=$TARGET_DIR --pallet=$PALLET") | ||
fi | ||
;; | ||
polkadot) | ||
# Example: polkadot/runtime/rococo/src/weights/pallet_balances.rs | ||
RUNTIME=$(echo $f | cut -d'/' -f 3) | ||
COMMANDS+=("$BASE_COMMAND --runtime=$RUNTIME --target_dir=$TARGET_DIR --pallet=$PALLET") | ||
;; | ||
substrate) | ||
# Example: substrate/frame/contracts/src/weights.rs | ||
COMMANDS+=("$BASE_COMMAND --target_dir=$TARGET_DIR --runtime=dev --pallet=$PALLET") | ||
;; | ||
*) | ||
echo "Unknown dir: $TARGET_DIR" | ||
exit 1 | ||
;; | ||
esac | ||
fi | ||
|
||
if [ "$REPO_NAME" == "trappist" ]; then | ||
case $TARGET_DIR in | ||
runtime) | ||
TYPE=$(echo $f | cut -d'/' -f 2) | ||
if [ "$TYPE" == "trappist" || "$TYPE" == "stout" ]; then | ||
# Example: runtime/trappist/src/weights/pallet_assets.rs | ||
COMMANDS+=("$BASE_COMMAND --target_dir=trappist --runtime=$TYPE --pallet=$PALLET") | ||
fi | ||
;; | ||
*) | ||
echo "Unknown dir: $TARGET_DIR" | ||
exit 1 | ||
;; | ||
esac | ||
fi | ||
done | ||
|
||
for cmd in "${COMMANDS[@]}"; do | ||
echo "Running command: $cmd" | ||
. $cmd | ||
done |