-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from rgallor/rust-codegen
feat(ci): add rust check and codegen
- Loading branch information
Showing
18 changed files
with
1,287 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Copyright 2023 SECO Mind Srl | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
name: ci | ||
|
||
on: | ||
workflow_dispatch: | ||
pull_request: | ||
push: | ||
branches: | ||
- "main" | ||
- "release-*" | ||
|
||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} | ||
cancel-in-progress: true | ||
|
||
jobs: | ||
reuse: | ||
uses: ./.github/workflows/reuse-lint.yaml | ||
codegen-check: | ||
needs: [reuse] | ||
uses: ./.github/workflows/codegen-check.yaml | ||
rust-check: | ||
needs: [codegen-check] | ||
uses: ./.github/workflows/rust-check.yaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# Copyright 2023 SECO Mind Srl | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
name: codegen-check | ||
|
||
permissions: | ||
contents: read | ||
|
||
on: | ||
workflow_call: | ||
|
||
env: | ||
CARGO_TERM_COLOR: always | ||
PB_REL: https://github.com/protocolbuffers/protobuf/releases | ||
PB_VERSION: 24.4 | ||
|
||
jobs: | ||
check: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Install protoc | ||
run: | | ||
curl -LO "$PB_REL/download/v$PB_VERSION/protoc-$PB_VERSION-linux-x86_64.zip" | ||
unzip "protoc-$PB_VERSION-linux-x86_64.zip" -d "$HOME/.local" | ||
echo "$HOME/.local/bin" >> "$GITHUB_PATH" | ||
- name: Install rust toolchain | ||
uses: dtolnay/rust-toolchain@stable | ||
- name: Generate code | ||
run: make all | ||
- name: Check diff in generated code | ||
run: ./scripts/check_diff.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
# Copyright 2023 SECO Mind Srl | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
name: check | ||
permissions: | ||
contents: read | ||
on: | ||
workflow_call: | ||
env: | ||
CARGO_TERM_COLOR: always | ||
defaults: | ||
run: | ||
working-directory: rust | ||
jobs: | ||
fmt: | ||
name: stable / fmt | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout sources | ||
uses: actions/checkout@v4 | ||
- name: Install toolchain | ||
uses: dtolnay/rust-toolchain@stable | ||
with: | ||
components: rustfmt | ||
- name: Check formatting | ||
run: cargo fmt --check | ||
clippy: | ||
runs-on: ubuntu-latest | ||
name: ${{ matrix.toolchain }} / clippy | ||
permissions: | ||
contents: read | ||
checks: write | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
toolchain: [stable, beta] | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Install ${{ matrix.toolchain }} | ||
uses: dtolnay/rust-toolchain@master | ||
with: | ||
toolchain: ${{ matrix.toolchain }} | ||
components: clippy | ||
- name: cargo clippy | ||
uses: actions-rs/clippy-check@v1 | ||
with: | ||
token: ${{ secrets.GITHUB_TOKEN }} | ||
args: --manifest-path rust/Cargo.toml --all-targets --all-features -- -D warnings | ||
doc: | ||
runs-on: ubuntu-latest | ||
name: nightly / doc | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Install nightly | ||
uses: dtolnay/rust-toolchain@nightly | ||
- name: cargo doc | ||
run: cargo doc --no-deps --all-features | ||
env: | ||
RUSTDOCFLAGS: --cfg docsrs -D warnings | ||
hack: | ||
runs-on: ubuntu-latest | ||
name: ubuntu / stable / features | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Install stable | ||
uses: dtolnay/rust-toolchain@stable | ||
- name: cargo install cargo-hack | ||
uses: taiki-e/install-action@cargo-hack | ||
# intentionally no target specifier; see https://github.com/jonhoo/rust-ci-conf/pull/4 | ||
- name: cargo hack | ||
run: cargo hack --feature-powerset check | ||
minimal-versions: | ||
runs-on: ubuntu-latest | ||
name: ubuntu / nightly / minimal-versions | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Install nightly | ||
uses: dtolnay/rust-toolchain@nightly | ||
- name: cargo install cargo-hack | ||
uses: taiki-e/install-action@cargo-hack | ||
- name: remove dev-deps | ||
run: cargo hack --remove-dev-deps | ||
- name: update to minimal deps | ||
run: cargo update -Z direct-minimal-versions | ||
- name: cargo check | ||
run: cargo check --all-features | ||
env: | ||
RUSTDOCFLAGS: -D warnings | ||
msrv: | ||
runs-on: ubuntu-latest | ||
# we use a matrix here just because env can't be used in job names | ||
# https://docs.github.com/en/actions/learn-github-actions/contexts#context-availability | ||
strategy: | ||
matrix: | ||
msrv: [1.66.1] | ||
name: ubuntu / ${{ matrix.msrv }} | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Install ${{ matrix.msrv }} | ||
uses: dtolnay/rust-toolchain@master | ||
with: | ||
toolchain: ${{ matrix.msrv }} | ||
- name: cargo +${{ matrix.msrv }} check | ||
run: cargo check --all-features --package edgehog-device-forwarder-proto |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,14 @@ | ||
# Copyright 2023 SECO Mind Srl | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
# Pre commit configuration file | ||
.pre-commit-config.yaml | ||
|
||
# IntelliJ | ||
.idea/ | ||
|
||
# Rust dist directory | ||
target/ | ||
|
||
# Codegen output directory | ||
output/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ | ||
Upstream-Name: edgehog-device-forwarder-proto | ||
Source: https://github.com/edgehog-device-manager/edgehog-device-forwarder-proto | ||
|
||
Files: out/* rust/Cargo.lock rust/edgehog-device-forwarder-proto/src/proto.rs | ||
Copyright: 2023 SECO Mind Srl | ||
License: Apache-2.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
# Copyright 2023 SECO Mind Srl | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
# This Makefile serves to generate language-specific messages from .proto file. | ||
|
||
# we want bash as shell | ||
SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \ | ||
else if [ -x BASH_PATH="$(command -v bash)" ]; then echo $$BASH_PATH; \ | ||
else echo sh; fi; fi) | ||
|
||
# Set O variable if not already done on the command line; | ||
# or avoid confusing packages that can use the O=<dir> syntax for out-of-tree | ||
# build by preventing it from being forwarded to sub-make calls. | ||
ifneq ("$(origin O)", "command line") | ||
O := $(CURDIR)/output | ||
endif | ||
|
||
# Remove the trailing '/.' from $(O) as it can be added by the makefile wrapper | ||
# installed in the $(O) directory. | ||
# Also remove the trailing '/' the user can set when on the command line. | ||
override O := $(patsubst %/,%,$(patsubst %.,%,$(O))) | ||
# Make sure $(O) actually exists before calling realpath on it; this is to | ||
# avoid empty CANONICAL_O in case on non-existing entry. | ||
CANONICAL_O := $(shell mkdir -p $(O) >/dev/null 2>&1)$(realpath $(O)) | ||
|
||
CANONICAL_CURDIR = $(realpath $(CURDIR)) | ||
|
||
PROTO_DIR = $(CANONICAL_CURDIR)/proto | ||
RUST_LANG_DIR = $(CANONICAL_CURDIR)/rust | ||
|
||
BASE_DIR := $(CANONICAL_O) | ||
$(if $(BASE_DIR),, $(error output directory "$(O)" does not exist)) | ||
|
||
BUILD_DIR := $(BASE_DIR)/build | ||
RUST_BUILD_DIR := $(BUILD_DIR)/rust | ||
|
||
FILES=$(wildcard proto/edgehog/device/forwarder/*.proto) | ||
|
||
PROTOC_CHECK_SCRIPT=$(CANONICAL_CURDIR)/scripts/protoc_check.sh | ||
|
||
RUST_LANG=$(RUST_BUILD_DIR)/proto.rs | ||
RUST_FILES=$(shell find "$(RUST_LANG_DIR)/rust-codegen" -type f -regex '.*(rs|Cargo.toml|Cargo.lock)$$') \ | ||
$(RUST_LANG_DIR)/Cargo.toml $(RUST_LANG_DIR)/Cargo.lock | ||
|
||
# This is our default rule, so must come first | ||
.PHONY: all | ||
all: rust | ||
|
||
.PHONY: install | ||
install: rust-install | ||
|
||
.PHONY: clean | ||
clean: | ||
rm -rf $(BUILD_DIR) | ||
|
||
.PHONY: protoc-check | ||
protoc-check: $(PROTOC_CHECK_SCRIPT) | ||
$(PROTOC_CHECK_SCRIPT) | ||
|
||
.PHONY: rust | ||
rust: protoc-check $(RUST_LANG) | ||
|
||
$(RUST_LANG): $(FILES) $(RUST_FILES) | ||
cargo run --manifest-path "$(RUST_LANG_DIR)"/Cargo.toml -p rust-codegen -- -w "$(PROTO_DIR)" -o "$(RUST_BUILD_DIR)" | ||
|
||
.PHONY: rust-install | ||
rust-install: rust | ||
install -m 664 "$(RUST_BUILD_DIR)/edgehog.device.forwarder.rs" "$(RUST_LANG_DIR)/edgehog-device-forwarder-proto/src/proto.rs" | ||
|
||
.PHONY: rust-dirclean | ||
rust-dirclean: | ||
rm -rf $(RUST_BUILD_DIR) | ||
|
||
.PHONY: help | ||
help: | ||
@echo 'Cleaning:' | ||
@echo ' clean - Delete all files created by build' | ||
@echo | ||
@echo 'Build:' | ||
@echo ' all - Build everything and generate the code for the various languages' | ||
@echo ' install - Install files into repo folder' | ||
@echo | ||
@echo 'Language-specific:' | ||
@echo ' <lang> - Build and generate the code for the <lang> languages' | ||
@echo ' <lang>-install - Install <lang> files into the repo <lang> folder' | ||
@echo ' <lang>-dirclean - Remove <lang> build directory' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Copyright 2023 SECO Mind Srl | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
target/ |
Oops, something went wrong.