Skip to content

Commit

Permalink
style and lint fixes, add test/lint CI
Browse files Browse the repository at this point in the history
  • Loading branch information
jhheider committed Nov 26, 2024
1 parent adca322 commit bed7336
Show file tree
Hide file tree
Showing 8 changed files with 355 additions and 212 deletions.
67 changes: 67 additions & 0 deletions .github/workflows/check-and-lint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# https://github.com/BamPeers/rust-ci-github-actions-workflow

on:
pull_request:
push:
branches:
- main

name: Check and Lint

jobs:
check:
name: Check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: nightly
override: true
- uses: actions-rs/cargo@v1
with:
command: check
env:
RUSTFLAGS: "-D warnings"

fmt:
name: Rustfmt
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: nightly
override: true
- run: rustup component add rustfmt
- uses: actions-rs/cargo@v1
with:
command: fmt
args: --all -- --check

clippy:
name: Clippy
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions-rs/toolchain@v1
with:
toolchain: nightly
components: clippy
override: true
- uses: actions-rs/cargo@v1
with:
command: clippy
args: --all-features
env:
RUSTFLAGS: "-D warnings"

markdownlint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: nosborn/[email protected]
with:
files: .
65 changes: 65 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# https://github.com/BamPeers/rust-ci-github-actions-workflow

on:
pull_request:
push:
branches:
- main

name: Test # with Code Coverage

permissions:
contents: read
checks: write
pull-requests: write

jobs:
test:
name: Test
env:
PROJECT_NAME_UNDERSCORE: bpb_pkgx
CARGO_INCREMENTAL: 0
RUSTFLAGS: -Ccodegen-units=1 -Copt-level=0 -Clink-dead-code -Coverflow-checks=off -Zpanic_abort_tests -Cpanic=abort -D warnings
RUSTDOCFLAGS: -Cpanic=abort
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: nightly
override: true
- name: Cache dependencies
uses: actions/cache@v2
env:
cache-name: cache-dependencies
with:
path: |
~/.cargo/.crates.toml
~/.cargo/.crates2.json
~/.cargo/bin
~/.cargo/registry/index
~/.cargo/registry/cache
target
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('Cargo.lock') }}
- uses: actions-rs/cargo@v1
with:
command: test
args: --all-features

# coverage:
# name: Coverage
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v4
# - uses: actions-rs/toolchain@v1
# with:
# profile: minimal
# toolchain: nightly
# override: true
# - name: Generate test result and coverage report
# run: |
# cargo install cargo-tarpaulin
# cargo tarpaulin --engine ptrace -o lcov --output-dir coverage --coveralls $COVERALLS_TOKEN
# env:
# COVERALLS_TOKEN: ${{ secrets.COVERALLS_TOKEN }}
64 changes: 16 additions & 48 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ authors = ["Without Boats <[email protected]>", "Jacob Heider <[email protected]>"]
toml = "0.4.6"
rand = { version = "0.8.5", features = ["std"] }
sha2 = "0.7.1"
serde_derive = "1.0.70"
serde = "1.0.70"
serde_derive = "1.0.215"
serde = "1.0.215"
hex = "0.3.2"
failure = "0.1.1"

Expand Down
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,15 @@ do.

## `pkgx` Updates

* Updated to edition 2021 by pkgx
* Stores the private key in the macOS keychain such that only this tool (when
- Updated to edition 2021 by pkgx
- Stores the private key in the macOS keychain such that only this tool (when
codesigned) can access it.

### TODO

- [ ] Move keychain identifiers out to build variables in `config.rs`
- [ ] Move keychain identifier out to a build variable in `keychain.rs`

## How to Install

```sh
Expand Down
29 changes: 14 additions & 15 deletions src/config.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
use std::io::{Read, Write};
use std::io::Read;

use failure::Error;

use crate::key_data::KeyData;

use crate::keychain::get_keychain_item;
use crate::keychain::add_keychain_item;
use crate::keychain::{add_keychain_item, get_keychain_item};

const KEYCHAIN_SERVICE: &str = "xyz.tea.BASE.bpb";
const KEYCHAIN_ACCOUNT: &str = "example_account";

#[derive(Serialize, Deserialize)]
pub struct Config {
Expand Down Expand Up @@ -38,17 +40,14 @@ impl Config {
}

pub fn load() -> Result<Config, Error> {
let service = "xyz.tea.BASE.bpb";
let account = "example_account";
let str = get_keychain_item(service, account)?;
Ok(toml::from_str::<Config>(&str)?)
let str = get_keychain_item(KEYCHAIN_SERVICE, KEYCHAIN_ACCOUNT)?;
Ok(toml::from_str::<Config>(&str)?)
}

pub fn write(&self) -> Result<(), Error> {
let secret = toml::to_string(self)?;
let service = "xyz.tea.BASE.bpb";
let account = "example_account"; //self.user_id();
add_keychain_item(service, account, &secret)
// let account = self.user_id();
add_keychain_item(KEYCHAIN_SERVICE, KEYCHAIN_ACCOUNT, &secret)
}

pub fn timestamp(&self) -> u64 {
Expand Down Expand Up @@ -79,11 +78,11 @@ struct SecretKey {

impl SecretKey {
fn secret(&self) -> Result<[u8; 32], Error> {
if let Some(key) = &self.key {
to_32_bytes(key)
} else {
bail!("No secret key or program specified")
}
if let Some(key) = &self.key {
to_32_bytes(key)
} else {
bail!("No secret key or program specified")
}
}
}

Expand Down
Loading

0 comments on commit bed7336

Please sign in to comment.