|
| 1 | +name: Build |
| 2 | +permissions: {} |
| 3 | + |
| 4 | +on: |
| 5 | + push: |
| 6 | + paths: |
| 7 | + - ".github/workflows/build.yml" |
| 8 | + - "examples/**" |
| 9 | + - "src/**" |
| 10 | + - "Cargo.toml" |
| 11 | + pull_request: |
| 12 | + paths: |
| 13 | + - ".github/workflows/build.yml" |
| 14 | + - "examples/**" |
| 15 | + - "src/**" |
| 16 | + - "Cargo.toml" |
| 17 | + |
| 18 | +## To trigger this workflow using `act` (https://github.com/nektos/act) you can do the following. |
| 19 | +# act push -j build |
| 20 | + |
| 21 | +jobs: |
| 22 | + build: |
| 23 | + name: Build and Test |
| 24 | + permissions: |
| 25 | + contents: read |
| 26 | + runs-on: ubuntu-24.04 |
| 27 | + timeout-minutes: 30 |
| 28 | + # Make warnings errors, this is to prevent warnings slipping through. |
| 29 | + # This is done globally to prevent rebuilds when the RUSTFLAGS env variable changes. |
| 30 | + env: |
| 31 | + RUSTFLAGS: "-D warnings" |
| 32 | + strategy: |
| 33 | + fail-fast: false |
| 34 | + |
| 35 | + steps: |
| 36 | + # Install dependencies |
| 37 | + - name: "Install dependencies Ubuntu" |
| 38 | + run: sudo apt-get update && sudo apt-get install -y --no-install-recommends build-essential pkg-config openssl libssl-dev |
| 39 | + # End Install dependencies |
| 40 | + |
| 41 | + |
| 42 | + # Install Rust with clippy |
| 43 | + - name: "Install rust-toolchain version" |
| 44 | + uses: dtolnay/rust-toolchain@fcf085fcb4b4b8f63f96906cd713eb52181b5ea4 # stable at Mar 18, 2025, 8:14 PM GMT+1 |
| 45 | + with: |
| 46 | + components: clippy |
| 47 | + # End Install Rust with clippy |
| 48 | + |
| 49 | + # Show environment |
| 50 | + - name: "Show environment" |
| 51 | + run: | |
| 52 | + rustc -vV |
| 53 | + cargo -vV |
| 54 | + # End Show environment |
| 55 | + |
| 56 | + # Checkout the repo |
| 57 | + - name: "Checkout" |
| 58 | + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 |
| 59 | + with: |
| 60 | + persist-credentials: false |
| 61 | + # End Checkout the repo |
| 62 | + |
| 63 | + # Enable Rust Caching |
| 64 | + - uses: Swatinem/rust-cache@9d47c6ad4b02e050fd481d890b2ea34778fd09d6 # v2.7.8 |
| 65 | + # End Enable Rust Caching |
| 66 | + |
| 67 | + # Run cargo commands |
| 68 | + - name: "Run cargo update" |
| 69 | + id: run_cargo_update |
| 70 | + if: ${{ always() }} |
| 71 | + run: | |
| 72 | + cargo update --verbose |
| 73 | +
|
| 74 | + - name: "cargo test" |
| 75 | + id: run_cargo_test |
| 76 | + if: ${{ always() }} |
| 77 | + run: | |
| 78 | + cargo test --verbose |
| 79 | +
|
| 80 | + - name: "Build all features" |
| 81 | + id: build_all_features |
| 82 | + if: ${{ always() }} |
| 83 | + run: | |
| 84 | + cargo build --all-features --verbose |
| 85 | +
|
| 86 | + - name: "Build otp example" |
| 87 | + id: build_example_otp |
| 88 | + if: ${{ always() }} |
| 89 | + run: | |
| 90 | + cargo build --example otp |
| 91 | +
|
| 92 | + - name: "Build otp_async example" |
| 93 | + id: build_example_otp_async |
| 94 | + if: ${{ always() }} |
| 95 | + run: | |
| 96 | + cargo build --example otp_async |
| 97 | +
|
| 98 | + - name: "Build otp_custom example" |
| 99 | + id: build_example_otp_custom |
| 100 | + if: ${{ always() }} |
| 101 | + run: | |
| 102 | + cargo build --example otp_custom |
| 103 | +
|
| 104 | + - name: "Build otp_with_proxy example" |
| 105 | + id: build_example_otp_with_proxy |
| 106 | + if: ${{ always() }} |
| 107 | + run: | |
| 108 | + cargo build --example otp_with_proxy |
| 109 | + # End Run cargo tests |
| 110 | + |
| 111 | + |
| 112 | + # Run cargo clippy, and fail on warnings |
| 113 | + - name: "Run clippy" |
| 114 | + id: run_cargo_clippy |
| 115 | + if: ${{ always() }} |
| 116 | + run: | |
| 117 | + cargo clippy --all-features |
| 118 | +
|
| 119 | + - name: "Run clippy" |
| 120 | + id: run_cargo_clippy_examples |
| 121 | + if: ${{ always() }} |
| 122 | + run: | |
| 123 | + cargo clippy --examples |
| 124 | + # End Run cargo clippy |
| 125 | + |
| 126 | + |
| 127 | + # Check for any previous failures, if there are stop, else continue. |
| 128 | + # This is useful so all test/clippy/fmt actions are done, and they can all be addressed |
| 129 | + - name: "Some checks failed" |
| 130 | + if: ${{ failure() }} |
| 131 | + env: |
| 132 | + RUN_CARGO_UPDATE: ${{ steps.run_cargo_update.outcome }} |
| 133 | + RUN_CARGO_TEST: ${{ steps.run_cargo_test.outcome }} |
| 134 | + BUILD_ALL: ${{ steps.build_all_features.outcome }} |
| 135 | + EXAMPLE_OTP: ${{ steps.build_example_otp.outcome }} |
| 136 | + EXAMPLE_OTP_ASYNC: ${{ steps.build_example_otp_async.outcome }} |
| 137 | + EXAMPLE_OTP_CUSTOM: ${{ steps.build_example_otp_custom.outcome }} |
| 138 | + EXAMPLE_OTP_WITH_PROXY: ${{ steps.build_example_otp_with_proxy.outcome }} |
| 139 | + RUN_CARGO_CLIPPY: ${{ steps.run_cargo_clippy.outcome }} |
| 140 | + RUN_CARGO_CLIPPY_EXAMPLES: ${{ steps.run_cargo_clippy_examples.outcome }} |
| 141 | + run: | |
| 142 | + echo "### :x: Checks Failed!" >> ${GITHUB_STEP_SUMMARY} |
| 143 | + echo "" >> ${GITHUB_STEP_SUMMARY} |
| 144 | + echo "|Job|Status|" >> ${GITHUB_STEP_SUMMARY} |
| 145 | + echo "|---|------|" >> ${GITHUB_STEP_SUMMARY} |
| 146 | + echo "|cargo update|${RUN_CARGO_UPDATE}|" >> ${GITHUB_STEP_SUMMARY} |
| 147 | + echo "|cargo test|${RUN_CARGO_TEST}|" >> ${GITHUB_STEP_SUMMARY} |
| 148 | + echo "|build all features|${BUILD_ALL}|" >> ${GITHUB_STEP_SUMMARY} |
| 149 | + echo "|build example otp|${EXAMPLE_OTP}|" >> ${GITHUB_STEP_SUMMARY} |
| 150 | + echo "|build example otp_async|${EXAMPLE_OTP_ASYNC}|" >> ${GITHUB_STEP_SUMMARY} |
| 151 | + echo "|build example otp_custom|${EXAMPLE_OTP_CUSTOM}|" >> ${GITHUB_STEP_SUMMARY} |
| 152 | + echo "|build example otp_with_proxy|${EXAMPLE_OTP_WITH_PROXY}|" >> ${GITHUB_STEP_SUMMARY} |
| 153 | + echo "|clippy all features|${RUN_CARGO_CLIPPY}|" >> ${GITHUB_STEP_SUMMARY} |
| 154 | + echo "|clippy examples|${RUN_CARGO_CLIPPY_EXAMPLES}|" >> ${GITHUB_STEP_SUMMARY} |
| 155 | + echo "" >> ${GITHUB_STEP_SUMMARY} |
| 156 | + echo "Please check the failed jobs and fix where needed." >> ${GITHUB_STEP_SUMMARY} |
| 157 | + echo "" >> ${GITHUB_STEP_SUMMARY} |
| 158 | + exit 1 |
| 159 | +
|
| 160 | +
|
| 161 | + # If all was ok, then we show this |
| 162 | + - name: "All checks passed" |
| 163 | + if: ${{ success() }} |
| 164 | + run: | |
| 165 | + echo "### :tada: Checks Passed!" >> ${GITHUB_STEP_SUMMARY} |
| 166 | + echo "" >> ${GITHUB_STEP_SUMMARY} |
0 commit comments