Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add copyright check to CI/CD pipeline #43

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
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
27 changes: 15 additions & 12 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: CI

on:
push:
push:
pull_request:
types: [opened, synchronize, reopened]

Expand All @@ -19,41 +19,44 @@ jobs:

steps:
- name: Checkout sources
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Install stable toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: stable
toolchain: 1.75.0
profile: minimal
override: true
components: rustfmt

- name: Setup cache
uses: Swatinem/rust-cache@v2

- name: Check for copyright statements
run: |
./tools/check-copyright.sh --check
- name: Check formatting
uses: actions-rs/cargo@v1
with:
command: fmt
args: --check

lint:
name: Lint
runs-on: ubuntu-latest

steps:
- name: Checkout sources
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Install stable toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: stable
toolchain: 1.75.0
profile: minimal
override: true
components: clippy

- name: Setup cache
uses: Swatinem/rust-cache@v2

Expand All @@ -69,15 +72,15 @@ jobs:

steps:
- name: Checkout sources
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Install stable toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: stable
toolchain: 1.75.0
profile: minimal
override: true

- name: Setup cache
uses: Swatinem/rust-cache@v2

Expand All @@ -91,7 +94,7 @@ jobs:
with:
command: tarpaulin
args: --release --all-features --engine llvm --out xml

- name: Upload to codecov.io
uses: codecov/codecov-action@v2
with:
Expand Down
2 changes: 1 addition & 1 deletion src/network_management/network_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ impl NetworkManager {
self.get_control_function_address_by_name(destination.get_name()),
priority,
)
.unwrap_or(CanId::default());
.unwrap_or_default();

if message_id.raw() != CanId::default().raw() {
self.enqueue_can_message(
Expand Down
1 change: 1 addition & 0 deletions src/object_pool/colour.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Copyright 2024 Raven Industries inc
#[derive(Debug, Clone, Copy, PartialEq)]
#[non_exhaustive]
pub struct Colour {
Expand Down
1 change: 1 addition & 0 deletions src/object_pool/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Copyright 2024 Raven Industries inc
pub mod colour;
pub mod reader;
pub mod writer;
Expand Down
2 changes: 2 additions & 0 deletions src/object_pool/object.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Copyright 2024 Raven Industries inc
use crate::network_management::name::NAME;
use crate::object_pool::object_attributes::{
Alignment, AnimationOptions, ButtonOptions, ColorFormat, ColourPaletteOptions,
Expand All @@ -12,6 +13,7 @@ use crate::object_pool::object_id::ObjectId;
use crate::object_pool::{Colour, ObjectType};

#[derive(Debug)]
#[allow(clippy::enum_variant_names)]
pub enum Object {
WorkingSet(WorkingSet),
DataMask(DataMask),
Expand Down
1 change: 1 addition & 0 deletions src/object_pool/object_attributes.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Copyright 2024 Raven Industries inc
use crate::object_pool::object_id::ObjectId;
use bitvec::field::BitField;
use bitvec::order::{Lsb0, Msb0};
Expand Down
1 change: 1 addition & 0 deletions src/object_pool/object_id.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Copyright 2024 Raven Industries inc
use crate::object_pool::ParseError;

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
Expand Down
1 change: 1 addition & 0 deletions src/object_pool/object_pool.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Copyright 2024 Raven Industries inc
use crate::object_pool::colour::Colour;
use crate::object_pool::object::{
AlarmMask, Button, Container, DataMask, GraphicsContext, InputBoolean, InputList, InputNumber,
Expand Down
1 change: 1 addition & 0 deletions src/object_pool/object_type.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Copyright 2024 Raven Industries inc
use crate::object_pool::ParseError;
use crate::object_pool::ParseError::UnknownObjectType;

Expand Down
1 change: 1 addition & 0 deletions src/object_pool/reader.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Copyright 2024 Raven Industries inc
use super::*;
use crate::object_pool::colour::Colour;
use crate::object_pool::object::*;
Expand Down
1 change: 1 addition & 0 deletions src/object_pool/vt_version.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Copyright 2024 Raven Industries inc
use crate::object_pool::ParseError;
use crate::object_pool::ParseError::UnknownObjectType;

Expand Down
1 change: 1 addition & 0 deletions src/object_pool/writer.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Copyright 2024 Raven Industries inc
use super::*;
use crate::object_pool::colour::Colour;
use crate::object_pool::object::{
Expand Down
86 changes: 86 additions & 0 deletions tools/check-copyright.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#!/bin/bash
set -o errexit
set -o pipefail
set -o nounset
set -o noclobber

REPO_DIRECTORY="$(git rev-parse --show-toplevel)"
RED='\033[0;31m'
GREEN='\033[0;32m'
RESET='\033[0m'

usage() {
echo "Usage: $0 [--help]"
echo
echo "Ensures that each source file has a copyright comment as per the project license"
echo
echo " --help, -h Show this help and exit"
echo " --check, -c Do not modify the source files, exit with failure if any notices are missing"
}

check_source_file() {
local source="$1"
local read_only="$2"
local failed_check="false"

if ! head "$source" | grep -i -E "// Copyright 20[0-9]{2} Raven Industries inc" >&/dev/null; then
failed_check="true"
if [[ "$read_only" = "false" ]]; then
local year
year="$(date +%Y)"
sed -i "1s;^;// Copyright $year Raven Industries inc\n;" "$source"
fi
fi

if [[ "$failed_check" = "true" ]]; then
return 1
fi
}

check_sources() {
local read_only="$1"
local failed_check="false"

shopt -s globstar
for source in "$REPO_DIRECTORY"/src/**/*.rs; do
echo -n "Checking '$source' for copyright statement ... "
if ! check_source_file "$source" "$read_only"; then
failed_check="true"
echo -e " ${RED}FAIL${RESET}"
else
echo -e " ${GREEN}ok${RESET}"
fi
done
if [[ "$failed_check" = "true" ]]; then
return 1
fi
}

main() {
local read_only="false"

while [[ $# -gt 0 ]]; do
case "$1" in
--help | -h)
usage
exit 0
;;
--check | -c)
read_only="true"
;;
-*)
echo "Unexpected option: $1" >&2
exit 1
;;
*)
echo "Unexpected positional argument: $1" >&2
exit 1
;;
esac
shift
done

check_sources "$read_only"
}

main "$@"
Loading