Skip to content

Commit 3025559

Browse files
committed
gha
1 parent 0e362ab commit 3025559

File tree

6 files changed

+137
-2
lines changed

6 files changed

+137
-2
lines changed

.github/dependabot.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: "cargo"
4+
directory: "/"
5+
schedule:
6+
interval: "weekly"
7+
- package-ecosystem: "github-actions"
8+
directory: "/"
9+
schedule:
10+
interval: "weekly"
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name: Nightly build
2+
on:
3+
schedule:
4+
- cron: "51 3 * * *"
5+
workflow_dispatch:
6+
7+
jobs:
8+
lint-and-test-nightly:
9+
uses: ./.github/workflows/build.yml

.github/workflows/build.yml

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
name: Build
2+
on: [push, workflow_call]
3+
4+
permissions:
5+
contents: write
6+
7+
jobs:
8+
lint:
9+
runs-on: "windows-latest"
10+
steps:
11+
- uses: actions/checkout@v4
12+
- name: install stable rust
13+
run: rustup install stable
14+
- uses: Swatinem/rust-cache@v2
15+
- name: Format check
16+
run: cargo fmt --check
17+
- name: Clippy
18+
run: cargo clippy -- --deny warnings
19+
docs:
20+
runs-on: "windows-latest"
21+
steps:
22+
- uses: actions/checkout@v4
23+
- name: install stable rust
24+
run: rustup install stable
25+
- uses: Swatinem/rust-cache@v2
26+
- name: Build docs
27+
run: cargo doc --no-deps
28+
- name: Generate index.html
29+
shell: cmd
30+
# u wot?
31+
run: |
32+
echo|set /p="<meta http-equiv="refresh" content="0; url=ick/">" > target/doc/index.html
33+
exit /B 0
34+
- name: Upload artifacts (docs)
35+
uses: actions/upload-artifact@v4
36+
with:
37+
name: docs
38+
path: |
39+
target/doc
40+
if-no-files-found: error
41+
retention-days: 1
42+
- name: Deploy docs
43+
uses: peaceiris/actions-gh-pages@v3
44+
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/initial' }}
45+
with:
46+
publish_branch: gh-pages
47+
github_token: ${{ secrets.GITHUB_TOKEN }}
48+
publish_dir: target/doc
49+
force_orphan: true
50+
tests:
51+
runs-on: ${{ matrix.os }}
52+
strategy:
53+
matrix:
54+
os: [ "ubuntu-latest", "windows-latest" ]
55+
fail-fast: false
56+
steps:
57+
- uses: actions/checkout@v4
58+
- name: install stable rust
59+
run: rustup install stable
60+
- uses: Swatinem/rust-cache@v2
61+
with:
62+
key: ${{ matrix.os }}
63+
- name: Unit tests
64+
run: cargo test
65+
- name: Unit tests (release mode)
66+
run: cargo test --release
67+
- name: Build (debug)
68+
run: cargo build
69+
- name: Build (release)
70+
run: cargo build --release
71+
- name: Upload artifacts (debug)
72+
uses: actions/upload-artifact@v4
73+
with:
74+
name: ${{ format('debug-{0}', matrix.os) }}
75+
path: |
76+
target/debug/ick
77+
target/debug/ick.d
78+
target/debug/ick.exe
79+
target/debug/ick.pdb
80+
if-no-files-found: error
81+
retention-days: 1
82+
- name: Upload artifacts (release)
83+
uses: actions/upload-artifact@v4
84+
with:
85+
name: ${{ format('release-{0}', matrix.os) }}
86+
path: |
87+
target/release/ick
88+
target/release/ick.d
89+
target/release/ick.exe
90+
target/release/ick.pdb
91+
if-no-files-found: error
92+
retention-days: 1
93+
results:
94+
if: ${{ always() }}
95+
runs-on: ubuntu-latest
96+
name: Final Results
97+
needs: [tests, lint, docs]
98+
steps:
99+
- run: exit 1
100+
# see https://stackoverflow.com/a/67532120/4907315
101+
if: >-
102+
${{
103+
contains(needs.*.result, 'failure')
104+
|| contains(needs.*.result, 'cancelled')
105+
}}

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ keepass = "0.8.4"
1212
log = "0.4.27"
1313
serde = { version = "1.0.219", features = ["derive"] }
1414
serde_json = "1.0.143"
15+
16+
[target.'cfg(windows)'.dependencies]
1517
windows = { version = "0.61.3", features = ["Win32", "Win32_Security", "Win32_Security_Credentials" ] }
1618

1719
[dev-dependencies]

src/lib.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ use clap_verbosity_flag::InfoLevel;
8080
use log::{debug, trace};
8181

8282
mod credentials;
83+
#[cfg(target_os = "windows")]
8384
mod wincred;
8485

8586
#[derive(Debug, Args)]
@@ -132,9 +133,11 @@ struct App {
132133
#[derive(Subcommand, Debug)]
133134
enum Commands {
134135
/// Add credentials to the windows credential store
136+
#[cfg(target_os = "windows")]
135137
AddCreds {},
136138

137139
/// Remove credentials from the windows credential store
140+
#[cfg(target_os = "windows")]
138141
RemoveCreds {},
139142

140143
/// Retrieve credentials for all specified machines in JSON format, for use
@@ -150,12 +153,14 @@ enum Commands {
150153
},
151154
}
152155

156+
#[cfg(target_os = "windows")]
153157
fn add_win_creds<T: AsRef<str>>(instruments: &[T], admin: bool) -> anyhow::Result<()> {
154158
credentials::get_credentials(instruments, admin, None)?
155159
.iter()
156160
.try_for_each(wincred::add_win_cred)
157161
}
158162

163+
#[cfg(target_os = "windows")]
159164
fn remove_win_creds<T: AsRef<str>>(instruments: &[T]) -> anyhow::Result<()> {
160165
instruments
161166
.iter()
@@ -214,8 +219,12 @@ pub fn run() -> anyhow::Result<()> {
214219
let machines = get_machines(&args)?;
215220

216221
match args.command {
222+
#[cfg(target_os = "windows")]
217223
Commands::AddCreds {} => add_win_creds(&machines, args.global_opts.admin),
224+
225+
#[cfg(target_os = "windows")]
218226
Commands::RemoveCreds {} => remove_win_creds(&machines),
227+
219228
Commands::Json { pretty } => print_json(&machines, args.global_opts.admin, pretty),
220229
}
221230
}
@@ -251,7 +260,7 @@ bar
251260
instruments_file: None,
252261
admin: false,
253262
},
254-
command: Commands::RemoveCreds {},
263+
command: Commands::Json { pretty: false },
255264
});
256265

257266
assert!(result.is_err_and(|e| { e.to_string().contains("No machines specified") }));

src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ fn main() -> ExitCode {
77
Ok(_) => {
88
trace!("Exiting successfully");
99
ExitCode::SUCCESS
10-
},
10+
}
1111
Err(s) => {
1212
error!("{s}");
1313
ExitCode::FAILURE

0 commit comments

Comments
 (0)