Browse Source

use shell script for CI tasks

Thibaut Vandervelden 1 year ago
parent
commit
68a67fa2d5
3 changed files with 148 additions and 91 deletions
  1. 0 25
      .github/workflows/clippy.yml
  2. 42 66
      .github/workflows/test.yml
  3. 106 0
      ci.sh

+ 0 - 25
.github/workflows/clippy.yml

@@ -1,25 +0,0 @@
-on:
-  push:
-    branches: [ staging, trying ]
-  pull_request_target:
-
-name: Clippy check
-jobs:
-  clippy:
-    runs-on: ubuntu-latest
-    permissions:
-      checks: write
-    steps:
-      - uses: actions/checkout@v2
-        if: github.event_name == 'pull_request_target'
-        with:
-          ref: refs/pull/${{ github.event.number }}/head
-      - uses: actions/checkout@v2
-        if: github.event_name != 'pull_request_target'
-      - run: sed -n 's,^rust-version = "\(.*\)"$,RUSTUP_TOOLCHAIN=\1,p' Cargo.toml >> $GITHUB_ENV
-      - run: rustup toolchain install $RUSTUP_TOOLCHAIN
-      - run: rustup component add clippy
-      - uses: actions-rs/clippy-check@v1
-        with:
-          token: ${{ secrets.GITHUB_TOKEN }}
-          args: --tests --examples -- -D warnings

+ 42 - 66
.github/workflows/test.yml

@@ -8,82 +8,58 @@ name: Test
 jobs:
   tests:
     runs-on: ubuntu-22.04
-    needs: [test, check]
+    needs: [check-msrv, test-msrv, test-stable, clippy]
     steps:
       - name: Done
         run: exit 0
-  test:
-    runs-on: ubuntu-22.04
-    continue-on-error: ${{ matrix.rust == 'nightly' }}
-    strategy:
-      matrix:
-        # Test on stable, MSRV, and nightly.
-        # Failure is permitted on nightly.
-        rust:
-          #- stable  # TODO: enable again when "stable" is 1.66 or higher.
-          - 1.65.0
-          - nightly
-
-        features:
-          # Test default features.
-          - default
-
-          # Test minimal featureset
-          - std proto-ipv4
-
-          # Test features chosen to be as orthogonal as possible.
-          - std medium-ethernet phy-raw_socket proto-ipv6 socket-udp socket-dns
-          - std medium-ethernet phy-tuntap_interface proto-ipv6 socket-udp
-          - std medium-ethernet proto-ipv4 proto-ipv4-fragmentation socket-raw socket-dns
-          - std medium-ethernet proto-ipv4 proto-igmp socket-raw socket-dns
-          - std medium-ethernet proto-ipv4 socket-udp socket-tcp socket-dns
-          - std medium-ethernet proto-ipv4 proto-dhcpv4 socket-udp
-          - std medium-ethernet medium-ip medium-ieee802154 proto-ipv6 socket-udp socket-dns
-          - std medium-ethernet proto-ipv6 socket-tcp
-          - std medium-ethernet medium-ip proto-ipv4 socket-icmp socket-tcp
-          - std medium-ip proto-ipv6 socket-icmp socket-tcp
-          - std medium-ieee802154 proto-sixlowpan socket-udp
-          - std medium-ieee802154 proto-sixlowpan proto-sixlowpan-fragmentation socket-udp
-          - std medium-ip proto-ipv4 proto-ipv6 socket-tcp socket-udp
 
-          # Test features chosen to be as aggressive as possible.
-          - std medium-ethernet medium-ip medium-ieee802154 proto-ipv4 proto-ipv6 socket-raw socket-udp socket-tcp socket-icmp socket-dns async
+  check-msrv:
+    runs-on: ubuntu-22.04
+    steps:
+      - uses: actions/checkout@v2
+      - name: Run Checks MSRV
+        run: ./ci.sh check msrv
 
-        include:
-          # Test alloc feature which requires nightly.
-          - rust: nightly
-            features: alloc medium-ethernet proto-ipv4 proto-ipv6 socket-raw socket-udp socket-tcp socket-icmp
-    env:
-      RUSTUP_TOOLCHAIN: "${{ matrix.rust }}"
+  test-msrv:
+    runs-on: ubuntu-22.04
     steps:
       - uses: actions/checkout@v2
-      - name: Run Tests
-        run: cargo test --no-default-features --features "${{ matrix.features }}"
+      - name: Run Tests MSRV
+        run: ./ci.sh test msrv
 
-  check:
+  clippy:
     runs-on: ubuntu-22.04
-    continue-on-error: ${{ matrix.rust == 'nightly' }}
-    strategy:
-      matrix:
-        # Test on stable, MSRV, and nightly.
-        # Failure is permitted on nightly.
-        rust:
-          #- stable  # TODO: enable again when "stable" is 1.66 or higher.
-          - 1.65.0
-          - nightly
+    steps:
+      - uses: actions/checkout@v2
+      - name: Run Clippy
+        run: ./ci.sh clippy
 
-        features:
-          # These feature sets cannot run tests, so we only check they build.
-          - medium-ip medium-ethernet medium-ieee802154 proto-ipv6 proto-ipv6 proto-igmp proto-dhcpv4 socket-raw socket-udp socket-tcp socket-icmp socket-dns async
-          - defmt medium-ip medium-ethernet proto-ipv6 proto-ipv6 proto-igmp proto-dhcpv4 socket-raw socket-udp socket-tcp socket-icmp socket-dns async
-          - defmt alloc medium-ip medium-ethernet proto-ipv6 proto-ipv6 proto-igmp proto-dhcpv4 socket-raw socket-udp socket-tcp socket-icmp socket-dns async
+  test-stable:
+    runs-on: ubuntu-22.04
+    steps:
+      - uses: actions/checkout@v2
+      - name: Run Tests stable
+        run: ./ci.sh test stable
 
