Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .github/dependabot.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Copyright 2023 SECO Mind Srl
# SPDX-License-Identifier: Apache-2.0

version: 2
updates:
- package-ecosystem: github-actions
directory: /
schedule:
interval: weekly
- package-ecosystem: cargo
directory: "/rust"
schedule:
interval: weekly
ignore:
- dependency-name: "*"
# patch and minor updates don't matter for libraries
# remove this ignore rule if your package has binaries
update-types:
- "version-update:semver-patch"
- "version-update:semver-minor"
35 changes: 35 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# 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
nix-check:
needs: [ reuse ]
uses: ./.github/workflows/nix-check.yaml
rust-codegen:
needs: [ reuse ]
uses: ./.github/workflows/rust-codegen.yaml
rust-check:
needs: [ rust-codegen ]
uses: ./.github/workflows/rust-check.yaml
commit-codegen:
if: github.event_name == 'push' || github.event_name == 'workflow_dispatch'
needs: [ rust-check ]
permissions:
contents: write
uses: ./.github/workflows/commit-codegen.yaml
29 changes: 29 additions & 0 deletions .github/workflows/commit-codegen.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Copyright 2023 SECO Mind Srl
# SPDX-License-Identifier: Apache-2.0

name: commit-codegen

on:
workflow_call:
workflow_dispatch:

permissions:
contents: write

jobs:
commit:
name: Commit and push generated code
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Download rust proto
uses: actions/download-artifact@v3
id: download-rust
with:
name: rust-proto
- name: Move rust proto to src
run: |
mv -v '${{steps.download-rust.outputs.download-path}}/edgehog.device.forwarder.rs' \
rust/edgehog-device-forwarder-proto/src/proto.rs
- name: Commit the generated code
run: .github/workflows/scripts/commit.sh
24 changes: 24 additions & 0 deletions .github/workflows/nix-check.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Copyright 2023 SECO Mind Srl
# SPDX-License-Identifier: Apache-2.0

name: nix-check

permissions:
contents: read

on:
workflow_call:

jobs:
flake:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: DeterminateSystems/nix-installer-action@main
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
- uses: DeterminateSystems/magic-nix-cache-action@main
with:
# Don't send the diagnostics automatically
diagnostic-endpoint: ""
- run: nix flake check
18 changes: 18 additions & 0 deletions .github/workflows/reuse-lint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Copyright 2023 SECO Mind Srl
# SPDX-License-Identifier: Apache-2.0

name: reuse

permissions:
contents: read

on:
workflow_call:

jobs:
check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: REUSE Compliance Check
uses: fsfe/reuse-action@v2
153 changes: 153 additions & 0 deletions .github/workflows/rust-check.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
# 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
# Download proto artifact
- uses: actions/download-artifact@v3
id: download-proto
with:
name: rust-proto
- name: Move proto to src
run: |
mv -v '${{steps.download-proto.outputs.download-path}}/edgehog.device.forwarder.rs' \
edgehog-device-forwarder-proto/src/proto.rs
##
- 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
# Download proto artifact
- uses: actions/download-artifact@v3
id: download-proto
with:
name: rust-proto
- name: Move proto to src
run: |
mv -v ${{steps.download-proto.outputs.download-path}}/edgehog.device.forwarder.rs \
edgehog-device-forwarder-proto/src/proto.rs
##
- 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
# Download proto artifact
- uses: actions/download-artifact@v3
id: download-proto
with:
name: rust-proto
- name: Move proto to src
run: |
mv -v '${{steps.download-proto.outputs.download-path}}/edgehog.device.forwarder.rs' \
edgehog-device-forwarder-proto/src/proto.rs
# 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
# Download proto artifact
- uses: actions/download-artifact@v3
id: download-proto
with:
name: rust-proto
- name: Move proto to src
run: |
mv -v '${{steps.download-proto.outputs.download-path}}/edgehog.device.forwarder.rs' \
edgehog-device-forwarder-proto/src/proto.rs
##
- 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 }}
# Download proto artifact
- uses: actions/download-artifact@v3
id: download-proto
with:
name: rust-proto
- name: Move proto to src
run: |
mv -v '${{steps.download-proto.outputs.download-path}}/edgehog.device.forwarder.rs' \
edgehog-device-forwarder-proto/src/proto.rs
##
- name: cargo +${{ matrix.msrv }} check
run: cargo check --all-features --package edgehog-device-forwarder-proto
33 changes: 33 additions & 0 deletions .github/workflows/rust-codegen.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Copyright 2023 SECO Mind Srl
# SPDX-License-Identifier: Apache-2.0

name: rust-codegen

permissions:
contents: read

on:
workflow_call:

env:
CARGO_TERM_COLOR: always

jobs:
rust-build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: DeterminateSystems/nix-installer-action@main
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
- uses: DeterminateSystems/magic-nix-cache-action@main
with:
# Don't send the diagnostics automatically
diagnostic-endpoint: ""
- name: Generate Rust code
run: nix build -L .#rust
- name: Upload generated code
uses: actions/upload-artifact@v3
with:
name: rust-proto
path: result/
12 changes: 12 additions & 0 deletions .github/workflows/scripts/commit.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env bash

# Copyright 2023 SECO Mind Srl
# SPDX-License-Identifier: Apache-2.0

set -exEuo pipefail

git config user.name github-actions
git config user.email github-actions@github.com
git add -v rust/edgehog-device-forwarder-proto
git diff --staged --quiet || git commit -s -m "chore(rust): update generated code"
git push
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Copyright 2023 SECO Mind Srl
# SPDX-License-Identifier: Apache-2.0

.pre-commit-config.yaml
/out
.idea/

# nix
/result
21 changes: 21 additions & 0 deletions .nix/codegen/rust.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Copyright 2023 SECO Mind Srl
# SPDX-License-Identifier: Apache-2.0

{ naereskBuilder, src, lib, protobuf, makeWrapper }:
let
unwrapped =
naereskBuilder {
inherit src;
name = "rust-codegen-unwrapped";
pname = "rust-codegen";
cargoBuildOptions = old: old ++ [ "--package=rust-codegen" ];
};
in
unwrapped.overrideAttrs {
passthru = { inherit unwrapped; };
name = "rust-codegen";
buildInputs = [ makeWrapper ];
postInstall = ''
wrapProgram $out/bin/rust-codegen --set PATH ${lib.makeBinPath [protobuf]}
'';
}
13 changes: 13 additions & 0 deletions .nix/rust.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright 2023 SECO Mind Srl
# SPDX-License-Identifier: Apache-2.0

{ rust-codegen, stdenvNoCC, protoSrc, protobuf }:
stdenvNoCC.mkDerivation {
name = "rust-edgehog-device-forwarder-proto";
nativeBuildInputs = [ protobuf ];
src = protoSrc;
buildPhase = ''
mkdir -p $out
${rust-codegen}/bin/rust-codegen -w . -o $out/
'';
}
7 changes: 7 additions & 0 deletions .reuse/dep5
Original file line number Diff line number Diff line change
@@ -0,0 +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
Loading