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

adding github actions for linting and testing #26

Closed
wants to merge 17 commits into from
53 changes: 53 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: CI

on:
pull_request:
branches:
- main
push:
branches:
- main

jobs:
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Cache Rust
uses: Swatinem/rust-cache@v2
with:
save-if: false
shared-key: base

- name: Install Cargo tools
run: |
rustup component add rustfmt clippy

- name: Check for license headers
run: ./ci/lintHeaders.sh

- name: "`cargo fmt` check"
run: |
cargo fmt --all -- --check

- name: "Clippy check on"
run: |
cargo clippy --all-targets -- -D warnings

test:
name: Unit Tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Cache Rust
uses: Swatinem/rust-cache@v2
with:
save-if: false
shared-key: base

- name: Run tests
run: |
cargo test
patnir marked this conversation as resolved.
Show resolved Hide resolved
31 changes: 31 additions & 0 deletions ci/lintHeaders.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/env bash

# Finds files in a given directory with a given file extension that don't have
# an MPL license header.
# $ lintHeaders ./src *.rs

license1="/* This Source Code Form is subject to the terms of the Mozilla Public"
license2=" * License, v. 2.0. If a copy of the MPL was not distributed with this"
license3=" * file, You can obtain one at https://mozilla.org/MPL/2.0/. */"

files=( $(find src -name "**/*.rs") )

echo "Checking the following files for license headers: ${files[@]}"
result=0

headerLineNumbers() {
grep -Fn -e "$license1" -e "$license2" -e "$license3" "$1" | cut -f1 -d:
}

expectedHeaderLineNumbers='1
2
3'
Comment on lines +16 to +22
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this works but perhaps an easier way to achieve the same result would be:

license="/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */"
[[ "$(head -n3 "$1")" = "$license" ]]


for file in ${files[@]}; do
if ! [ "$(headerLineNumbers $file)" = "$expectedHeaderLineNumbers" ]; then
echo "$file"
result=1
fi
done

exit $result
4 changes: 4 additions & 0 deletions src/keys.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */

use crate::frost::keys::PublicKeyPackage as FrostPublicKeyPackage;
use crate::frost::VerifyingKey;
use crate::participant::Identity;
Expand Down
Empty file added src/test/test.rs
Empty file.
Loading