Skip to content

Commit

Permalink
ci: install protoc from repositories where possible (#3258)
Browse files Browse the repository at this point in the history
With the addition of more CI jobs, we are constantly running into API limits on setting up protoc. For all jobs that run on ubuntu, we can install it from `apt` instead.

On ubuntu 22.04, which is what `ubuntu-latest` points to, this installs `protoc v3.12.4`.

(cherry picked from commit 68d0f88)

# Conflicts:
#	.github/workflows/cache-factory.yml
#	.github/workflows/ci.yml
  • Loading branch information
thomaseizinger authored and mergify[bot] committed Feb 15, 2023
1 parent ace63fe commit 75d491d
Show file tree
Hide file tree
Showing 2 changed files with 228 additions and 0 deletions.
80 changes: 80 additions & 0 deletions .github/workflows/cache-factory.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# This workflow _produces_ caches which are used to speed up pull request builds.
# The caches are split by Rust version (stable vs MSRV per crate) because those caches cannot share any artifacts.

name: Cache factory

on:
push:
branches:
- master # Caches are only created on master branch.

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
gather_msrv_versions:
runs-on: ubuntu-latest
outputs:
versions: ${{ steps.find-rust-versions.outputs.versions }}
steps:
- uses: actions/checkout@v3

- id: find-rust-versions
run: |
RUST_VERSIONS=$(cargo metadata --format-version=1 --no-deps | jq -c '.packages | map(.rust_version) | unique | del(..|nulls)')
echo "versions=${RUST_VERSIONS}" >> $GITHUB_OUTPUT
make_msrv_cache:
runs-on: ubuntu-latest
needs: gather_msrv_versions
strategy:
fail-fast: false
matrix:
rust: ${{ fromJSON(needs.gather_msrv_versions.outputs.versions) }}
steps:
- name: Install Protoc
run: sudo apt-get install protobuf-compiler

- uses: actions/checkout@v3

- uses: actions-rs/toolchain@16499b5e05bf2e26879000db0c1d13f7e13fa3af # v1.0.7
with:
toolchain: ${{ matrix.rust }}
override: true

- uses: Swatinem/rust-cache@359a70e43a0bb8a13953b04a90f76428b4959bb6 # v2.2.0
with:
shared-key: msrv-cache

- name: Compile all crates which have MSRV ${{ matrix.rust }}
run: |
cargo metadata --format-version=1 --no-deps | \
jq -r '.packages[] | select(.rust_version == "${{ matrix.rust }}") | "+\(.rust_version) build --all-features --package \(.name)"' |
xargs --verbose -L 1 cargo
make_stable_rust_cache:
runs-on: ubuntu-latest
steps:
- name: Install Protoc
run: sudo apt-get install protobuf-compiler

- uses: actions/checkout@v3

- uses: actions-rs/toolchain@16499b5e05bf2e26879000db0c1d13f7e13fa3af # v1.0.7
with:
toolchain: stable
override: true

- uses: Swatinem/rust-cache@359a70e43a0bb8a13953b04a90f76428b4959bb6 # v2.2.0
with:
shared-key: stable-cache

- name: Compile workspace with stable Rust
run: cargo test --all-features --all-targets --workspace --no-run

- name: Render docs
run: cargo doc --all-features --workspace

- name: Install tools
run: cargo install cargo-semver-checks --locked
148 changes: 148 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,126 @@ on:
- master

jobs:
<<<<<<< HEAD
test-desktop:
name: Build and test
=======
test:
name: Test ${{ matrix.crate }}
runs-on: ubuntu-latest
needs: gather_published_crates
strategy:
fail-fast: false
matrix:
crate: ${{ fromJSON(needs.gather_published_crates.outputs.members) }}
steps:
- name: Install Protoc
run: sudo apt-get install protobuf-compiler

- uses: actions/checkout@v3

- name: Get MSRV for ${{ matrix.crate }}
id: parse-msrv
run: |
RUST_VERSION=$(cargo metadata --format-version=1 --no-deps | jq -r '.packages[] | select(.name == "${{ matrix.crate }}") | .rust_version')
echo "version=${RUST_VERSION}" >> $GITHUB_OUTPUT
- name: Install Rust ${{ steps.parse-msrv.outputs.version }} for MSRV check
uses: actions-rs/toolchain@16499b5e05bf2e26879000db0c1d13f7e13fa3af # v1.0.7
with:
profile: minimal
toolchain: ${{ steps.parse-msrv.outputs.version }}
override: true

- uses: Swatinem/rust-cache@359a70e43a0bb8a13953b04a90f76428b4959bb6 # v2.2.0
with:
shared-key: msrv-cache
save-if: false

- name: Check if ${{ matrix.crate }} compiles on MSRV (Rust ${{ steps.parse-msrv.outputs.version }})
run: cargo +${{ steps.parse-msrv.outputs.version }} build --package ${{ matrix.crate }} --all-features

- uses: actions-rs/toolchain@16499b5e05bf2e26879000db0c1d13f7e13fa3af # v1.0.7
with:
profile: minimal
toolchain: stable
override: true

- uses: Swatinem/rust-cache@359a70e43a0bb8a13953b04a90f76428b4959bb6 # v2.2.0
with:
shared-key: stable-cache
save-if: false

- name: Run all tests
run: cargo test --package ${{ matrix.crate }} --all-features

- name: Check if we compile without any features activated
run: cargo build --package ${{ matrix.crate }} --no-default-features

- name: Check if crate has been released
id: check-released
run: |
RESPONSE_CODE=$(curl https://crates.io/api/v1/crates/${{ matrix.crate }} --silent --write-out "%{http_code}" --output /dev/null)
echo "code=${RESPONSE_CODE}"
echo "code=${RESPONSE_CODE}" >> $GITHUB_OUTPUT
- name: Check public API for semver violations
if: steps.check-released.outputs.code == 200 # Workaround until https://github.com/obi1kenobi/cargo-semver-check/issues/146 is shipped.
run: |
cargo install cargo-semver-checks --locked
cargo semver-checks check-release -p ${{ matrix.crate }}
- name: Enforce no dependency on meta crate
run: |
cargo metadata --format-version=1 --no-deps | \
jq -e -r '.packages[] | select(.name == "${{ matrix.crate }}") | .dependencies | all(.name != "libp2p")'
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:
- name: Install Protoc
if: ${{ matrix.os != 'ubuntu-latest' }}
uses: arduino/setup-protoc@64c0c85d18e984422218383b81c52f8b077404d3 # v1.1.2
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}

- name: Install Protoc
if: ${{ matrix.os == 'ubuntu-latest' }}
run: sudo apt-get install protobuf-compiler

- uses: actions/checkout@v3

- uses: actions-rs/toolchain@16499b5e05bf2e26879000db0c1d13f7e13fa3af # v1.0.7
with:
profile: minimal
toolchain: stable
override: true
target: ${{ matrix.target }}

- uses: Swatinem/rust-cache@359a70e43a0bb8a13953b04a90f76428b4959bb6 # v2.2.0
with:
key: ${{ matrix.target }}
save-if: ${{ github.ref == 'refs/heads/master' }}

- run: cargo check --package libp2p --all-features --target=${{ matrix.target }}

feature_matrix: # Test various feature combinations work correctly
name: Compile with select features (${{ matrix.features }})
>>>>>>> 68d0f882 (ci: install `protoc` from repositories where possible (#3258))
runs-on: ubuntu-latest
strategy:
matrix:
Expand All @@ -18,6 +136,11 @@ jobs:
"--benches --all-features",
]
steps:
<<<<<<< HEAD
=======
- name: Install Protoc
run: sudo apt-get install protobuf-compiler
>>>>>>> 68d0f882 (ci: install `protoc` from repositories where possible (#3258))

- name: Cancel Previous Runs
uses: styfle/cancel-workflow-action@bb6001c4ea612bf59c3abfc4756fbceee4f870c7 # 0.10.0
Expand Down Expand Up @@ -91,6 +214,11 @@ jobs:
name: Check rustdoc intra-doc links
runs-on: ubuntu-latest
steps:
<<<<<<< HEAD
=======
- name: Install Protoc
run: sudo apt-get install protobuf-compiler
>>>>>>> 68d0f882 (ci: install `protoc` from repositories where possible (#3258))

- name: Cancel Previous Runs
uses: styfle/cancel-workflow-action@bb6001c4ea612bf59c3abfc4756fbceee4f870c7 # 0.10.0
Expand All @@ -108,14 +236,34 @@ jobs:
toolchain: stable
override: true

<<<<<<< HEAD
- uses: Swatinem/rust-cache@6720f05bc48b77f96918929a9019fb2203ff71f8 # v2.0.0
=======
clippy:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
rust-version: [
stable,
beta
]
steps:
- name: Install Protoc
run: sudo apt-get install protobuf-compiler
>>>>>>> 68d0f882 (ci: install `protoc` from repositories where possible (#3258))

- 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

check-clippy:
runs-on: ubuntu-latest
steps:
<<<<<<< HEAD
=======
- name: Install Protoc
run: sudo apt-get install protobuf-compiler
>>>>>>> 68d0f882 (ci: install `protoc` from repositories where possible (#3258))

- name: Cancel Previous Runs
uses: styfle/cancel-workflow-action@bb6001c4ea612bf59c3abfc4756fbceee4f870c7 # 0.10.0
Expand Down

0 comments on commit 75d491d

Please sign in to comment.