Skip to content

Commit 00df148

Browse files
committed
Add GitHub Actions Workflow
Add a GitHub actions workflow to run checks and build all the examples to validate if at least building the code works.
1 parent 6c4ae65 commit 00df148

File tree

1 file changed

+155
-0
lines changed

1 file changed

+155
-0
lines changed

.github/workflows/build.yml

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

0 commit comments

Comments
 (0)