Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

CI: Rewrite check-each-crate in python #13238

Merged
merged 9 commits into from
Jan 25, 2023
Merged
Show file tree
Hide file tree
Changes from 6 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
57 changes: 57 additions & 0 deletions scripts/ci/gitlab/check-each-crate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/usr/bin/env python3

# A script that checks each workspace crate individually.
# It's relevant to check workspace crates individually because otherwise their compilation problems
# due to feature misconfigurations won't be caught, as exemplified by
# https://github.com/paritytech/substrate/issues/12705
#
# `check-each-crate.py target_group groups_total`
#
# - `target_group`: Integer starting from 1, the group this script should execute.
# - `groups_total`: Integer starting from 1, total number of groups.

import subprocess, sys

# Get all crates
output = subprocess.check_output(["cargo", "tree", "--workspace", "--depth", "0", "--prefix", "none"])
bkchr marked this conversation as resolved.
Show resolved Hide resolved

# Convert the output into a proper list
crates = []
for line in output.splitlines():
if line != b"":
crates.append(line.decode('utf8').split(" ")[0])

# Make the list unique and sorted
crates = list(set(crates))
crates.sort()

target_group = int(sys.argv[1]) - 1
groups_total = int(sys.argv[2])

if len(crates) == 0:
print("No crates detected!", file=sys.stderr)
sys.exit(1)

print(f"Total crates: {len(crates)}", file=sys.stderr)

crates_per_group = len(crates) // groups_total
michalkucharczyk marked this conversation as resolved.
Show resolved Hide resolved

# If this is the last runner, we need to take care of crates
# after the group that we lost because of the integer division.
if target_group + 1 == groups_total:
overflow_crates = len(crates) % groups_total
else:
overflow_crates = 0

print(f"Crates per group: {crates_per_group}", file=sys.stderr)

# Check each crate
for i in range(0, crates_per_group + overflow_crates):
crate = crates_per_group * target_group + i

print(f"Checking {crates[crate]}", file=sys.stderr)

res = subprocess.run(["cargo", "check", "--locked", "-p", crates[crate]])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In theory we would have to check with each feature subset… but that would make it even slower 😅

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I know :P


if res.returncode != 0:
sys.exit(1)
54 changes: 0 additions & 54 deletions scripts/ci/gitlab/check-each-crate.sh

This file was deleted.

4 changes: 2 additions & 2 deletions scripts/ci/gitlab/pipeline/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ cargo-check-each-crate:
CI_JOB_NAME: cargo-check-each-crate
script:
- rusty-cachier snapshot create
- time ./scripts/ci/gitlab/check-each-crate.sh "$CI_NODE_INDEX" "$CI_NODE_TOTAL"
- PYTHONUNBUFFERED=x time ./scripts/ci/gitlab/check-each-crate.py "$CI_NODE_INDEX" "$CI_NODE_TOTAL"
# need to update cache only from one job
- if [ "$CI_NODE_INDEX" == 1 ]; then rusty-cachier cache upload; fi
parallel: 2
Expand Down Expand Up @@ -449,6 +449,6 @@ cargo-check-each-crate-macos:
script:
# TODO: enable rusty-cachier once it supports Mac
# TODO: use parallel jobs, as per cargo-check-each-crate, once more Mac runners are available
- time ./scripts/ci/gitlab/check-each-crate.sh 1 1
- time ./scripts/ci/gitlab/check-each-crate.py 1 1
tags:
- osx