From f5e3ad7ed062f47bd7aaaac0fc0e6211fd00fe87 Mon Sep 17 00:00:00 2001 From: Maksym H Date: Fri, 4 Oct 2024 16:36:19 +0100 Subject: [PATCH 1/8] fix regex, improve prdoc generation inputs --- .github/scripts/generate-prdoc.py | 15 +++++++-------- .github/workflows/cmd.yml | 4 ++-- docs/contributor/commands-readme.md | 3 ++- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/.github/scripts/generate-prdoc.py b/.github/scripts/generate-prdoc.py index f05d517a5802..73fd05a2552d 100644 --- a/.github/scripts/generate-prdoc.py +++ b/.github/scripts/generate-prdoc.py @@ -7,7 +7,7 @@ This will delete any prdoc that already exists for the PR if `--force` is passed. Usage: - python generate-prdoc.py --pr 1234 --audience "TODO" --bump "TODO" + python generate-prdoc.py --pr 1234 --audience "Node Dev" --bump "patch" """ import argparse @@ -111,21 +111,20 @@ def yaml_multiline_string_presenter(dumper, data): # parse_args is also used by cmd/cmd.py def setup_parser(parser=None): + allowed_audiences = ["Runtime Dev", "Runtime User", "Node Dev", "Node Operator"] 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.") - + parser.add_argument("--audience", type=str, nargs='*', choices=allowed_audiences, default=["TODO"], help="The audience of whom the changes may concern. Example: --audience \"Runtime Dev\" \"Node Dev\"") + parser.add_argument("--bump", type=str, default="major", choices=["patch", "minor", "major", "silent", "ignore", "no change"], help="A default bump level for all crates. Example: --bump \"patch\"") + parser.add_argument("--force", action="store_true", help="Whether to overwrite any existing PrDoc.") return parser def main(args): - force = True if (args.force or "false").lower() == "true" else False - print(f"Args: {args}, force: {force}") + print(f"Args: {args}, force: {args.force}") setup_yaml() try: - from_pr_number(args.pr, args.audience, args.bump, force) + from_pr_number(args.pr, args.audience, args.bump, args.force) return 0 except Exception as e: print(f"Error generating prdoc: {e}") diff --git a/.github/workflows/cmd.yml b/.github/workflows/cmd.yml index e416b1202691..ecd339490059 100644 --- a/.github/workflows/cmd.yml +++ b/.github/workflows/cmd.yml @@ -152,7 +152,7 @@ jobs: id: get-pr-comment with: text: ${{ github.event.comment.body }} - regex: '^(\/cmd )([-\/\s\w.=:]+)$' # see explanation in docs/contributor/commands-readme.md#examples + regex: "^(\\/cmd )([-\\/\\s\\w.=:'\"]+)$" # see explanation in docs/contributor/commands-readme.md#examples - name: Save output of help id: help @@ -291,7 +291,7 @@ jobs: id: get-pr-comment with: text: ${{ github.event.comment.body }} - regex: '^(\/cmd )([-\/\s\w.=:]+)$' # see explanation in docs/contributor/commands-readme.md#examples + regex: "^(\\/cmd )([-\\/\\s\\w.=:'\"]+)$" # see explanation in docs/contributor/commands-readme.md#examples - name: Build workflow link if: ${{ !contains(github.event.comment.body, '--quiet') }} diff --git a/docs/contributor/commands-readme.md b/docs/contributor/commands-readme.md index 861c3ac784d5..761b975bf719 100644 --- a/docs/contributor/commands-readme.md +++ b/docs/contributor/commands-readme.md @@ -41,7 +41,8 @@ the default branch. ### Examples -The regex in cmd.yml is: `^(\/cmd )([-\/\s\w.=:]+)$` accepts only alphanumeric, space, "-", "/", "=", ":", "." chars. +The regex in cmd.yml is: `^(\/cmd )([-\/\s\w.=:'"]+)$` accepts only alphanumeric, space, "-", "/", "=", ":", ".", '"' chars. `/cmd bench --runtime bridge-hub-westend --pallet=pallet_name` +`/cmd prdoc --pr 5924 --audience "Node Dev" "Node Operator" --bump "patch"` `/cmd update-ui --image=docker.io/paritytech/ci-unified:bullseye-1.77.0-2024-04-10-v202407161507 --clean` From 3a92dcbd05992cf972fc9b92bd0fc3b0cf85511f Mon Sep 17 00:00:00 2001 From: Maksym H Date: Fri, 4 Oct 2024 18:21:56 +0100 Subject: [PATCH 2/8] add default --pr command, modify --audience arguments to avoid quotes --- .github/scripts/generate-prdoc.py | 16 +++++++++++----- .github/workflows/cmd.yml | 28 +++++++++++++++++++++------- .github/workflows/command-prdoc.yml | 17 +++++++---------- docs/contributor/commands-readme.md | 4 ++-- 4 files changed, 41 insertions(+), 24 deletions(-) diff --git a/.github/scripts/generate-prdoc.py b/.github/scripts/generate-prdoc.py index 73fd05a2552d..59f768258eef 100644 --- a/.github/scripts/generate-prdoc.py +++ b/.github/scripts/generate-prdoc.py @@ -111,25 +111,31 @@ def yaml_multiline_string_presenter(dumper, data): # parse_args is also used by cmd/cmd.py def setup_parser(parser=None): - allowed_audiences = ["Runtime Dev", "Runtime User", "Node Dev", "Node Operator"] + allowed_audiences = ["runtime_dev", "runtime_user", "node_dev", "node_operator"] 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, nargs='*', choices=allowed_audiences, default=["TODO"], help="The audience of whom the changes may concern. Example: --audience \"Runtime Dev\" \"Node Dev\"") + parser.add_argument("--pr", type=int, required=True, help="The PR number to generate the PrDoc for.") + parser.add_argument("--audience", type=str, nargs='*', choices=allowed_audiences, default=["todo"], help="The audience of whom the changes may concern. Example: --audience runtime_dev node_dev") parser.add_argument("--bump", type=str, default="major", choices=["patch", "minor", "major", "silent", "ignore", "no change"], help="A default bump level for all crates. Example: --bump \"patch\"") parser.add_argument("--force", action="store_true", help="Whether to overwrite any existing PrDoc.") return parser +def snake_to_title(s): + return ' '.join(word.capitalize() for word in s.split('_')) + def main(args): print(f"Args: {args}, force: {args.force}") setup_yaml() try: - from_pr_number(args.pr, args.audience, args.bump, args.force) + # Convert snake_case audience arguments to title case + mapped_audiences = [snake_to_title(a) for a in args.audience] + from_pr_number(args.pr, mapped_audiences, args.bump, args.force) return 0 except Exception as e: print(f"Error generating prdoc: {e}") return 1 if __name__ == "__main__": - args = setup_parser().parse_args() + parser = setup_parser() + args = parser.parse_args() main(args) diff --git a/.github/workflows/cmd.yml b/.github/workflows/cmd.yml index ecd339490059..746fc657c452 100644 --- a/.github/workflows/cmd.yml +++ b/.github/workflows/cmd.yml @@ -152,15 +152,15 @@ jobs: id: get-pr-comment with: text: ${{ github.event.comment.body }} - regex: "^(\\/cmd )([-\\/\\s\\w.=:'\"]+)$" # see explanation in docs/contributor/commands-readme.md#examples + regex: "^(\\/cmd )([-\\/\\s\\w.=:]+)$" # see explanation in docs/contributor/commands-readme.md#examples - name: Save output of help id: help env: CMD: ${{ steps.get-pr-comment.outputs.group2 }} # to avoid "" around the command run: | - echo 'help<> $GITHUB_OUTPUT python3 -m pip install -r .github/scripts/generate-prdoc.requirements.txt + echo 'help<> $GITHUB_OUTPUT python3 .github/scripts/cmd/cmd.py $CMD >> $GITHUB_OUTPUT echo 'EOF' >> $GITHUB_OUTPUT @@ -291,7 +291,18 @@ jobs: id: get-pr-comment with: text: ${{ github.event.comment.body }} - regex: "^(\\/cmd )([-\\/\\s\\w.=:'\"]+)$" # see explanation in docs/contributor/commands-readme.md#examples + regex: "^(\\/cmd )([-\\/\\s\\w.=:]+)$" # see explanation in docs/contributor/commands-readme.md#examples + + # In order to run prdoc without specifying the PR number, we need to add the PR number as an argument automatically + - name: Prepare PR Number argument + id: pr-arg + run: | + CMD="${{ steps.get-pr-comment.outputs.group2 }}" + if [[ $CMD == *"prdoc"* ]] && [[ ! $CMD =~ --pr[[:space:]=][0-9]+ ]]; then + echo "arg=--pr ${{ github.event.issue.number }}" >> $GITHUB_OUTPUT + else + echo "arg=" >> $GITHUB_OUTPUT + fi - name: Build workflow link if: ${{ !contains(github.event.comment.body, '--quiet') }} @@ -314,7 +325,8 @@ jobs: echo "run_url=$runLink" >> $GITHUB_OUTPUT - name: Comment PR (Start) - if: ${{ !contains(github.event.comment.body, '--quiet') }} + # No need to comment on prdoc start or if --quiet + if: ${{ !contains(github.event.comment.body, '--quiet') && !contains(github.event.comment.body, 'prdoc') }} uses: actions/github-script@v7 with: github-token: ${{ secrets.GITHUB_TOKEN }} @@ -344,14 +356,15 @@ jobs: id: cmd env: CMD: ${{ steps.get-pr-comment.outputs.group2 }} # to avoid "" around the command + PR_ARG: ${{ steps.pr-arg.outputs.arg }} run: | - echo "Running command: '$CMD' on '${{ needs.set-image.outputs.RUNNER }}' runner, container: '${{ needs.set-image.outputs.IMAGE }}'" + echo "Running command: '$CMD $PR_ARG' on '${{ needs.set-image.outputs.RUNNER }}' runner, container: '${{ needs.set-image.outputs.IMAGE }}'" echo "RUST_NIGHTLY_VERSION: $RUST_NIGHTLY_VERSION" # Fixes "detected dubious ownership" error in the ci git config --global --add safe.directory '*' git remote -v python3 -m pip install -r .github/scripts/generate-prdoc.requirements.txt - python3 .github/scripts/cmd/cmd.py $CMD + python3 .github/scripts/cmd/cmd.py $CMD $PR_ARG git status git diff @@ -395,7 +408,8 @@ jobs: } >> $GITHUB_OUTPUT - name: Comment PR (End) - if: ${{ !failure() && !contains(github.event.comment.body, '--quiet') }} + # No need to comment on prdoc success or --quiet + if: ${{ !failure() && !contains(github.event.comment.body, '--quiet') && !contains(github.event.comment.body, 'prdoc') }} uses: actions/github-script@v7 env: SUBWEIGHT: "${{ steps.subweight.outputs.result }}" diff --git a/.github/workflows/command-prdoc.yml b/.github/workflows/command-prdoc.yml index 2154c8a987f2..c7ae69a41c18 100644 --- a/.github/workflows/command-prdoc.yml +++ b/.github/workflows/command-prdoc.yml @@ -25,18 +25,15 @@ on: required: true options: - "TODO" - - "Runtime Dev" - - "Runtime User" - - "Node Dev" - - "Node Operator" + - "runtime_dev" + - "runtime_user" + - "node_dev" + - "node_operator" overwrite: - type: choice + type: boolean description: Overwrite existing PrDoc - default: "true" + default: true required: true - options: - - "true" - - "false" concurrency: group: command-prdoc @@ -81,4 +78,4 @@ jobs: with: commit_message: Add PrDoc (auto generated) branch: ${{ steps.gh.outputs.branch }} - file_pattern: 'prdoc/*.prdoc' + file_pattern: "prdoc/*.prdoc" diff --git a/docs/contributor/commands-readme.md b/docs/contributor/commands-readme.md index 761b975bf719..994c9f49321b 100644 --- a/docs/contributor/commands-readme.md +++ b/docs/contributor/commands-readme.md @@ -41,8 +41,8 @@ the default branch. ### Examples -The regex in cmd.yml is: `^(\/cmd )([-\/\s\w.=:'"]+)$` accepts only alphanumeric, space, "-", "/", "=", ":", ".", '"' chars. +The regex in cmd.yml is: `^(\/cmd )([-\/\s\w.=:]+)$` accepts only alphanumeric, space, "-", "/", "=", ":" chars. `/cmd bench --runtime bridge-hub-westend --pallet=pallet_name` -`/cmd prdoc --pr 5924 --audience "Node Dev" "Node Operator" --bump "patch"` +`/cmd prdoc --pr 5924 --audience runtime_dev runtime_user --bump patch` `/cmd update-ui --image=docker.io/paritytech/ci-unified:bullseye-1.77.0-2024-04-10-v202407161507 --clean` From 7fa9806344b6face234479a274a291f3e44bb8fc Mon Sep 17 00:00:00 2001 From: Maksym H Date: Fri, 4 Oct 2024 18:25:32 +0100 Subject: [PATCH 3/8] fix --- .github/scripts/generate-prdoc.py | 4 ++-- .github/workflows/command-prdoc.yml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/scripts/generate-prdoc.py b/.github/scripts/generate-prdoc.py index 59f768258eef..7cef1f1e7345 100644 --- a/.github/scripts/generate-prdoc.py +++ b/.github/scripts/generate-prdoc.py @@ -7,7 +7,7 @@ This will delete any prdoc that already exists for the PR if `--force` is passed. Usage: - python generate-prdoc.py --pr 1234 --audience "Node Dev" --bump "patch" + python generate-prdoc.py --pr 1234 --audience node_dev --bump patch """ import argparse @@ -116,7 +116,7 @@ def setup_parser(parser=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, nargs='*', choices=allowed_audiences, default=["todo"], help="The audience of whom the changes may concern. Example: --audience runtime_dev node_dev") - parser.add_argument("--bump", type=str, default="major", choices=["patch", "minor", "major", "silent", "ignore", "no change"], help="A default bump level for all crates. Example: --bump \"patch\"") + parser.add_argument("--bump", type=str, default="major", choices=["patch", "minor", "major", "silent", "ignore", "no_change"], help="A default bump level for all crates. Example: --bump patch") parser.add_argument("--force", action="store_true", help="Whether to overwrite any existing PrDoc.") return parser diff --git a/.github/workflows/command-prdoc.yml b/.github/workflows/command-prdoc.yml index c7ae69a41c18..7022e8e0e006 100644 --- a/.github/workflows/command-prdoc.yml +++ b/.github/workflows/command-prdoc.yml @@ -14,7 +14,7 @@ on: required: true options: - "TODO" - - "no change" + - "no_change" - "patch" - "minor" - "major" From cdf29e8985edfb8d90a4a835de5df0cb390c2a9c Mon Sep 17 00:00:00 2001 From: Maksym H Date: Fri, 4 Oct 2024 18:50:11 +0100 Subject: [PATCH 4/8] make --pr optional for /cmd --- .github/scripts/cmd/cmd.py | 2 +- .github/scripts/generate-prdoc.py | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/scripts/cmd/cmd.py b/.github/scripts/cmd/cmd.py index b5835f1f3085..b421ab753f78 100755 --- a/.github/scripts/cmd/cmd.py +++ b/.github/scripts/cmd/cmd.py @@ -77,7 +77,7 @@ spec.loader.exec_module(generate_prdoc) parser_prdoc = subparsers.add_parser('prdoc', help='Generates PR documentation') -generate_prdoc.setup_parser(parser_prdoc) +generate_prdoc.setup_parser(parser_prdoc, pr_required=False) def main(): global args, unknown, runtimesMatrix diff --git a/.github/scripts/generate-prdoc.py b/.github/scripts/generate-prdoc.py index 7cef1f1e7345..edcdb82cd22e 100644 --- a/.github/scripts/generate-prdoc.py +++ b/.github/scripts/generate-prdoc.py @@ -110,11 +110,12 @@ def yaml_multiline_string_presenter(dumper, data): yaml.add_representer(str, yaml_multiline_string_presenter) # parse_args is also used by cmd/cmd.py -def setup_parser(parser=None): +# if pr_required is False, then --pr is optional, as it can be derived from the PR comment body +def setup_parser(parser=None, pr_required=True): allowed_audiences = ["runtime_dev", "runtime_user", "node_dev", "node_operator"] 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("--pr", type=int, required=pr_required, help="The PR number to generate the PrDoc for.") parser.add_argument("--audience", type=str, nargs='*', choices=allowed_audiences, default=["todo"], help="The audience of whom the changes may concern. Example: --audience runtime_dev node_dev") parser.add_argument("--bump", type=str, default="major", choices=["patch", "minor", "major", "silent", "ignore", "no_change"], help="A default bump level for all crates. Example: --bump patch") parser.add_argument("--force", action="store_true", help="Whether to overwrite any existing PrDoc.") From e04b7a9d09e85c7fd4943153eac75f97666b071e Mon Sep 17 00:00:00 2001 From: Maksym H Date: Fri, 4 Oct 2024 19:28:50 +0100 Subject: [PATCH 5/8] Update cmd.yml --- .github/workflows/cmd.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/cmd.yml b/.github/workflows/cmd.yml index 746fc657c452..776fd0c676f8 100644 --- a/.github/workflows/cmd.yml +++ b/.github/workflows/cmd.yml @@ -298,7 +298,7 @@ jobs: id: pr-arg run: | CMD="${{ steps.get-pr-comment.outputs.group2 }}" - if [[ $CMD == *"prdoc"* ]] && [[ ! $CMD =~ --pr[[:space:]=][0-9]+ ]]; then + if echo "$CMD" | grep -q "prdoc" && ! echo "$CMD" | grep -qE "--pr[[:space:]=][0-9]+"; then echo "arg=--pr ${{ github.event.issue.number }}" >> $GITHUB_OUTPUT else echo "arg=" >> $GITHUB_OUTPUT From 3b84cf478e5fd6870b5836e17b7d52b88b75ddce Mon Sep 17 00:00:00 2001 From: Maksym H Date: Fri, 4 Oct 2024 21:39:44 +0100 Subject: [PATCH 6/8] Update cmd.yml --- .github/workflows/cmd.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/cmd.yml b/.github/workflows/cmd.yml index 776fd0c676f8..815ba484db91 100644 --- a/.github/workflows/cmd.yml +++ b/.github/workflows/cmd.yml @@ -298,7 +298,7 @@ jobs: id: pr-arg run: | CMD="${{ steps.get-pr-comment.outputs.group2 }}" - if echo "$CMD" | grep -q "prdoc" && ! echo "$CMD" | grep -qE "--pr[[:space:]=][0-9]+"; then + if echo "$CMD" | grep -q "prdoc" && ! echo "$CMD" | grep -qE "\-\-pr[[:space:]=][0-9]+"; then echo "arg=--pr ${{ github.event.issue.number }}" >> $GITHUB_OUTPUT else echo "arg=" >> $GITHUB_OUTPUT From 07fe011d0a90b5dbfef06a5a838c66d1ebcb2618 Mon Sep 17 00:00:00 2001 From: Maksym H Date: Fri, 4 Oct 2024 21:52:21 +0100 Subject: [PATCH 7/8] Update commands-readme.md --- docs/contributor/commands-readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/contributor/commands-readme.md b/docs/contributor/commands-readme.md index 994c9f49321b..3a7ec163dbf1 100644 --- a/docs/contributor/commands-readme.md +++ b/docs/contributor/commands-readme.md @@ -41,7 +41,7 @@ the default branch. ### Examples -The regex in cmd.yml is: `^(\/cmd )([-\/\s\w.=:]+)$` accepts only alphanumeric, space, "-", "/", "=", ":" chars. +The regex in cmd.yml is: `^(\/cmd )([-\/\s\w.=:]+)$` accepts only alphanumeric, space, "-", "/", "=", ":", "." chars. `/cmd bench --runtime bridge-hub-westend --pallet=pallet_name` `/cmd prdoc --pr 5924 --audience runtime_dev runtime_user --bump patch` From 6b3ffd3edd62b8068b986b68f6108d49886819b2 Mon Sep 17 00:00:00 2001 From: Maksym H <1177472+mordamax@users.noreply.github.com> Date: Mon, 7 Oct 2024 17:00:54 +0100 Subject: [PATCH 8/8] Update docs/contributor/commands-readme.md --- docs/contributor/commands-readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/contributor/commands-readme.md b/docs/contributor/commands-readme.md index 3a7ec163dbf1..3a0fadc3bb25 100644 --- a/docs/contributor/commands-readme.md +++ b/docs/contributor/commands-readme.md @@ -44,5 +44,5 @@ the default branch. The regex in cmd.yml is: `^(\/cmd )([-\/\s\w.=:]+)$` accepts only alphanumeric, space, "-", "/", "=", ":", "." chars. `/cmd bench --runtime bridge-hub-westend --pallet=pallet_name` -`/cmd prdoc --pr 5924 --audience runtime_dev runtime_user --bump patch` +`/cmd prdoc --audience runtime_dev runtime_user --bump patch --force` `/cmd update-ui --image=docker.io/paritytech/ci-unified:bullseye-1.77.0-2024-04-10-v202407161507 --clean`