Skip to content

Commit

Permalink
Merge branch 'master' into pg/bump-uint
Browse files Browse the repository at this point in the history
  • Loading branch information
ordian authored Sep 11, 2024
2 parents a9e3058 + 8f6699b commit d95334c
Show file tree
Hide file tree
Showing 57 changed files with 2,056 additions and 2,063 deletions.
21 changes: 19 additions & 2 deletions .github/scripts/cmd/cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@
import json
import argparse
import _help
import importlib.util

_HelpAction = _help._HelpAction

f = open('.github/workflows/runtimes-matrix.json', 'r')
runtimesMatrix = json.load(f)

print(f'runtimesMatrix: {runtimesMatrix}\n')

runtimeNames = list(map(lambda x: x['name'], runtimesMatrix))

common_args = {
Expand Down Expand Up @@ -69,6 +68,17 @@
for arg, config in common_args.items():
parser_ui.add_argument(arg, **config)

"""
PRDOC
"""
# Import generate-prdoc.py dynamically
spec = importlib.util.spec_from_file_location("generate_prdoc", ".github/scripts/generate-prdoc.py")
generate_prdoc = importlib.util.module_from_spec(spec)
spec.loader.exec_module(generate_prdoc)

parser_prdoc = subparsers.add_parser('prdoc', help='Generates PR documentation')
generate_prdoc.setup_parser(parser_prdoc)

def main():
global args, unknown, runtimesMatrix
args, unknown = parser.parse_known_args()
Expand Down Expand Up @@ -215,6 +225,13 @@ def main():
print('❌ Failed to format code')
sys.exit(1)

elif args.command == 'prdoc':
# Call the main function from ./github/scripts/generate-prdoc.py module
exit_code = generate_prdoc.main(args)
if exit_code != 0 and not args.continue_on_fail:
print('❌ Failed to generate prdoc')
sys.exit(exit_code)

print('🚀 Done')

if __name__ == '__main__':
Expand Down
18 changes: 18 additions & 0 deletions .github/scripts/cmd/test_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,18 @@ def setUp(self):
self.patcher3 = patch('argparse.ArgumentParser.parse_known_args')
self.patcher4 = patch('os.system', return_value=0)
self.patcher5 = patch('os.popen')
self.patcher6 = patch('importlib.util.spec_from_file_location', return_value=MagicMock())
self.patcher7 = patch('importlib.util.module_from_spec', return_value=MagicMock())
self.patcher8 = patch('cmd.generate_prdoc.main', return_value=0)

self.mock_open = self.patcher1.start()
self.mock_json_load = self.patcher2.start()
self.mock_parse_args = self.patcher3.start()
self.mock_system = self.patcher4.start()
self.mock_popen = self.patcher5.start()
self.mock_spec_from_file_location = self.patcher6.start()
self.mock_module_from_spec = self.patcher7.start()
self.mock_generate_prdoc_main = self.patcher8.start()

# Ensure that cmd.py uses the mock_runtimes_matrix
import cmd
Expand All @@ -48,6 +54,9 @@ def tearDown(self):
self.patcher3.stop()
self.patcher4.stop()
self.patcher5.stop()
self.patcher6.stop()
self.patcher7.stop()
self.patcher8.stop()

def test_bench_command_normal_execution_all_runtimes(self):
self.mock_parse_args.return_value = (argparse.Namespace(
Expand Down Expand Up @@ -317,5 +326,14 @@ def test_update_ui_command(self, mock_system, mock_parse_args):
mock_exit.assert_not_called()
mock_system.assert_called_with('sh ./scripts/update-ui-tests.sh')

@patch('argparse.ArgumentParser.parse_known_args', return_value=(argparse.Namespace(command='prdoc', continue_on_fail=False), []))
@patch('os.system', return_value=0)
def test_prdoc_command(self, mock_system, mock_parse_args):
with patch('sys.exit') as mock_exit:
import cmd
cmd.main()
mock_exit.assert_not_called()
self.mock_generate_prdoc_main.assert_called_with(mock_parse_args.return_value[0])

if __name__ == '__main__':
unittest.main()
31 changes: 21 additions & 10 deletions .github/scripts/generate-prdoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,17 +113,28 @@ def yaml_multiline_string_presenter(dumper, data):

yaml.add_representer(str, yaml_multiline_string_presenter)

def parse_args():
parser = argparse.ArgumentParser()
parser.add_argument("--pr", type=int, required=True)
parser.add_argument("--audience", type=str, default="TODO")
parser.add_argument("--bump", type=str, default="TODO")
parser.add_argument("--force", type=str)
return parser.parse_args()
# parse_args is also used by cmd/cmd.py
def setup_parser(parser=None):
if parser is None:
parser = argparse.ArgumentParser()
parser.add_argument("--pr", type=int, required=True, help="The PR number to generate the PrDoc for." )
parser.add_argument("--audience", type=str, default="TODO", help="The audience of whom the changes may concern.")
parser.add_argument("--bump", type=str, default="TODO", help="A default bump level for all crates.")
parser.add_argument("--force", type=str, help="Whether to overwrite any existing PrDoc.")

return parser

if __name__ == "__main__":
args = parse_args()
def main(args):
force = True if (args.force or "false").lower() == "true" else False
print(f"Args: {args}, force: {force}")
setup_yaml()
from_pr_number(args.pr, args.audience, args.bump, force)
try:
from_pr_number(args.pr, args.audience, args.bump, force)
return 0
except Exception as e:
print(f"Error generating prdoc: {e}")
return 1

if __name__ == "__main__":
args = setup_parser().parse_args()
main(args)
6 changes: 6 additions & 0 deletions .github/scripts/generate-prdoc.requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
requests
cargo-workspace
PyGithub
whatthepatch
pyyaml
toml
37 changes: 24 additions & 13 deletions .github/workflows/check-cargo-check-runtimes.yml
Original file line number Diff line number Diff line change
@@ -1,28 +1,39 @@
name: Check Cargo Check Runtimes

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

on:
pull_request:
types: [opened, synchronize, reopened, ready_for_review, labeled]
types: [opened, synchronize, reopened, ready_for_review]

# Jobs in this workflow depend on each other, only for limiting peak amount of spawned workers

jobs:
# GitHub Actions allows using 'env' in a container context.
# However, env variables don't work for forks: https://github.com/orgs/community/discussions/44322
# This workaround sets the container image for each job using 'set-image' job output.
set-image:
if: contains(github.event.label.name, 'GHA-migration') || contains(github.event.pull_request.labels.*.name, 'GHA-migration')
# GitHub Actions allows using 'env' in a container context.
# However, env variables don't work for forks: https://github.com/orgs/community/discussions/44322
# This workaround sets the container image for each job using 'set-image' job output.
runs-on: ubuntu-latest
timeout-minutes: 20
outputs:
IMAGE: ${{ steps.set_image.outputs.IMAGE }}
RUNNER: ${{ steps.set_runner.outputs.RUNNER }}
steps:
- name: Checkout
uses: actions/checkout@v4
- id: set_image
run: cat .github/env >> $GITHUB_OUTPUT
- id: set_runner
run: |
# Run merge queues on persistent runners
if [[ $GITHUB_REF_NAME == *"gh-readonly-queue"* ]]; then
echo "RUNNER=arc-runners-polkadot-sdk-beefy-persistent" >> $GITHUB_OUTPUT
else
echo "RUNNER=arc-runners-polkadot-sdk-beefy" >> $GITHUB_OUTPUT
fi
check-runtime-assets:
runs-on: arc-runners-polkadot-sdk-beefy
runs-on: ${{ needs.set-image.outputs.RUNNER }}
needs: [set-image]
timeout-minutes: 20
container:
Expand All @@ -36,7 +47,7 @@ jobs:
root: cumulus/parachains/runtimes/assets

check-runtime-collectives:
runs-on: arc-runners-polkadot-sdk-beefy
runs-on: ${{ needs.set-image.outputs.RUNNER }}
needs: [check-runtime-assets, set-image]
timeout-minutes: 20
container:
Expand All @@ -50,7 +61,7 @@ jobs:
root: cumulus/parachains/runtimes/collectives

check-runtime-coretime:
runs-on: arc-runners-polkadot-sdk-beefy
runs-on: ${{ needs.set-image.outputs.RUNNER }}
container:
image: ${{ needs.set-image.outputs.IMAGE }}
needs: [check-runtime-assets, set-image]
Expand All @@ -64,7 +75,7 @@ jobs:
root: cumulus/parachains/runtimes/coretime

check-runtime-bridge-hubs:
runs-on: arc-runners-polkadot-sdk-beefy
runs-on: ${{ needs.set-image.outputs.RUNNER }}
container:
image: ${{ needs.set-image.outputs.IMAGE }}
needs: [set-image]
Expand All @@ -78,7 +89,7 @@ jobs:
root: cumulus/parachains/runtimes/bridge-hubs

check-runtime-contracts:
runs-on: arc-runners-polkadot-sdk-beefy
runs-on: ${{ needs.set-image.outputs.RUNNER }}
container:
image: ${{ needs.set-image.outputs.IMAGE }}
needs: [check-runtime-collectives, set-image]
Expand All @@ -92,7 +103,7 @@ jobs:
root: cumulus/parachains/runtimes/contracts

check-runtime-starters:
runs-on: arc-runners-polkadot-sdk-beefy
runs-on: ${{ needs.set-image.outputs.RUNNER }}
container:
image: ${{ needs.set-image.outputs.IMAGE }}
needs: [check-runtime-assets, set-image]
Expand All @@ -106,7 +117,7 @@ jobs:
root: cumulus/parachains/runtimes/starters

check-runtime-testing:
runs-on: arc-runners-polkadot-sdk-beefy
runs-on: ${{ needs.set-image.outputs.RUNNER }}
container:
image: ${{ needs.set-image.outputs.IMAGE }}
needs: [check-runtime-starters, set-image]
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/check-features.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ on:
pull_request:
types: [opened, synchronize, reopened, ready_for_review]

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
check-features:
runs-on: ubuntu-latest
Expand Down
48 changes: 42 additions & 6 deletions .github/workflows/check-frame-omni-bencher.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
branches:
- master
pull_request:
types: [ opened, synchronize, reopened, ready_for_review, labeled ]
types: [opened, synchronize, reopened, ready_for_review, labeled]
merge_group:

concurrency:
Expand All @@ -28,19 +28,46 @@ jobs:
# However, env variables don't work for forks: https://github.com/orgs/community/discussions/44322
# This workaround sets the container image for each job using 'set-image' job output.
runs-on: ubuntu-latest
needs: changes
if: ${{ needs.changes.outputs.rust }}
outputs:
IMAGE: ${{ steps.set_image.outputs.IMAGE }}
RUNNER: ${{ steps.set_runner.outputs.RUNNER }}
steps:
- name: Checkout
uses: actions/checkout@v4
- id: set_image
run: cat .github/env >> $GITHUB_OUTPUT
- id: set_runner
run: |
# Run merge queues on persistent runners
if [[ $GITHUB_REF_NAME == *"gh-readonly-queue"* ]]; then
echo "RUNNER=arc-runners-polkadot-sdk-beefy-persistent" >> $GITHUB_OUTPUT
else
echo "RUNNER=arc-runners-polkadot-sdk-beefy" >> $GITHUB_OUTPUT
fi
quick-benchmarks-omni:
runs-on: ${{ needs.set-image.outputs.RUNNER }}
needs: [set-image, changes]
if: ${{ needs.changes.outputs.rust }}
env:
RUSTFLAGS: "-C debug-assertions"
RUST_BACKTRACE: "full"
WASM_BUILD_NO_COLOR: 1
WASM_BUILD_RUSTFLAGS: "-C debug-assertions"
timeout-minutes: 30
container:
image: ${{ needs.set-image.outputs.IMAGE }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: script
run: |
forklift cargo build --locked --quiet --release -p asset-hub-westend-runtime --features runtime-benchmarks
forklift cargo run --locked --release -p frame-omni-bencher --quiet -- v1 benchmark pallet --runtime target/release/wbuild/asset-hub-westend-runtime/asset_hub_westend_runtime.compact.compressed.wasm --all --steps 2 --repeat 1 --quiet
run-frame-omni-bencher:
runs-on: arc-runners-polkadot-sdk-beefy
needs: [ set-image, changes ] # , build-frame-omni-bencher ]
runs-on: ${{ needs.set-image.outputs.RUNNER }}
needs: [set-image, changes] # , build-frame-omni-bencher ]
if: ${{ needs.changes.outputs.rust }}
timeout-minutes: 30
strategy:
Expand Down Expand Up @@ -81,5 +108,14 @@ jobs:
runs-on: ubuntu-latest
name: All benchmarks passed
needs: run-frame-omni-bencher
if: always() && !cancelled()
steps:
- run: echo '### Good job! All the benchmarks passed 🚀' >> $GITHUB_STEP_SUMMARY
- run: |
tee resultfile <<< '${{ toJSON(needs) }}'
FAILURES=$(cat resultfile | grep '"result": "failure"' | wc -l)
if [ $FAILURES -gt 0 ]; then
echo "### At least one required job failed ❌" >> $GITHUB_STEP_SUMMARY
exit 1
else
echo '### Good job! All the required jobs passed 🚀' >> $GITHUB_STEP_SUMMARY
fi
4 changes: 4 additions & 0 deletions .github/workflows/check-labels.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
name: Check labels

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

on:
pull_request:
types: [labeled, opened, synchronize, unlabeled]
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/check-licenses.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ on:
pull_request:
merge_group:

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

permissions:
packages: read

Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/check-links.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ on:
types: [opened, synchronize, reopened, ready_for_review]
merge_group:

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

permissions:
packages: read

Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/check-prdoc.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
name: Check PRdoc

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

on:
pull_request:
types: [labeled, opened, synchronize, unlabeled]
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/check-semver.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ jobs:
- name: install parity-publish
# Set the target dir to cache the build.
run: CARGO_TARGET_DIR=./target/ cargo install [email protected] -q
run: CARGO_TARGET_DIR=./target/ cargo install [email protected] --locked -q

- name: check semver
run: |
Expand Down
Loading

0 comments on commit d95334c

Please sign in to comment.