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

Improve CI, update actions to match tanssi repo #27

Merged
merged 5 commits into from
Jul 17, 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
43 changes: 43 additions & 0 deletions .cargo/zepter.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# This file should be kept updated with the upstream config file:
# https://github.com/paritytech/polkadot-sdk/blob/master/.config/zepter.yaml

version:
format: 1
# Minimum version of the binary that is expected to work. This is just for printing a nice error
# message when someone tries to use an older version.
binary: 0.13.2

# The examples in this file assume crate `A` to have a dependency on crate `B`.
workflows:
check:
- [
'lint',
# Check that `A` activates the features of `B`.
'propagate-feature',
# These are the features to check:
'--features=try-runtime,runtime-benchmarks,std',
# Do not try to add a new section into `[features]` of `A` only because `B` expose that feature. There are edge-cases where this is still needed, but we can add them manually.
'--left-side-feature-missing=ignore',
# Ignore the case that `A` it outside of the workspace. Otherwise it will report errors in external dependencies that we have no influence on.
'--left-side-outside-workspace=ignore',
# Some features imply that they activate a specific dependency as non-optional. Otherwise the default behaviour with a `?` is used.
'--feature-enables-dep=try-runtime:frame-try-runtime,runtime-benchmarks:frame-benchmarking',
# Auxillary flags:
'--offline',
'--locked',
'--show-path',
'--quiet',
]
# Same as `check`, but with the `--fix` flag.
default:
- [ $check.0, '--fix' ]

# Will be displayed when any workflow fails:
help:
text: |
Polkadot-SDK uses the Zepter CLI to detect abnormalities in the feature configuration.
It looks like one more more checks failed; please check the console output. You can try to automatically address them by running `zepter`.
Otherwise please ask directly in the Merge Request, GitHub Discussions or on Matrix Chat, thank you.
links:
- "https://github.com/paritytech/polkadot-sdk/issues/1831"
- "https://github.com/ggwpez/zepter"
34 changes: 34 additions & 0 deletions .github/scripts/check_toml_lints.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/bin/bash

# Script to check that all the Cargo.toml files in the repo have an entry with
# [lints] workspace = true
# (except the root Cargo.toml, which should have the list of lints)
# If a Cargo.toml does not have this entry, running cargo clippy will use the
# default lints instead of our lints, which can lead to false positives and
# false negatives.

# Always run the commands from the "tanssi" dir
cd $(dirname $0)/../..

# Initialize a flag to indicate failure
failure=0

# List files tracked by git, excluding those ignored by .gitignore
git ls-files | grep '^.*/Cargo.toml$' | while read -r file; do
# Check if the file contains the [lints]\nworkspace = true pattern
if ! grep -Pzoq "\[lints]\nworkspace = true" "$file"; then
# If the pattern is not found, print a message and set the failure flag
echo "Missing [lints] workspace = true in $file"
failure=1
else
:;
# If found, print a confirmation message (optional)
#echo "[lints] workspace = true found in $file"
fi
done

# Exit with a non-zero status if any Cargo.toml file was missing the required lines
if [ "$failure" -eq 1 ]; then
exit 1
fi

10 changes: 5 additions & 5 deletions .github/workflow-templates/cargo-build/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ runs:
shell: bash
run: |
mkdir -p mold
curl -L --retry 10 --silent --show-error https://github.com/rui314/mold/releases/download/v1.1.1/mold-1.1.1-$(uname -m)-linux.tar.gz | tar -C $(realpath mold) --strip-components=1 -xzf -
wget https://github.com/rui314/mold/releases/download/v2.30.0/mold-2.30.0-$(uname -m)-linux.tar.gz -O - | tar -C $(realpath mold) --strip-components=1 -xzf -
# With rustup's nice new toml format, we just need to run rustup show to install the toolchain
# https://github.com/actions-rs/toolchain/issues/126#issuecomment-782989659
- name: Setup Rust toolchain
Expand All @@ -40,9 +40,9 @@ runs:
shell: bash
run: |
env
params=" --release"
if [ -n "${{ github.event.inputs.features }}" ]; then
params="$params --features ${{ github.event.inputs.features }}"
params=" --locked --release"
if [ -n "${{ inputs.features }}" ]; then
params="$params --features ${{ inputs.features }}"
fi
echo "cargo build $params"
cargo build $params
cargo build $params
80 changes: 54 additions & 26 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ jobs:
echo "git_ref=$GITHUB_REF" >> $GITHUB_OUTPUT
fi

- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
ref: ${{ steps.check-git-ref.outputs.git_ref }}
- name: Get Sha
Expand All @@ -77,7 +77,7 @@ jobs:
needs: ["set-tags"]
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
ref: ${{ needs.set-tags.outputs.git_ref }}
- name: Find un-copyrighted files
Expand All @@ -95,7 +95,7 @@ jobs:
needs: ["set-tags"]
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
ref: ${{ needs.set-tags.outputs.git_ref }}
- uses: gaurav-nelson/github-action-markdown-link-check@v1
Expand All @@ -109,63 +109,91 @@ jobs:
needs: ["set-tags"]
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
ref: ${{ needs.set-tags.outputs.git_ref }}
# With rustup's nice new toml format, we just need to run rustup show to install the toolchain
# https://github.com/actions-rs/toolchain/issues/126#issuecomment-782989659
- name: Setup Rust toolchain
run: rustup show
- name: Format code with rustfmt
run: cargo fmt -- --check
run: cargo fmt --all --check

####### Building and Testing binaries #######
####### Static Analyses #######

cargo-clippy:
runs-on:
labels: ubuntu-latest
runs-on: ubuntu-latest
needs: ["set-tags"]
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
ref: ${{ needs.set-tags.outputs.git_ref }}

- name: Setup Rust toolchain
run: rustup show

- name: Find toml files with lints key not set
run: ./.github/scripts/check_toml_lints.sh

- name: Install Protoc
uses: arduino/setup-protoc@v1

- name: Clippy
run: SKIP_WASM_BUILD=1 cargo clippy --all-targets --locked --workspace --features try-runtime,runtime-benchmarks

cargo-toml-feature-propagation:
runs-on: ubuntu-latest
needs: ["set-tags"]
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ needs.set-tags.outputs.git_ref }}

- name: Setup Rust toolchain
run: rustup show
- name: Clippy
run: SKIP_WASM_BUILD=1 env -u RUSTFLAGS cargo clippy --features try-runtime,runtime-benchmarks

build:
runs-on:
labels: ubuntu-latest
- name: Install zepter
run: cargo install --locked -f zepter --version 1.1.0

- name: Run zepter
run: zepter run check

toml-formatting:
runs-on: ubuntu-latest
needs: ["set-tags"]
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
ref: ${{ needs.set-tags.outputs.git_ref }}
- name: Install Protoc
uses: arduino/setup-protoc@v1
- name: Cargo build
uses: ./.github/workflow-templates/cargo-build

build-features:
- name: Setup Rust toolchain
run: rustup show

- name: Install toml-maid
run: cargo install --locked -f toml-maid

- name: Run toml-maid
run: toml-maid --check


####### Building and Testing binaries #######

build:
runs-on:
labels: ubuntu-latest
needs: ["set-tags"]
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
ref: ${{ needs.set-tags.outputs.git_ref }}
- name: Install Protoc
uses: arduino/setup-protoc@v1
- name: Cargo build
uses: ./.github/workflow-templates/cargo-build
with:
features: "try-runtime,runtime-benchmarks"

rust-test:
runs-on:
Expand All @@ -177,7 +205,7 @@ jobs:
SCCACHE_CACHE_SIZE: "100GB"
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
ref: ${{ needs.set-tags.outputs.git_ref }}
- name: Install Protoc
Expand All @@ -192,7 +220,7 @@ jobs:
shell: bash
run: |
mkdir -p mold
curl -L --retry 10 --silent --show-error https://github.com/rui314/mold/releases/download/v1.1.1/mold-1.1.1-$(uname -m)-linux.tar.gz | tar -C $(realpath mold) --strip-components=1 -xzf -
curl -L --retry 10 --silent --show-error https://github.com/rui314/mold/releases/download/v2.30.0/mold-2.30.0-$(uname -m)-linux.tar.gz | tar -C $(realpath mold) --strip-components=1 -xzf -
# With rustup's nice new toml format, we just need to run rustup show to install the toolchain
# https://github.com/actions-rs/toolchain/issues/126#issuecomment-782989659
- name: Setup Rust toolchain
Expand All @@ -206,4 +234,4 @@ jobs:
run: |
cargo test --release --all
- name: Run sccache stat for check pre test
run: ${SCCACHE_PATH} --show-stats
run: ${SCCACHE_PATH} --show-stats
6 changes: 6 additions & 0 deletions .rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Must be run in nightly:
# cargo +nightly fmt