-    env:
-      # Set DEFMT_LOG to trace so that all net_{error, .., trace} messages
-      # are actually compiled and verified
-      DEFMT_LOG: "trace"
-      RUSTUP_TOOLCHAIN: "${{ matrix.rust }}"
+  test-nightly:
+    runs-on: ubuntu-22.04
+    continue-on-error: true
     steps:
       - uses: actions/checkout@v2
-      - name: Check
-        run: cargo check --no-default-features --features "${{ matrix.features }}"
+      - name: Run Tests nightly
+        run: ./ci.sh test nightly
+
+  #check-stable:
+    #runs-on: ubuntu-22.04
+    #steps:
+      #- uses: actions/checkout@v2
+      #- name: Run Tests
+        #run: ./ci.sh check stable
+
+  #check-nightly:
+    #runs-on: ubuntu-22.04
+    #continue-on-error: true
+    #steps:
+      #- uses: actions/checkout@v2
+      #- name: Run Tests
+        #run: ./ci.sh check nightly

+ 106 - 0
ci.sh

@@ -0,0 +1,106 @@
+#!/usr/bin/env bash
+
+set -eox pipefail
+
+export DEFMT_LOG=trace
+
+MSRV="1.65.0"
+
+RUSTC_VERSIONS=(
+    $MSRV
+    "stable"
+    "nightly"
+)
+
+FEATURES_TEST=(
+    "default"
+    "std,proto-ipv4"
+    "std,medium-ethernet,phy-raw_socket,proto-ipv6,socket-udp,socket-dns"
+    "std,medium-ethernet,phy-tuntap_interface,proto-ipv6,socket-udp"
+    "std,medium-ethernet,proto-ipv4,proto-ipv4-fragmentation,socket-raw,socket-dns"
+    "std,medium-ethernet,proto-ipv4,proto-igmp,socket-raw,socket-dns"
+    "std,medium-ethernet,proto-ipv4,socket-udp,socket-tcp,socket-dns"
+    "std,medium-ethernet,proto-ipv4,proto-dhcpv4,socket-udp"
+    "std,medium-ethernet,medium-ip,medium-ieee802154,proto-ipv6,socket-udp,socket-dns"
+    "std,medium-ethernet,proto-ipv6,socket-tcp"
+    "std,medium-ethernet,medium-ip,proto-ipv4,socket-icmp,socket-tcp"
+    "std,medium-ip,proto-ipv6,socket-icmp,socket-tcp"
+    "std,medium-ieee802154,proto-sixlowpan,socket-udp"
+    "std,medium-ieee802154,proto-sixlowpan,proto-sixlowpan-fragmentation,socket-udp"
+    "std,medium-ip,proto-ipv4,proto-ipv6,socket-tcp,socket-udp"
+    "std,medium-ethernet,medium-ip,medium-ieee802154,proto-ipv4,proto-ipv6,socket-raw,socket-udp,socket-tcp,socket-icmp,socket-dns,async"
+)
+
+FEATURES_TEST_NIGHTLY=(
+    "alloc,medium-ethernet,proto-ipv4,proto-ipv6,socket-raw,socket-udp,socket-tcp,socket-icmp"
+)
+
+FEATURES_CHECK=(
+    "medium-ip,medium-ethernet,medium-ieee802154,proto-ipv6,proto-ipv6,proto-igmp,proto-dhcpv4,socket-raw,socket-udp,socket-tcp,socket-icmp,socket-dns,async"
+    "defmt,medium-ip,medium-ethernet,proto-ipv6,proto-ipv6,proto-igmp,proto-dhcpv4,socket-raw,socket-udp,socket-tcp,socket-icmp,socket-dns,async"
+    "defmt,alloc,medium-ip,medium-ethernet,proto-ipv6,proto-ipv6,proto-igmp,proto-dhcpv4,socket-raw,socket-udp,socket-tcp,socket-icmp,socket-dns,async"
+)
+
+test() {
+    local version=$1
+    rustup toolchain install $version
+
+    for features in ${FEATURES_TEST[@]}; do
+        cargo +$version test --no-default-features --features "$features"
+    done
+
+    if [[ $version == "nightly" ]]; then
+        for features in ${FEATURES_TEST_NIGHTLY[@]}; do
+            cargo +$version test --no-default-features --features "$features"
+        done
+    fi
+}
+
+check() {
+    local version=$1
+    rustup toolchain install $version
+
+    export DEFMT_LOG="trace"
+
+    for features in ${FEATURES_CHECK[@]}; do
+        cargo +$version check --no-default-features --features "$features"
+    done
+}
+
+clippy() {
+    rustup toolchain install $MSRV
+    rustup component add clippy --toolchain=$MSRV
+    cargo +$MSRV clippy --tests --examples -- -D warnings
+}
+
+if [[ $1 == "test" || $1 == "all" ]]; then
+    if [[ -n $2 ]]; then
+        if [[ $2 == "msrv" ]]; then
+            test $MSRV
+        else
+            test $2
+        fi
+    else
+        for version in ${RUSTC_VERSIONS[@]}; do
+            test $version
+        done
+    fi
+fi
+
+if [[ $1 == "check" || $1 == "all" ]]; then
+    if [[ -n $2 ]]; then
+        if [[ $2 == "msrv" ]]; then
+            check $MSRV
+        else
+            check $2
+        fi
+    else
+        for version in ${RUSTC_VERSIONS[@]}; do
+            check $version
+        done
+    fi
+fi
+
+if [[ $1 == "clippy" || $1 == "all" ]]; then
+    clippy
+fi