From 607c4f41066883aab5f8cc470ebfac31ff7dc478 Mon Sep 17 00:00:00 2001 From: StackOverflowExcept1on <109800286+StackOverflowExcept1on@users.noreply.github.com> Date: Wed, 20 Sep 2023 14:14:31 +0300 Subject: [PATCH] ci: add new functions to benchmark workflow (#3253) --- .github/workflows/benchmarks.yml | 31 +++++++++++---- .github/workflows/comparison-table.yml | 46 ++++++++++++++++++++++ .github/workflows/time-consuming-tests.yml | 2 +- scripts/weight-diff.sh | 17 +++++--- utils/weight-diff/src/main.rs | 6 +-- 5 files changed, 84 insertions(+), 18 deletions(-) create mode 100644 .github/workflows/comparison-table.yml diff --git a/.github/workflows/benchmarks.yml b/.github/workflows/benchmarks.yml index cdb98420dac..8ec90626b45 100644 --- a/.github/workflows/benchmarks.yml +++ b/.github/workflows/benchmarks.yml @@ -3,10 +3,15 @@ name: Benchmarks on: workflow_dispatch: inputs: - create_pr: - description: Whether to create a pull request after the benchmarks are completed - required: false - type: boolean + change-type: + description: How should changes be made after the benchmarks are completed? + required: true + default: ignore + type: choice + options: + - ignore + - commit + - pull_request env: CARGO_TERM_COLOR: always @@ -15,6 +20,9 @@ env: jobs: benchmarks: runs-on: bench + permissions: + contents: write + pull-requests: write env: RUSTUP_HOME: /tmp/rustup_home steps: @@ -65,11 +73,18 @@ jobs: run: | echo "::notice::You can download the artifacts and use script \`./scripts/unpack-weights.sh\` to apply the changes to your branch" - - name: Create Pull Request - if: ${{ inputs.create_pr }} + - name: Create commit + if: ${{ inputs.change-type == 'commit' }} + uses: stefanzweifel/git-auto-commit-action@v4 + with: + commit_message: >- + chore(runtime): update weights + file_pattern: "pallets/gear/src/ runtime/gear/src/weights/ runtime/vara/src/weights/" + + - name: Create pull Request + if: ${{ inputs.change-type == 'pull_request' }} uses: peter-evans/create-pull-request@v5 with: - token: ${{ secrets.GH_TOKEN_FOR_PR }} add-paths: | pallets/gear/src/ runtime/gear/src/weights/ @@ -78,7 +93,7 @@ jobs: branch: weights/patch branch-suffix: short-commit-hash title: >- - chore: update weights + chore(runtime): update weights body: | `run_all_benchmarks.sh` script is applied to update weights (branch: `${{ github.ref_name }}`, commit ${{ github.sha }}) **Note:** If CI fails, try manually updating the heuristic tests: `runtime/{gear, vara}/src/tests.rs` diff --git a/.github/workflows/comparison-table.yml b/.github/workflows/comparison-table.yml new file mode 100644 index 00000000000..17f39581145 --- /dev/null +++ b/.github/workflows/comparison-table.yml @@ -0,0 +1,46 @@ +name: Comparison table + +on: + workflow_dispatch: + inputs: + runtime: + description: For which runtime generate comparison table? + required: true + type: choice + options: + - gear + - vara + +env: + CARGO_TERM_COLOR: always + TERM: xterm-256color + +jobs: + comparison-table: + runs-on: [kuberunner] + env: + RUSTUP_HOME: /tmp/rustup_home + steps: + - name: "ACTIONS: Checkout & fetch all history" + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: "Install: Set cargo path" + run: echo "/tmp/cargo/bin" >> $GITHUB_PATH + + - name: "Install: Rust toolchain" + uses: dsherret/rust-toolchain-file@v1 + + - name: "Build: Init" + run: ./scripts/gear.sh init cargo + + - name: "Generate comparison tables (${{ inputs.runtime }})" + run: | + ./scripts/weight-diff.sh master $(git branch --show-current) ${{ inputs.runtime }} --display-units > ${{ inputs.runtime }}-tables.txt + + - name: "ACTIONS: Upload artifact with comparison tables (${{ inputs.runtime }})" + uses: actions/upload-artifact@v3 + with: + name: ${{ inputs.runtime }}-tables + path: ${{ inputs.runtime }}-tables.txt diff --git a/.github/workflows/time-consuming-tests.yml b/.github/workflows/time-consuming-tests.yml index 126744ebcfa..9c75a58480c 100644 --- a/.github/workflows/time-consuming-tests.yml +++ b/.github/workflows/time-consuming-tests.yml @@ -24,7 +24,7 @@ jobs: - name: "Install: Rust toolchain" uses: dsherret/rust-toolchain-file@v1 - - name: "Buid: Init" + - name: "Build: Init" run: ./scripts/gear.sh init cargo - name: "Build: Node" diff --git a/scripts/weight-diff.sh b/scripts/weight-diff.sh index ae52c2c55c3..11a1baed4db 100755 --- a/scripts/weight-diff.sh +++ b/scripts/weight-diff.sh @@ -39,18 +39,23 @@ flag=$4 dump_path="weight-dumps" mkdir -p "$dump_path" -set -x +if [ -z $CI ] ; then + set -x + CARGO_FLAGS="" +else + CARGO_FLAGS="--quiet" +fi git checkout "$branch1" dump_path1="$dump_path/${branch1//\//-}.json" -cargo run --package gear-weight-diff --release -- dump "$dump_path1" --label "$branch1" +cargo run $CARGO_FLAGS --package gear-weight-diff --release -- dump "$dump_path1" --label "$branch1" git checkout "$branch2" dump_path2="$dump_path/${branch2//\//-}.json" -cargo run --package gear-weight-diff --release -- dump "$dump_path2" --label "$branch2" +cargo run $CARGO_FLAGS --package gear-weight-diff --release -- dump "$dump_path2" --label "$branch2" git checkout "$current_branch" -cargo run --package gear-weight-diff --release -- diff "$dump_path1" "$dump_path2" "$runtime" "instruction" $flag -cargo run --package gear-weight-diff --release -- diff "$dump_path1" "$dump_path2" "$runtime" "host-fn" $flag -cargo run --package gear-weight-diff --release -- diff "$dump_path1" "$dump_path2" "$runtime" "memory" $flag +cargo run $CARGO_FLAGS --package gear-weight-diff --release -- diff "$dump_path1" "$dump_path2" "$runtime" "instruction" $flag +cargo run $CARGO_FLAGS --package gear-weight-diff --release -- diff "$dump_path1" "$dump_path2" "$runtime" "host-fn" $flag +cargo run $CARGO_FLAGS --package gear-weight-diff --release -- diff "$dump_path1" "$dump_path2" "$runtime" "memory" $flag diff --git a/utils/weight-diff/src/main.rs b/utils/weight-diff/src/main.rs index f99233311d9..a40f85b1090 100644 --- a/utils/weight-diff/src/main.rs +++ b/utils/weight-diff/src/main.rs @@ -66,13 +66,13 @@ enum Commands { }, } -#[derive(Debug, Clone, ValueEnum)] +#[derive(Debug, Copy, Clone, ValueEnum)] enum Runtime { Gear, Vara, } -#[derive(Debug, Clone, ValueEnum)] +#[derive(Debug, Copy, Clone, ValueEnum)] enum WeightsKind { Instruction, HostFn, @@ -247,7 +247,7 @@ fn main() { } } - println!("Comparison table for {runtime:?} runtime"); + println!("Comparison table for {runtime:?} runtime for {kind:?}"); println!(); let mut builder = Builder::default();