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

ci/nightly: Compare parsec and parsec-tool dependency versions #116

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
17 changes: 17 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,20 @@ jobs:
args: -v -r *.md
- name: Fail if there were link errors
run: exit ${{ steps.lc.outputs.exit_code }}

mismatcher:
name: Check for mismatched dependencies (those that have more than one version)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
ref: "${{ github.event.inputs.rev }}"
- name: Install latest Rust
uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: stable
rustflags: ""
- name: Execute CI script
uses: ./.github/actions/ci_script
with:
ci-flags: "mismatcher"
17 changes: 0 additions & 17 deletions .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,3 @@ jobs:
run: cargo install cargo-audit
- name: Execute cargo audit
run: cargo audit

mismatcher:
name: Check for mismatched dependencies (those that have more than one version)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
ref: "${{ github.event.inputs.rev }}"
- name: Install Rust MSRV
uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: stable
rustflags: ""
- name: Execute CI script
uses: ./.github/actions/ci_script
with:
ci-flags: "mismatcher"
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions tests/ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,10 @@ done
# Dependency mismatcher #
#########################
if [ "$MISMATCHER" = "True" ]; then

python3 $(pwd)/utils/dependency_cross_matcher.py --deps_dir $(pwd)
mismatcher_result=$?
if [ "$mismatcher_result" -ne 0 ]; then
error_msg "Found dependencies version mismatches"
fi

python3 $(pwd)/utils/dependency_cross_matcher.py -c --deps_dir $(pwd)/parsec $(pwd)

exit 0
fi
Expand Down
67 changes: 53 additions & 14 deletions utils/dependency_cross_matcher.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
# Copyright 2023 Contributors to the Parsec project.
# SPDX-License-Identifier: Apache-2.0

# Checks the version mismatches for dependencies in Cargo based repositories:
# * In parsec-tool itself
# * Between parsec and parsec-tool
import argparse
import re
import os
import subprocess
import sys


def run_cargo_tree(path):
cmd = 'cargo tree --all-features -d'
def run_cargo_tree(path, flags=None):
cmd = 'cargo tree'
if flags is not None:
cmd += ' ' + flags
prev_dir = os.getcwd()
os.chdir(os.path.join(path))
return subprocess.check_output(cmd, shell=True).decode()
Expand Down Expand Up @@ -43,30 +51,61 @@ def main(argv=[], prog_name=''):
parser = argparse.ArgumentParser(prog='DependencyCrossmatcher',
description='Checks the version mismatches for dependencies '
'in Cargo based repositories')
parser.add_argument("-c", "--compare", action='store_true',
help='Check for mismatches between 2 repositories')
parser.add_argument('--deps_dir',
required=True,
help='Existing directory that contains the Cargo.toml for analyzing'
nargs='+',
help='Existing directories that contain Cargo.toml for analyzing '
'dependencies')
args = parser.parse_args()

mismatches = run_deps_mismatcher(run_cargo_tree(args.deps_dir))
print_deps(mismatches)
tgonzalezorlandoarm marked this conversation as resolved.
Show resolved Hide resolved
mismatches = dict()
parsec_tool_flags = '--all-features -d'

if args.compare:
exceptions = {
'bindgen': ['v0.66.1', 'v0.57.0'],
}
parsec_repo, parsec_tool_repo = args.deps_dir
parsec_flags = '--all-features' + ' '
parsec_flags = '--features tss-esapi/generate-bindings,cryptoki/generate-bindings -d'
mismatches_parsec = run_deps_mismatcher(run_cargo_tree(parsec_repo, parsec_flags))
mismatches_parsec_tool = run_deps_mismatcher(run_cargo_tree(parsec_tool_repo,
parsec_tool_flags)
)

# Dependencies that are common to both parsec_repo and parsec_tool_repo repos
common_deps = list(set(mismatches_parsec.keys()) & set(mismatches_parsec_tool.keys()))
for dep in common_deps:
# Symmetric difference of repos parsec_repo and parsec_tool_repo
mistmatch = list(set(mismatches_parsec[dep]) ^ set(mismatches_parsec_tool[dep]))
if len(mistmatch) > 0:
mismatches[dep] = mistmatch
else:
exceptions = {
'base64': ['v0.13.1', 'v0.21.4'],
'bitflags': ['v1.3.2', 'v2.4.1'],
'nom': ['v5.1.3', 'v7.1.3'],
'syn': ['v1.0.109', 'v2.0.38'],
'yasna': ['v0.4.0', 'v0.5.2'],
}
mismatches = run_deps_mismatcher(run_cargo_tree(args.deps_dir[0], parsec_tool_flags))

mismatches = get_deps_with_more_than_1v(mismatches)

print('---------------------exceptions-----------------------\n\n')
print_deps(exceptions)

print('---------------------mistmatches----------------------\n\n')
print_deps(mismatches)

exceptions = {
'base64': ['v0.13.1', 'v0.21.4'],
'bitflags': ['v1.3.2', 'v2.4.1'],
'nom': ['v5.1.3', 'v7.1.3'],
'syn': ['v1.0.109', 'v2.0.38'],
'yasna': ['v0.4.0', 'v0.5.2'],
}
if not args.compare:
errormsg = "Found dependencies version mismatches in parsec-tool"
else:
errormsg = "Found dependencies version mismatches between parsec and parsec-tool"

if exceptions != mismatches:
return 1
assert exceptions == mismatches, errormsg

return 0

Expand Down
Loading