ci: add automated hole-punch tests #13804
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Continuous integration | |
on: | |
pull_request: | |
push: | |
branches: | |
- master | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.ref }} | |
cancel-in-progress: true | |
env: | |
SEGMENT_DOWNLOAD_TIMEOUT_MINS: 2 # Fail cache download after 2 minutes. | |
RUSTFLAGS: '-Dwarnings' # Never tolerate warnings. | |
jobs: | |
test: | |
name: Test ${{ matrix.crate }} | |
runs-on: ${{ fromJSON( | |
github.repository == 'libp2p/rust-libp2p' && ( | |
(contains(fromJSON('["libp2p-webrtc", "libp2p"]'), matrix.crate) && '["self-hosted", "linux", "x64", "2xlarge"]') || | |
(contains(fromJSON('["libp2p-quic", "libp2p-perf"]'), matrix.crate) && '["self-hosted", "linux", "x64", "xlarge"]') || | |
'["self-hosted", "linux", "x64", "large"]' | |
) || '"ubuntu-latest"') }} | |
timeout-minutes: 10 | |
needs: gather_published_crates | |
strategy: | |
fail-fast: false | |
matrix: | |
crate: ${{ fromJSON(needs.gather_published_crates.outputs.members) }} | |
env: | |
CRATE: ${{ matrix.crate }} | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- uses: r7kamura/rust-problem-matchers@2c2f1016021a7455a6b5b4bbae31145f3b3cd83a #v1.4.0 | |
- uses: dtolnay/rust-toolchain@stable | |
- uses: Swatinem/rust-cache@3cf7f8cc28d1b4e7d01e3783be10a97d55d483c8 # v2.7.1 | |
with: | |
shared-key: stable-cache | |
save-if: false | |
- name: Run all tests | |
run: cargo test --package "$CRATE" --all-features | |
- name: Check if we compile without any features activated | |
run: cargo build --package "$CRATE" --no-default-features | |
- name: Enforce no dependency on meta crate | |
if: env.CRATE != 'libp2p-server' && env.CRATE != 'libp2p-perf' | |
run: | | |
cargo metadata --format-version=1 --no-deps | \ | |
jq -e -r '.packages[] | select(.name == "'"$CRATE"'") | .dependencies | all(.name != "libp2p")' | |
- uses: taiki-e/cache-cargo-install-action@924d49e0af41f449f0ad549559bc608ee4653562 # v1 | |
with: | |
tool: tomlq | |
- name: Enforce version in `workspace.dependencies` matches latest version | |
if: env.CRATE != 'libp2p' | |
run: | | |
PACKAGE_VERSION=$(cargo metadata --format-version=1 --no-deps | jq -e -r '.packages[] | select(.name == "'"$CRATE"'") | .version') | |
SPECIFIED_VERSION=$(tomlq "workspace.dependencies.$CRATE.version" --file ./Cargo.toml) | |
echo "Package version: $PACKAGE_VERSION"; | |
echo "Specified version: $SPECIFIED_VERSION"; | |
test "$PACKAGE_VERSION" = "$SPECIFIED_VERSION" | |
- name: Ensure manifest and CHANGELOG are properly updated | |
if: > | |
github.event_name == 'pull_request' && | |
!startsWith(github.event.pull_request.title, 'chore') && | |
!startsWith(github.event.pull_request.title, 'refactor') && | |
!startsWith(github.event.pull_request.title, 'deps') && | |
!startsWith(github.event.pull_request.title, 'docs') && | |
!contains(github.event.pull_request.labels.*.name, 'internal-change') | |
run: | | |
git fetch origin master:master | |
./scripts/ensure-version-bump-and-changelog.sh | |
env: | |
HEAD_SHA: ${{ github.event.pull_request.head.sha }} | |
wasm_tests: | |
name: Run all WASM tests | |
runs-on: ubuntu-latest | |
env: | |
CHROMEDRIVER_VERSION: '114.0.5735.90' | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: dtolnay/rust-toolchain@stable | |
with: | |
target: wasm32-unknown-unknown | |
- uses: taiki-e/cache-cargo-install-action@v1 | |
with: | |
tool: [email protected] | |
- name: Install Google Chrome | |
run: | | |
curl -o /tmp/google-chrome-stable_amd64.deb https://dl.google.com/linux/chrome/deb/pool/main/g/google-chrome-stable/google-chrome-stable_${CHROMEDRIVER_VERSION}-1_amd64.deb | |
sudo dpkg -i /tmp/google-chrome-stable_amd64.deb | |
- name: Install chromedriver | |
uses: nanasess/setup-chromedriver@v2 | |
with: | |
chromedriver-version: ${{ env.CHROMEDRIVER_VERSION }} | |
- name: Run all tests | |
run: ./wasm-tests/run-all.sh | |
cross: | |
name: Compile on ${{ matrix.target }} | |
strategy: | |
matrix: | |
include: | |
- target: "wasm32-unknown-unknown" | |
os: ubuntu-latest | |
- target: "wasm32-unknown-emscripten" | |
os: ubuntu-latest | |
- target: "wasm32-wasi" | |
os: ubuntu-latest | |
- target: "x86_64-apple-darwin" | |
os: macos-latest | |
- target: "x86_64-pc-windows-msvc" | |
os: windows-latest | |
runs-on: ${{ matrix.os }} | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: dtolnay/rust-toolchain@stable | |
with: | |
target: ${{ matrix.target }} | |
- uses: r7kamura/rust-problem-matchers@2c2f1016021a7455a6b5b4bbae31145f3b3cd83a #v1.4.0 | |
- uses: Swatinem/rust-cache@3cf7f8cc28d1b4e7d01e3783be10a97d55d483c8 # v2.7.1 | |
with: | |
key: ${{ matrix.target }} | |
save-if: ${{ github.ref == 'refs/heads/master' }} | |
- run: cargo check --package libp2p --all-features --target=${{ matrix.target }} | |
msrv: | |
name: Compile with MSRV | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Extract MSRV from workspace manifest | |
shell: bash | |
run: | | |
MSRV=$(grep -oP 'rust-version\s*=\s*"\K[^"]+' Cargo.toml) | |
echo "MSRV=$MSRV" >> $GITHUB_ENV | |
- uses: dtolnay/rust-toolchain@master | |
with: | |
toolchain: ${{ env.MSRV }} | |
- uses: r7kamura/rust-problem-matchers@2c2f1016021a7455a6b5b4bbae31145f3b3cd83a #v1.4.0 | |
- uses: Swatinem/rust-cache@3cf7f8cc28d1b4e7d01e3783be10a97d55d483c8 # v2.7.1 | |
with: | |
save-if: ${{ github.ref == 'refs/heads/master' }} | |
- run: cargo +$MSRV check --workspace --all-features | |
feature_matrix: # Test various feature combinations work correctly | |
name: Compile with select features (${{ matrix.features }}) | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
include: | |
- features: "mdns tcp dns tokio" | |
- features: "mdns tcp dns async-std" | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: dtolnay/rust-toolchain@stable | |
- uses: r7kamura/rust-problem-matchers@2c2f1016021a7455a6b5b4bbae31145f3b3cd83a #v1.4.0 | |
- uses: Swatinem/rust-cache@3cf7f8cc28d1b4e7d01e3783be10a97d55d483c8 # v2.7.1 | |
with: | |
key: ${{ matrix.features }} | |
save-if: ${{ github.ref == 'refs/heads/master' }} | |
- run: cargo check --package libp2p --features="${{ matrix.features }}" | |
check-rustdoc-links: | |
name: Check rustdoc intra-doc links | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: dtolnay/rust-toolchain@stable | |
- uses: r7kamura/rust-problem-matchers@2c2f1016021a7455a6b5b4bbae31145f3b3cd83a #v1.4.0 | |
- uses: Swatinem/rust-cache@3cf7f8cc28d1b4e7d01e3783be10a97d55d483c8 # v2.7.1 | |
with: | |
save-if: ${{ github.ref == 'refs/heads/master' }} | |
- name: Check rustdoc links | |
run: RUSTDOCFLAGS="--deny rustdoc::broken_intra_doc_links --deny warnings" cargo doc --verbose --workspace --no-deps --all-features --document-private-items | |
clippy: | |
runs-on: ubuntu-latest | |
strategy: | |
fail-fast: false | |
matrix: | |
rust-version: [ | |
# 1.72.0, # current stable | |
# beta, | |
nightly-2023-09-10 | |
] | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: dtolnay/rust-toolchain@master | |
with: | |
toolchain: ${{ matrix.rust-version }} | |
components: clippy | |
- uses: r7kamura/rust-problem-matchers@2c2f1016021a7455a6b5b4bbae31145f3b3cd83a #v1.4.0 | |
- uses: Swatinem/rust-cache@3cf7f8cc28d1b4e7d01e3783be10a97d55d483c8 # v2.7.1 | |
with: | |
save-if: ${{ github.ref == 'refs/heads/master' }} | |
- run: cargo clippy --all-targets --all-features | |
ipfs-integration-test: | |
name: IPFS Integration tests | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: dtolnay/rust-toolchain@stable | |
- uses: r7kamura/rust-problem-matchers@2c2f1016021a7455a6b5b4bbae31145f3b3cd83a #v1.4.0 | |
- uses: Swatinem/rust-cache@3cf7f8cc28d1b4e7d01e3783be10a97d55d483c8 # v2.7.1 | |
with: | |
save-if: ${{ github.ref == 'refs/heads/master' }} | |
- name: Run ipfs-kad example - get peers | |
run: cd ./examples/ipfs-kad/ && RUST_LOG=libp2p_swarm=debug,libp2p_kad=trace,libp2p_tcp=debug cargo run -- get-peers | |
- name: Run ipfs-kad example - put PK record | |
run: cd ./examples/ipfs-kad/ && RUST_LOG=libp2p_swarm=debug,libp2p_kad=trace,libp2p_tcp=debug cargo run -- put-pk-record | |
examples: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: dtolnay/rust-toolchain@stable | |
- uses: r7kamura/rust-problem-matchers@2c2f1016021a7455a6b5b4bbae31145f3b3cd83a #v1.4.0 | |
- uses: Swatinem/rust-cache@3cf7f8cc28d1b4e7d01e3783be10a97d55d483c8 # v2.7.1 | |
with: | |
shared-key: stable-cache | |
save-if: false | |
- name: Compile all examples | |
run: | | |
set -e; | |
for toml in examples/**/Cargo.toml; do | |
cargo check --manifest-path "$toml"; | |
done | |
semver: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- run: wget -q -O- https://github.com/obi1kenobi/cargo-semver-checks/releases/download/v0.24.0/cargo-semver-checks-x86_64-unknown-linux-gnu.tar.gz | tar -xz -C ~/.cargo/bin | |
shell: bash | |
- uses: obi1kenobi/cargo-semver-checks-action@e275dda72e250d4df5b564e969e1348d67fefa52 # v2 | |
rustfmt: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: dtolnay/rust-toolchain@stable | |
with: | |
components: rustfmt | |
- uses: r7kamura/rust-problem-matchers@2c2f1016021a7455a6b5b4bbae31145f3b3cd83a #v1.4.0 | |
- name: Check formatting | |
run: cargo fmt -- --check | |
manifest_lint: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: dtolnay/rust-toolchain@stable | |
- uses: r7kamura/rust-problem-matchers@2c2f1016021a7455a6b5b4bbae31145f3b3cd83a #v1.4.0 | |
- name: Ensure `full` feature contains all features | |
run: | | |
ALL_FEATURES=$(cargo metadata --format-version=1 --no-deps | jq -r '.packages[] | select(.name == "libp2p") | .features | keys | map(select(. != "full")) | sort | join(" ")') | |
FULL_FEATURE=$(cargo metadata --format-version=1 --no-deps | jq -r '.packages[] | select(.name == "libp2p") | .features["full"] | sort | join(" ")') | |
test "$ALL_FEATURES = $FULL_FEATURE" | |
echo "$ALL_FEATURES"; | |
echo "$FULL_FEATURE"; | |
test "$ALL_FEATURES" = "$FULL_FEATURE" | |
gather_published_crates: | |
runs-on: ubuntu-latest | |
outputs: | |
members: ${{ steps.cargo-metadata.outputs.members }} | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: dtolnay/rust-toolchain@stable | |
- id: cargo-metadata | |
run: | | |
WORKSPACE_MEMBERS=$(cargo metadata --format-version=1 --no-deps | jq -c '.packages | map(select(.publish == null) | .name)') | |
echo "members=${WORKSPACE_MEMBERS}" >> $GITHUB_OUTPUT | |
check-proto-files: | |
name: Check for changes in proto files | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: Swatinem/rust-cache@3cf7f8cc28d1b4e7d01e3783be10a97d55d483c8 # v2.7.1 | |
- run: cargo install --version 0.10.0 pb-rs --locked | |
- name: Glob match | |
uses: tj-actions/glob@v17 | |
id: glob | |
with: | |
files: | | |
**/generated/*.proto | |
- name: Generate proto files | |
run: pb-rs --dont_use_cow ${{ steps.glob.outputs.paths }} | |
- name: Ensure generated files are unmodified # https://stackoverflow.com/a/5737794 | |
run: | | |
git_status=$(git status --porcelain) | |
echo $git_status | |
test -z "$git_status" | |
ensure-lockfile-uptodate: | |
name: Ensure that `Cargo.lock` is up-to-date | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: Swatinem/rust-cache@3cf7f8cc28d1b4e7d01e3783be10a97d55d483c8 # v2.7.1 | |
- run: cargo metadata --locked --format-version=1 > /dev/null | |
cargo-deny: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: EmbarkStudios/cargo-deny-action@v1 | |
with: | |
command: check advisories bans licenses sources |