Skip to content

Commit 08ef42e

Browse files
committed
style and lint fixes, add test/lint CI
1 parent adca322 commit 08ef42e

File tree

8 files changed

+350
-212
lines changed

8 files changed

+350
-212
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# https://github.com/BamPeers/rust-ci-github-actions-workflow
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- main
8+
9+
name: Check and Lint
10+
11+
jobs:
12+
check:
13+
name: Check
14+
runs-on: macos-latest
15+
steps:
16+
- uses: actions/checkout@v4
17+
- uses: actions-rs/toolchain@v1
18+
with:
19+
profile: minimal
20+
toolchain: nightly
21+
override: true
22+
- uses: actions-rs/cargo@v1
23+
with:
24+
command: check
25+
env:
26+
RUSTFLAGS: "-D warnings"
27+
28+
fmt:
29+
name: Rustfmt
30+
runs-on: ubuntu-latest
31+
steps:
32+
- uses: actions/checkout@v4
33+
- uses: actions-rs/toolchain@v1
34+
with:
35+
profile: minimal
36+
toolchain: nightly
37+
override: true
38+
- run: rustup component add rustfmt
39+
- uses: actions-rs/cargo@v1
40+
with:
41+
command: fmt
42+
args: --all -- --check
43+
44+
clippy:
45+
name: Clippy
46+
runs-on: macos-latest
47+
steps:
48+
- uses: actions/checkout@v4
49+
- uses: actions-rs/toolchain@v1
50+
with:
51+
toolchain: nightly
52+
components: clippy
53+
override: true
54+
- uses: actions-rs/cargo@v1
55+
with:
56+
command: clippy
57+
args: --all-features
58+
env:
59+
RUSTFLAGS: "-D warnings"
60+
61+
markdownlint:
62+
runs-on: ubuntu-latest
63+
steps:
64+
- uses: actions/checkout@v4
65+
- uses: nosborn/github-action-markdown-cli@v3.2.0
66+
with:
67+
files: .

.github/workflows/test.yml

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# https://github.com/BamPeers/rust-ci-github-actions-workflow
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- main
8+
9+
name: Test # with Code Coverage
10+
11+
jobs:
12+
test:
13+
name: Test
14+
env:
15+
PROJECT_NAME_UNDERSCORE: bpb_pkgx
16+
CARGO_INCREMENTAL: 0
17+
RUSTFLAGS: -Ccodegen-units=1 -Copt-level=0 -Clink-dead-code -Coverflow-checks=off -Zpanic_abort_tests -Cpanic=abort -D warnings
18+
RUSTDOCFLAGS: -Cpanic=abort
19+
runs-on: macos-latest
20+
steps:
21+
- uses: actions/checkout@v4
22+
- uses: actions-rs/toolchain@v1
23+
with:
24+
profile: minimal
25+
toolchain: nightly
26+
override: true
27+
- name: Cache dependencies
28+
uses: actions/cache@v2
29+
env:
30+
cache-name: cache-dependencies
31+
with:
32+
path: |
33+
~/.cargo/.crates.toml
34+
~/.cargo/.crates2.json
35+
~/.cargo/bin
36+
~/.cargo/registry/index
37+
~/.cargo/registry/cache
38+
target
39+
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('Cargo.lock') }}
40+
- uses: actions-rs/cargo@v1
41+
with:
42+
command: test
43+
args: --all-features
44+
45+
# coverage:
46+
# name: Coverage
47+
# runs-on: ubuntu-latest
48+
# steps:
49+
# - uses: actions/checkout@v4
50+
# - uses: actions-rs/toolchain@v1
51+
# with:
52+
# profile: minimal
53+
# toolchain: nightly
54+
# override: true
55+
# - name: Generate test result and coverage report
56+
# run: |
57+
# cargo install cargo-tarpaulin
58+
# cargo tarpaulin --engine ptrace -o lcov --output-dir coverage --coveralls $COVERALLS_TOKEN
59+
# env:
60+
# COVERALLS_TOKEN: ${{ secrets.COVERALLS_TOKEN }}

Cargo.lock

Lines changed: 16 additions & 48 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ authors = ["Without Boats <boats@mozilla.com>", "Jacob Heider <jacob@pkgx.dev>"]
1111
toml = "0.4.6"
1212
rand = { version = "0.8.5", features = ["std"] }
1313
sha2 = "0.7.1"
14-
serde_derive = "1.0.70"
15-
serde = "1.0.70"
14+
serde_derive = "1.0.215"
15+
serde = "1.0.215"
1616
hex = "0.3.2"
1717
failure = "0.1.1"
1818

README.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,15 @@ do.
66

77
## `pkgx` Updates
88

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

13+
### TODO
14+
15+
- [ ] Move keychain identifiers out to build variables in `config.rs`
16+
- [ ] Move keychain identifier out to a build variable in `keychain.rs`
17+
1318
## How to Install
1419

1520
```sh

src/config.rs

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
use std::io::{Read, Write};
1+
use std::io::Read;
22

33
use failure::Error;
44

55
use crate::key_data::KeyData;
66

7-
use crate::keychain::get_keychain_item;
8-
use crate::keychain::add_keychain_item;
7+
use crate::keychain::{add_keychain_item, get_keychain_item};
8+
9+
const KEYCHAIN_SERVICE: &str = "xyz.tea.BASE.bpb";
10+
const KEYCHAIN_ACCOUNT: &str = "example_account";
911

1012
#[derive(Serialize, Deserialize)]
1113
pub struct Config {
@@ -38,17 +40,14 @@ impl Config {
3840
}
3941

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

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

5453
pub fn timestamp(&self) -> u64 {
@@ -79,11 +78,11 @@ struct SecretKey {
7978

8079
impl SecretKey {
8180
fn secret(&self) -> Result<[u8; 32], Error> {
82-
if let Some(key) = &self.key {
83-
to_32_bytes(key)
84-
} else {
85-
bail!("No secret key or program specified")
86-
}
81+
if let Some(key) = &self.key {
82+
to_32_bytes(key)
83+
} else {
84+
bail!("No secret key or program specified")
85+
}
8786
}
8887
}
8988

0 commit comments

Comments
 (0)