Skip to content

Commit

Permalink
[skip ci] cmd.yml
Browse files Browse the repository at this point in the history
remove rust installation + add forklift
  • Loading branch information
mordamax committed Aug 21, 2024
1 parent 85ddf4c commit 1b76e07
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 52 deletions.
14 changes: 7 additions & 7 deletions .github/scripts/cmd/cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"which triggered /cmd"},
}

parser = argparse.ArgumentParser(prog="/cmd ", description='A command runner for polkadot runtimes repo', add_help=False)
parser = argparse.ArgumentParser(prog="/cmd ", description='A command runner for polkadot-sdk repo', add_help=False)
parser.add_argument('--help', action=_HelpAction, help='help for help if you need some help') # help for help

subparsers = parser.add_subparsers(help='a command to run', dest='command')
Expand All @@ -42,14 +42,14 @@
> --quiet makes it to output nothing to PR but reactions
%(prog)s --pallet pallet_balances pallet_xcm_benchmarks::generic --quiet
> runs bench for all pallets for westend runtime and continues even if some benchmarks fail
> runs bench for all pallets for polkadot runtime and continues even if some benchmarks fail
%(prog)s --runtime polkadot --continue-on-fail
%(prog)s --runtime westend --continue-on-fail
> does not output anything and cleans up the previous bot's & author command triggering comments in PR
%(prog)s --runtime polkadot kusama --pallet pallet_balances pallet_multisig --quiet --clean
%(prog)s --runtime westend rococo --pallet pallet_balances pallet_multisig --quiet --clean
'''

Expand Down Expand Up @@ -89,7 +89,7 @@

# loop over remaining runtimes to collect available pallets
for runtime in runtimesMatrix.values():
os.system(f"cargo build -p {runtime['package']} --profile {profile} --features runtime-benchmarks")
os.system(f"forklift cargo build -p {runtime['package']} --profile {profile} --features runtime-benchmarks")
print(f'-- listing pallets for benchmark for {runtime["name"]}')
wasm_file = f"target/{profile}/wbuild/{runtime['package']}/{runtime['package'].replace('-', '_')}.wasm"
output = os.popen(
Expand Down
108 changes: 64 additions & 44 deletions .github/workflows/cmd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,55 @@ permissions: # allow the action to comment on the PR

jobs:
is-org-member:
if: startsWith(github.event.comment.body, '/cmd')
runs-on: ubuntu-latest
outputs:
member: ${{ steps.is-member.outputs.is-member }}
member: ${{ steps.is-member.outputs.result }}
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Generate token
id: generate_token
uses: tibdex/[email protected]
with:
app_id: ${{ secrets.CMD_BOT_APP_ID }}
private_key: ${{ secrets.CMD_BOT_APP_KEY }}

- name: Check if user is a member of the organization
id: is-member
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
github-token: ${{ steps.generate_token.outputs.token }}
result-encoding: string
script: |
const membership = await github.orgs.checkMembershipForUser({
org: context.repo.owner,
username: context.actor
})
return membership.data.state === 'active'
const fs = require("fs");
try {
const org = '${{ github.event.repository.owner.login }}';
const username = '${{ github.event.comment.user.login }}';
const membership = await github.rest.orgs.checkMembershipForUser({
org: org,
username: username
});
console.log(membership, membership.status, membership.status === 204);
if (membership.status === 204) {
return 'true';
} else {
console.log(membership);
fs.appendFileSync(process.env["GITHUB_STEP_SUMMARY"], `${membership.data && membership.data.message || 'Unknown error happened, please check logs'}`);
}
} catch (error) {
console.log(error)
}
return 'false';
reject-non-fellows:
reject-non-members:
needs: is-org-member
if: ${{ startsWith(github.event.comment.body, '/cmd') && !contains(needs.fellows.outputs.github-handles, github.event.sender.login) }}
if: ${{ startsWith(github.event.comment.body, '/cmd') && needs.is-org-member.outputs.member != 'true' }}
runs-on: ubuntu-latest
steps:
- name: Add reaction to rejected comment
Expand All @@ -57,12 +84,12 @@ jobs:
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `Sorry, only fellows can run commands.`
body: `Sorry, only ${{ github.event.repository.owner.login }} members can run commands.`
})
acknowledge:
needs: fellows
if: ${{ startsWith(github.event.comment.body, '/cmd') && contains(needs.fellows.outputs.github-handles, github.event.sender.login) }}
needs: is-org-member
if: ${{ startsWith(github.event.comment.body, '/cmd') && needs.is-org-member.outputs.member == 'true' }}
runs-on: ubuntu-latest
steps:
- name: Add reaction to triggered comment
Expand All @@ -85,7 +112,7 @@ jobs:
uses: actions/checkout@v4

- name: Clean previous comments
if: ${{ startsWith(github.event.comment.body, '/cmd') && contains(github.event.comment.body, '--clean') && contains(needs.fellows.outputs.github-handles, github.event.sender.login) }}
if: ${{ startsWith(github.event.comment.body, '/cmd') && contains(github.event.comment.body, '--clean') && needs.is-org-member.outputs.member == 'true' }}
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -100,7 +127,13 @@ jobs:
if (
${{ github.event.comment.id }} !== comment.id &&
(
((comment.body.startsWith('Command') || comment.body.startsWith('<details><summary>Command')) && comment.user.type === 'Bot') ||
(
(
comment.body.startsWith('Command') ||
comment.body.startsWith('<details><summary>Command') ||
comment.body.startsWith('Sorry, only ')
) && comment.user.type === 'Bot'
) ||
(comment.body.startsWith('/cmd') && comment.user.login === context.actor)
)
) {
Expand All @@ -114,7 +147,7 @@ jobs:
})
help:
needs: [ clean, is-org-member ]
if: ${{ startsWith(github.event.comment.body, '/cmd') && contains(github.event.comment.body, '--help') && contains(needs.fellows.outputs.github-handles, github.event.sender.login) }}
if: ${{ startsWith(github.event.comment.body, '/cmd') && contains(github.event.comment.body, '--help') && needs.is-org-member.outputs.member == 'true' }}
runs-on: ubuntu-latest
steps:
- name: Checkout
Expand Down Expand Up @@ -174,19 +207,26 @@ jobs:
content: '+1'
})
cmd:
set-image:
needs: [ clean, is-org-member ]
if: ${{ startsWith(github.event.comment.body, '/cmd') && !contains(github.event.comment.body, '--help') && needs.is-org-member.outputs.member == 'true' }}
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:
needs: [ set-image ]
env:
JOB_NAME: 'cmd'
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: ${{ startsWith(github.event.comment.body, '/cmd bench') && 'arc-runners-polkadot-sdk-benchmark' || 'ubuntu-latest' }}
runs-on: ${{ startsWith(github.event.comment.body, '/cmd bench') && 'arc-runners-beefy-stg' || 'ubuntu-latest' }} # TODO: change to arc-runners-polkadot-sdk-benchmark
container:
image: ${{ needs.set-image.outputs.IMAGE }}
steps:
- name: Install updates and protobuf-compiler
if: startsWith(github.event.comment.body, '/cmd bench')
run: |
sudo apt update && sudo apt install --assume-yes \
openssl pkg-config g++ make cmake protobuf-compiler curl libssl-dev libclang-dev libudev-dev git jq
- name: Get command
uses: actions-ecosystem/action-regex-match@v2
id: get-pr-comment
Expand Down Expand Up @@ -235,30 +275,10 @@ jobs:
with:
ref: ${{ github.head_ref }}

- name: Set rust version via common env file
run: cat .github/env >> $GITHUB_ENV

- name: Install Rust
uses: dtolnay/rust-toolchain@master
with:
targets: "wasm32-unknown-unknown,x86_64-unknown-linux-musl"
components: "rust-src rustfmt clippy"
toolchain: "nightly-${{env.RUST_NIGHTLY_VERSION}}"

- name: Install dependencies for bench
if: startsWith(steps.get-pr-comment.outputs.group2, 'bench')
run: cargo install subweight frame-omni-bencher --locked

- name: Install dependencies for fmt
if: startsWith(steps.get-pr-comment.outputs.group2, 'fmt')
run: cargo install taplo-cli --version ${{ env.TAPLO_VERSION }}

- name: Setup Cache
if: startsWith(steps.get-pr-comment.outputs.group2, 'bench')
uses: Swatinem/rust-cache@a95ba195448af2da9b00fb742d14ffaaf3c21f43 # v2.7.0
with:
shared-key: "fellowship-cmd"

- name: Run cmd
id: cmd
env:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/runtimes-matrix.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"name": "collectives-westend",
"package": "collectives-westend-runtime",
"path": "cumulus/parachains/runtimes/collectives/collectives-westend",
"uri": "wss://westend-collectives-rpc.polkadot.io:443",
"uri": "wss://westend-collectives-rpc.polkadot.io:443"
},
{
"name": "contracts-rococo",
Expand Down

0 comments on commit 1b76e07

Please sign in to comment.