Skip to content

Commit 45d2dd4

Browse files
committed
feat(ci): add rust check and codegen
Add github workflows: - generate rust files from proto - check rust code - commit generated files - dependabot for cargo dependencies Signed-off-by: rgallor <riccardo.gallo@secomind.com>
1 parent 9897e0f commit 45d2dd4

File tree

9 files changed

+275
-10
lines changed

9 files changed

+275
-10
lines changed

.github/dependabot.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,14 @@ updates:
77
directory: /
88
schedule:
99
interval: weekly
10+
- package-ecosystem: cargo
11+
directory: "/rust"
12+
schedule:
13+
interval: weekly
14+
ignore:
15+
- dependency-name: "*"
16+
# patch and minor updates don't matter for libraries
17+
# remove this ignore rule if your package has binaries
18+
update-types:
19+
- "version-update:semver-patch"
20+
- "version-update:semver-minor"

.github/workflows/ci.yaml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Copyright 2023 SECO Mind Srl
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
name: ci
5+
6+
on:
7+
workflow_dispatch:
8+
pull_request:
9+
push:
10+
branches:
11+
- 'main'
12+
- 'release-*'
13+
14+
concurrency:
15+
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
16+
cancel-in-progress: true
17+
18+
jobs:
19+
reuse:
20+
uses: ./.github/workflows/reuse-lint.yaml
21+
rust-codegen:
22+
needs: [ reuse ]
23+
uses: ./.github/workflows/rust-codegen.yaml
24+
rust-check:
25+
needs: [ rust-codegen ]
26+
uses: ./.github/workflows/rust-check.yaml
27+
commit-codegen:
28+
if: github.event_name == 'push' || github.event_name == 'workflow_dispatch'
29+
needs: [ rust-check ]
30+
permissions:
31+
contents: write
32+
uses: ./.github/workflows/commit-codegen.yaml
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Copyright 2023 SECO Mind Srl
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
name: commit-codegen
5+
6+
on:
7+
workflow_call:
8+
workflow_dispatch:
9+
10+
permissions:
11+
contents: write
12+
13+
jobs:
14+
commit:
15+
name: Commit and push generated code
16+
runs-on: ubuntu-latest
17+
steps:
18+
- uses: actions/checkout@v4
19+
- name: Download rust proto
20+
uses: actions/download-artifact@v3
21+
id: download-rust
22+
with:
23+
name: rust-proto
24+
- name: Move rust proto to src
25+
run: |
26+
mv -v '${{steps.download-rust.outputs.download-path}}/edgehog.device.forwarder.rs' \
27+
rust/edgehog-device-forwarder-proto/src/proto.rs
28+
- name: Commit the generated code
29+
run: .github/workflows/scripts/commit.sh

.github/workflows/reuse-lint.yaml

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,7 @@ permissions:
77
contents: read
88

99
on:
10-
push:
11-
branches:
12-
- master
13-
- release-*
14-
pull_request:
15-
16-
concurrency:
17-
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
18-
cancel-in-progress: true
10+
workflow_call:
1911

2012
jobs:
2113
check:

