Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[prdoc] Validate crate names #3467

Merged
merged 10 commits into from
Feb 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 71 additions & 0 deletions .github/scripts/check-prdoc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#!/usr/bin/env python3

'''
Ensure that the prdoc files are valid.

# Example

```sh
python3 -m pip install cargo-workspace
python3 .github/scripts/check-prdoc.py Cargo.toml prdoc/*.prdoc
```

Produces example output:
```pre
πŸ”Ž Reading workspace polkadot-sdk/Cargo.toml
πŸ“¦ Checking 32 prdocs against 493 crates.
βœ… All prdocs are valid
```
'''

import os
import yaml
import argparse
import cargo_workspace

def check_prdoc_crate_names(root, paths):
'''
Check that all crates of the `crates` section of each prdoc is present in the workspace.
'''

print(f'πŸ”Ž Reading workspace {root}.')
workspace = cargo_workspace.Workspace.from_path(root)
crate_names = [crate.name for crate in workspace.crates]

print(f'πŸ“¦ Checking {len(paths)} prdocs against {len(crate_names)} crates.')
faulty = {}

for path in paths:
with open(path, 'r') as f:
prdoc = yaml.safe_load(f)

for crate in prdoc.get('crates', []):
crate = crate['name']
if crate in crate_names:
continue

faulty.setdefault(path, []).append(crate)

if len(faulty) == 0:
print('βœ… All prdocs are valid.')
else:
print('❌ Some prdocs are invalid.')
for path, crates in faulty.items():
print(f'πŸ’₯ {path} lists invalid crate: {", ".join(crates)}')
exit(1)

def parse_args():
parser = argparse.ArgumentParser(description='Check prdoc files')
parser.add_argument('root', help='The cargo workspace manifest', metavar='root', type=str, nargs=1)
parser.add_argument('prdoc', help='The prdoc files', metavar='prdoc', type=str, nargs='*')
args = parser.parse_args()

if len(args.prdoc) == 0:
print('❌ Need at least one prdoc file as argument.')
exit(1)

return { 'root': os.path.abspath(args.root[0]), 'prdocs': args.prdoc }

if __name__ == '__main__':
args = parse_args()
check_prdoc_crate_names(args['root'], args['prdocs'])
8 changes: 8 additions & 0 deletions .github/workflows/check-prdoc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,11 @@ jobs:
echo "Checking for PR#${GITHUB_PR}"
echo "You can find more information about PRDoc at $PRDOC_DOC"
$ENGINE run --rm -v $PWD:/repo -e RUST_LOG=info $IMAGE check -n ${GITHUB_PR}

- name: Validate prdoc for PR#${{ github.event.pull_request.number }}
if: ${{ !contains(steps.get-labels.outputs.labels, 'R0') }}
run: |
echo "Validating PR#${GITHUB_PR}"
python3 --version
python3 -m pip install cargo-workspace==1.2.1
python3 .github/scripts/check-prdoc.py Cargo.toml prdoc/pr_${GITHUB_PR}.prdoc
2 changes: 1 addition & 1 deletion prdoc/1.4.0/pr_1246.prdoc
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ migrations:
description: "Messages from the DMP dispatch queue will be moved over to the MQ pallet via `on_initialize`. This happens over multiple blocks and emits a `Completed` event at the end. The pallet can be un-deployed and deleted afterwards. Note that the migration reverses the order of messages, which should be acceptable as a one-off."

crates:
- name: cumulus_pallet_xcmp_queue
- name: cumulus-pallet-xcmp-queue
note: Pallet config must be altered according to the MR description.

host_functions: []
2 changes: 1 addition & 1 deletion prdoc/1.6.0/pr_2689.prdoc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Schema: Parity PR Documentation Schema (prdoc)
# See doc at https://github.com/paritytech/prdoc

title: BEEFY: Support compatibility with Warp Sync - Allow Warp Sync for Validators
title: "BEEFY: Support compatibility with Warp Sync - Allow Warp Sync for Validators"

doc:
- audience: Node Operator
Expand Down
2 changes: 1 addition & 1 deletion prdoc/1.6.0/pr_2771.prdoc
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ doc:
Enable better req-response protocol versioning, by allowing for fallback requests on different protocols.

crates:
- name: sc_network
- name: sc-network
2 changes: 1 addition & 1 deletion prdoc/pr_3412.prdoc
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ doc:

crates:
- name: pallet-babe
- name: pallet-aura-ext
- name: cumulus-pallet-aura-ext
- name: pallet-session
Loading