Skip to content

Commit

Permalink
ci: ensure all 3rd party crates have a specified version
Browse files Browse the repository at this point in the history
  • Loading branch information
metaclips committed Aug 1, 2024
1 parent 17cf5e7 commit 7581877
Showing 1 changed file with 90 additions and 65 deletions.
155 changes: 90 additions & 65 deletions .github/workflows/check_crate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,48 +32,44 @@ jobs:
run: cargo install --locked tomlq --version 0.1.0

- name: Read member paths from implementations/rust/ockam directory
id: member_paths
run: |
paths=$(find implementations/rust/ockam -name Cargo.toml)
echo "OCKAM_RUST_CRATES=$paths" >> $GITHUB_ENV
- name: Check for CHANGELOG.md
run: |
paths="${{ steps.member_paths.outputs.paths }}"
IFS=$'\n' read -r -d '' -a path_array <<< "$paths"
for path in "${path_array[@]}"; do
for crate in $(find $path -name 'Cargo.toml'); do
dir=$(dirname $crate)
if [ ! -f "$dir/CHANGELOG.md" ]; then
echo "Error: $dir/CHANGELOG.md is missing"
exit 1
fi
done
paths="${{ env.OCKAM_RUST_CRATES }}"
for crate in "${paths[@]}"; do
dir=$(dirname $crate)
if [ ! -f "$dir/CHANGELOG.md" ]; then
echo "Error: $dir/CHANGELOG.md is missing"
exit 1
fi
done
- name: Check for README.md
run: |
paths="${{ steps.member_paths.outputs.paths }}"
IFS=$'\n' read -r -d '' -a path_array <<< "$paths"
for path in "${path_array[@]}"; do
for crate in $(find $path -name 'Cargo.toml'); do
dir=$(dirname $crate)
if [ ! -f "$dir/README.md" ]; then
echo "Error: $dir/README.md is missing"
exit 1
fi
done
paths="${{ env.OCKAM_RUST_CRATES }}"
for crate in "${paths[@]}"; do
dir=$(dirname $crate)
if [ ! -f "$dir/README.md" ]; then
echo "Error: $dir/README.md is missing"
exit 1
fi
done
- name: Validate Cargo.toml categories
run: |
allowed_categories="
accessibility
aerospace
aerospace::drones
aerospace::protocols
aerospace::simulation
aerospace::space-protocols
aerospace::unmanned-aerial-vehicles
drones
protocols
simulation
space-protocols
unmanned-aerial-vehicles
algorithms
api-bindings
asynchronous
Expand All @@ -87,19 +83,19 @@ jobs:
concurrency
config
cryptography
cryptography::cryptocurrencies
cryptocurrencies
data-structures
database
database-implementations
date-and-time
development-tools
development-tools::build-utils
development-tools::cargo-plugins
development-tools::debugging
development-tools::ffi
development-tools::procedural-macro-helpers
development-tools::profiling
development-tools::testing
build-utils
cargo-plugins
debugging
ffi
procedural-macro-helpers
profiling
testing
email
embedded
emulators
Expand All @@ -118,20 +114,20 @@ jobs:
mathematics
memory-management
multimedia
multimedia::audio
multimedia::encoding
multimedia::images
multimedia::video
audio
encoding
images
video
network-programming
no-std
no-std::no-alloc
os
os::android-apis
os::freebsd-apis
os::linux-apis
os::macos-apis
os::unix-apis
os::windows-apis
android-apis
freebsd-apis
linux-apis
macos-apis
unix-apis
windows-apis
parser-implementations
parsing
rendering
Expand All @@ -140,13 +136,13 @@ jobs:
rendering::graphics-api
rust-patterns
science
science::bioinformatics
science::bioinformatics::genomics
science::bioinformatics::proteomics
science::bioinformatics::sequence-analysis
science::geo
science::neuroscience
science::robotics
bioinformatics
genomics
proteomics
sequence-analysis
geo
neuroscience
robotics
simulation
template-engine
text-editors
Expand All @@ -156,20 +152,49 @@ jobs:
visualization
wasm
web-programming
web-programming::http-client
web-programming::http-server
web-programming::websocket
http-client
http-server
websocket
"
paths="${{ steps.member_paths.outputs.paths }}"
IFS=$'\n' read -r -d '' -a path_array <<< "$paths"
for path in "${path_array[@]}"; do
for crate in $(find $path -name 'Cargo.toml'); do
categories=$(tomlq package.categories -f "$crate" | jq -r '.[]')
for category in $categories; do
if ! echo "$allowed_categories" | grep -q "$category"; then
echo "Error: $crate contains invalid category $category"
exit 1
fi
done
paths="${{ env.OCKAM_RUST_CRATES }}"
for crate in "${paths[@]}"; do
categories=$(tomlq package.categories -f "$crate" | jq -r '.[]')
for category in $categories; do
if ! echo "$allowed_categories" | grep -q "$category"; then
echo "Error: $crate contains invalid category $category"
exit 1
fi
done
done
- name: Check Cargo.toml To Ensure That All 3rd Party Crates Have Specified Versions
run: |
set -ex
paths="${{ env.OCKAM_RUST_CRATES }}"
regex="^[\^|=]*[0-9]+(\.[0-9]+)*(\.[0-9]+)*$"
for crate in "${path_array[@]}"; do
deps=$(toml2json <<< cat "$crate" | jq -r '.dependencies')
dev_deps=$(toml2json <<< cat "$crate" | jq -r ".\"dev-dependencies\"")
dependencies=$(echo "$deps $dev_deps" | jq -s add)
dependencies=$(toml2json <<< cat "$crate" | jq -r '.dependencies')
dependencies_keys=$(echo $dependencies | jq -r 'keys')
dependencies_keys_len=$(echo $dependencies | jq -r 'keys | length')
for ((i=0; i<$dependencies_keys_len; i++)); do
crate_name=$(jq -r ".[$i]" <<< $dependencies_keys)
version=$(jq -r ".\"$crate_name\".version" <<< $dependencies || jq -r ".\"$crate_name\"" <<< $dependencies)
if [[ $version =~ $regex ]]; then
echo "crate_name: $crate_name"
echo "version: $version"
else
echo "No version found for $crate_name $version"
exit 1
fi
done
done

0 comments on commit 7581877

Please sign in to comment.