.github/workflows/rust-check.yaml

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
# Copyright 2023 SECO Mind Srl
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
name: check
5+
permissions:
6+
contents: read
7+
on:
8+
workflow_call:
9+
env:
10+
CARGO_TERM_COLOR: always
11+
defaults:
12+
run:
13+
working-directory: rust
14+
jobs:
15+
fmt:
16+
name: stable / fmt
17+
runs-on: ubuntu-latest
18+
steps:
19+
- name: Checkout sources
20+
uses: actions/checkout@v4
21+
- name: Install toolchain
22+
uses: dtolnay/rust-toolchain@stable
23+
with:
24+
components: rustfmt
25+
- name: Check formatting
26+
run: cargo fmt --check
27+
clippy:
28+
runs-on: ubuntu-latest
29+
name: ${{ matrix.toolchain }} / clippy
30+
permissions:
31+
contents: read
32+
checks: write
33+
strategy:
34+
fail-fast: false
35+
matrix:
36+
toolchain: [ stable, beta ]
37+
steps:
38+
- uses: actions/checkout@v4
39+
# Download proto artifact
40+
- uses: actions/download-artifact@v3
41+
id: download-proto
42+
with:
43+
name: rust-proto
44+
- name: Move proto to src
45+
run: |
46+
mv -v '${{steps.download-proto.outputs.download-path}}/edgehog.device.forwarder.rs' \
47+
edgehog-device-forwarder-proto/src/proto.rs
48+
##
49+
- name: Install ${{ matrix.toolchain }}
50+
uses: dtolnay/rust-toolchain@master
51+
with:
52+
toolchain: ${{ matrix.toolchain }}
53+
components: clippy
54+
- name: cargo clippy
55+
uses: actions-rs/clippy-check@v1
56+
with:
57+
token: ${{ secrets.GITHUB_TOKEN }}
58+
args: --manifest-path rust/Cargo.toml --all-targets --all-features -- -D warnings
59+
doc:
60+
runs-on: ubuntu-latest
61+
name: nightly / doc
62+
steps:
63+
- uses: actions/checkout@v4
64+
- name: Install nightly
65+
uses: dtolnay/rust-toolchain@nightly
66+
# Download proto artifact
67+
- uses: actions/download-artifact@v3
68+
id: download-proto
69+
with:
70+
name: rust-proto
71+
- name: Move proto to src
72+
run: |
73+
mv -v ${{steps.download-proto.outputs.download-path}}/edgehog.device.forwarder.rs \
74+
edgehog-device-forwarder-proto/src/proto.rs
75+
##
76+
- name: cargo doc
77+
run: cargo doc --no-deps --all-features
78+
env:
79+
RUSTDOCFLAGS: --cfg docsrs -D warnings
80+
hack:
81+
runs-on: ubuntu-latest
82+
name: ubuntu / stable / features
83+
steps:
84+
- uses: actions/checkout@v4
85+
- name: Install stable
86+
uses: dtolnay/rust-toolchain@stable
87+
- name: cargo install cargo-hack
88+
uses: taiki-e/install-action@cargo-hack
89+
# Download proto artifact
90+
- uses: actions/download-artifact@v3
91+
id: download-proto
92+
with:
93+
name: rust-proto
94+
- name: Move proto to src
95+
run: |
96+
mv -v '${{steps.download-proto.outputs.download-path}}/edgehog.device.forwarder.rs' \
97+
edgehog-device-forwarder-proto/src/proto.rs
98+
# intentionally no target specifier; see https://github.com/jonhoo/rust-ci-conf/pull/4
99+
- name: cargo hack
100+
run: cargo hack --feature-powerset check
101+
minimal-versions:
102+
runs-on: ubuntu-latest
103+
name: ubuntu / nightly / minimal-versions
104+
steps:
105+
- uses: actions/checkout@v4
106+
- name: Install nightly
107+
uses: dtolnay/rust-toolchain@nightly
108+
- name: cargo install cargo-hack
109+
uses: taiki-e/install-action@cargo-hack
110+
- name: remove dev-deps
111+
run: cargo hack --remove-dev-deps
112+
- name: update to minimal deps
113+
run: cargo update -Z direct-minimal-versions
114+
# Download proto artifact
115+
- uses: actions/download-artifact@v3
116+
id: download-proto
117+
with:
118+
name: rust-proto
119+
- name: Move proto to src
120+
run: |
121+
mv -v '${{steps.download-proto.outputs.download-path}}/edgehog.device.forwarder.rs' \
122+
edgehog-device-forwarder-proto/src/proto.rs
123+
##
124+
- name: cargo check
125+
run: cargo check --all-features
126+
env:
127+
RUSTDOCFLAGS: -D warnings
128+
msrv:
129+
runs-on: ubuntu-latest
130+
# we use a matrix here just because env can't be used in job names
131+
# https://docs.github.com/en/actions/learn-github-actions/contexts#context-availability
132+
strategy:
133+
matrix:
134+
msrv: [ 1.66.1 ]
135+
name: ubuntu / ${{ matrix.msrv }}
136+
steps:
137+
- uses: actions/checkout@v4
138+
- name: Install ${{ matrix.msrv }}
139+
uses: dtolnay/rust-toolchain@master
140+
with:
141+
toolchain: ${{ matrix.msrv }}
142+
# Download proto artifact
143+
- uses: actions/download-artifact@v3
144+
id: download-proto
145+
with:
146+
name: rust-proto
147+
- name: Move proto to src
148+
run: |
149+
mv -v '${{steps.download-proto.outputs.download-path}}/edgehog.device.forwarder.rs' \
150+
edgehog-device-forwarder-proto/src/proto.rs
151+
##
152+
- name: cargo +${{ matrix.msrv }} check
153+
run: cargo check --all-features --package edgehog-device-forwarder-proto
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Copyright 2023 SECO Mind Srl
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
name: rust-codegen
5+
6+
permissions:
7+
contents: read
8+
9+
on:
10+
workflow_call:
11+
12+
env:
13+
CARGO_TERM_COLOR: always
14+
PB_REL: https://github.com/protocolbuffers/protobuf/releases
15+
PB_VERSION: 24.3
16+
17+
jobs:
18+
rust-build:
19+
runs-on: ubuntu-latest
20+
steps:
21+
- uses: actions/checkout@v4
22+
- name: Install protoc
23+
run: |
24+
curl -LO "$PB_REL/download/v$PB_VERSION/protoc-$PB_VERSION-linux-x86_64.zip"
25+
unzip "protoc-$PB_VERSION-linux-x86_64.zip" -d "$HOME/.local"
26+
echo "$HOME/.local/bin" >> "$GITHUB_PATH"
27+
- name: Install rust toolchain
28+
uses: dtolnay/rust-toolchain@stable
29+
- name: Generate Rust code
30+
run: cargo r --manifest-path rust/Cargo.toml -p rust-codegen -- -w proto/ -o out/
31+
- name: Upload generated code
32+
uses: actions/upload-artifact@v3
33+
with:
34+
name: rust-proto
35+
path: out/
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/usr/bin/env bash
2+
3+
# Copyright 2023 SECO Mind Srl
4+
# SPDX-License-Identifier: Apache-2.0
5+
6+
set -exEuo pipefail
7+
8+
git config user.name github-actions
9+
git config user.email github-actions@github.com
10+
git add -v rust/edgehog-device-forwarder-proto
11+
git diff --staged --quiet || git commit -s -m "chore(rust): update generated code"
12+
git push

rust/rust-codegen/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ version = "0.1.0"
77
edition = { workspace = true }
88
license = { workspace = true }
99
rust-version = { workspace = true }
10+
publish = false
1011

1112
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
1213

rust/rust-codegen/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33

44
use clap::Parser;
55
use color_eyre::eyre::Context;
6-
use std::path::PathBuf;
76
use std::fs;
7+
use std::path::PathBuf;
88

99
#[derive(Parser)]
1010
#[command(version, about)]

0 commit comments

Comments
 (0)