reorder_imports = true
max_width = 100
imports_granularity = "One"
1 change: 1 addition & 0 deletions Cargo.lock

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

25 changes: 25 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,31 @@ resolver = "2"
authors = [ "Moondance Labs" ]
repository = "https://github.com/moondance-labs/dancekit"

[workspace.lints.clippy]
# Deny main lint groups
complexity = { level = "deny", priority = 1 }
correctness = { level = "deny", priority = 1 }
suspicious = { level = "deny", priority = 1 }

# Add some additional lints
as_underscore = { level = "warn", priority = 1 }
cast_lossless = { level = "warn", priority = 1 }
cast_possible_wrap = { level = "warn", priority = 1 }
cast_precision_loss = { level = "warn", priority = 1 }
cast_sign_loss = { level = "warn", priority = 1 }
debug_assert_with_mut_call = { level = "warn", priority = 1 }
fn_to_numeric_cast_any = { level = "warn", priority = 1 }
invalid_upcast_comparisons = { level = "warn", priority = 1 }

# Allow annoying lints and false positives
erasing_op = { level = "allow", priority = 2 }
identity_op = { level = "allow", priority = 2 }
too-many-arguments = { level = "allow", priority = 2 }
type_complexity = { level = "allow", priority = 2 }

[workspace.lints.rust]
unsafe-code = { level = "deny", priority = 1 }

[workspace.dependencies]

ccp-authorities-noting-inherent = { path = "container-chain-primitives/authorities-noting-inherent", default-features = false }
Expand Down
3 changes: 3 additions & 0 deletions client/orchestrator-chain-interface/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ edition = "2021"
license = "GPL-3.0-only"
version = "0.1.0"

[lints]
workspace = true

[dependencies]
async-trait = { workspace = true }
futures = { workspace = true }
Expand Down
39 changes: 35 additions & 4 deletions container-chain-pallets/authorities-noting/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ version = "0.1.0"

[package.metadata.docs.rs]
targets = [ "x86_64-unknown-linux-gnu" ]

[lints]
workspace = true

[dependencies]
hex = { workspace = true, optional = true, features = [ "alloc" ] }
log = { workspace = true }
Expand Down Expand Up @@ -55,24 +59,51 @@ std = [
"ccp-authorities-noting-inherent/std",
"cumulus-pallet-parachain-system/std",
"cumulus-primitives-core/std",
"dp-chain-state-snapshot/std",
"dp-collator-assignment/std",
"dp-core/std",
"frame-benchmarking/std",
"frame-support/std",
"frame-system/std",
"hex",
"hex?/std",
"log/std",
"nimbus-primitives/std",
"parity-scale-codec/std",
"polkadot-parachain-primitives/std",
"polkadot-primitives/std",
"scale-info/std",
"serde",
"serde?/std",
"sp-consensus-aura/std",
"sp-core/std",
"sp-externalities/std",
"sp-inherents/std",
"sp-io/std",
"sp-runtime/std",
"sp-state-machine/std",
"sp-std/std",
"sp-trie/std",
"dp-chain-state-snapshot/std",
"dp-collator-assignment/std",
"dp-core/std",
"sp-version/std",
"test-relay-sproof-builder/std",
]
runtime-benchmarks = [
"cumulus-pallet-parachain-system/runtime-benchmarks",
"cumulus-primitives-core/runtime-benchmarks",
"frame-benchmarking",
"frame-benchmarking/runtime-benchmarks",
"frame-support/runtime-benchmarks",
"frame-system/runtime-benchmarks",
"hex",
"nimbus-primitives/runtime-benchmarks",
"polkadot-parachain-primitives/runtime-benchmarks",
"polkadot-primitives/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
]
try-runtime = [
"cumulus-pallet-parachain-system/try-runtime",
"frame-support/try-runtime",
"frame-system/try-runtime",
"nimbus-primitives/try-runtime",
"sp-runtime/try-runtime",
]
try-runtime = [ "frame-support/try-runtime" ]
Loading
Loading