Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
aspect committed Jul 22, 2024
1 parent eda7bd3 commit 3bf437f
Show file tree
Hide file tree
Showing 6 changed files with 155 additions and 8 deletions.
100 changes: 100 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
name: Tests

on: [push, pull_request]

jobs:

lints:
name: Lints
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v4

- name: Install stable toolchain
uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt, clippy

- name: Cache
uses: actions/cache@v4
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}

- name: Run cargo fmt
run: cargo fmt --all -- --check

check-native:
name: Check
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v4

- name: Install stable toolchain
uses: dtolnay/rust-toolchain@stable
with:
components: clippy

- name: Cache
uses: actions/cache@v4
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}

- name: Run cargo clippy
run: cargo clippy --workspace --tests --benches -- -D warnings

test:
name: Test Suite
runs-on: ubuntu-latest
strategy:
fail-fast: false
steps:

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

- name: Fix CRLF on Windows
if: runner.os == 'Windows'
run: git config --global core.autocrlf false

- name: Install stable toolchain
uses: dtolnay/rust-toolchain@stable

- name: Set up cache
uses: Swatinem/rust-cache@v2

- name: Install cargo-nextest
run: cargo install cargo-nextest

- name: Cache
uses: actions/cache@v4
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}

- name: Run cargo build with devnet-prealloc feature
run: cargo build --release

- name: Run cargo test regular features
run: cargo nextest run --release

- name: Run cargo doc tests
run: cargo test --doc --release
26 changes: 23 additions & 3 deletions src/actions/configure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use nginx::prelude::*;
#[derive(Describe, Eq, PartialEq, Debug, Clone, Copy)]
#[caption = "Configure"]
pub enum Configure {
/// Go back to the previous menu
#[describe("Back")]
Back,
// #[describe("Fail")]
Expand All @@ -15,12 +14,18 @@ pub enum Configure {
// Verbose,
#[describe("Enable / Disable services")]
Enable,
#[describe("Configure SSL certificates")]
Tls,
#[describe("Rebuild configuration")]
Rebuild,
#[describe("Restart all services")]
Restart,
// #[describe("Start all services")]
// Start,
// #[describe("Stop all services")]
// Stop,
#[describe("View configuration files")]
View,
#[describe("Configure SSL certificates")]
Tls,
}

impl Action for Configure {
Expand Down Expand Up @@ -176,6 +181,21 @@ impl Action for Configure {
nginx::reconfigure(ctx)?;
Ok(true)
}
Configure::Restart => {
kaspad::restart_all(ctx)?;
resolver::restart(ctx)?;
nginx::reconfigure(ctx)?;
Ok(true)
} // Configure::Start => {
// kaspad::start_all(ctx)?;
// resolver::start(ctx)?;
// Ok(true)
// }
// Configure::Stop => {
// kaspad::stop_all(ctx)?;
// resolver::stop(ctx)?;
// Ok(true)
// }
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/actions/status.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::imports::*;

#[derive(Describe, Eq, PartialEq, Debug, Clone, Copy)]
#[caption = "Manage"]
#[caption = "Status"]
pub enum Status {
#[describe("Back")]
Back,
Expand Down
17 changes: 17 additions & 0 deletions src/kaspad.rs
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,23 @@ pub fn start_all(ctx: &Context) -> Result<()> {
Ok(())
}

pub fn restart_all(ctx: &Context) -> Result<()> {
for config in active_configs(ctx) {
step(
format!(
"Restarting {} ({})",
config.service_title(),
config.service_name()
),
|| {
systemd::restart(config)?;
Ok(())
},
)?;
}
Ok(())
}

pub fn purge_data_folder_all(ctx: &Context) -> Result<()> {
for config in active_configs(ctx) {
purge_data_folder(config)?;
Expand Down
16 changes: 13 additions & 3 deletions src/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ pub fn update(ctx: &Context) -> Result<()> {

fetch(&config.origin)?;
build(&config.origin)?;
restart(config)?;
restart(ctx)?;
Ok(())
}

Expand Down Expand Up @@ -268,8 +268,18 @@ pub fn create_systemd_unit(ctx: &Context, config: &Config) -> Result<()> {
Ok(())
}

pub fn restart(config: &Config) -> Result<()> {
step("Restarting resolver...", || systemd::restart(config))
pub fn start(ctx: &Context) -> Result<()> {
systemd::start(&ctx.config.resolver)
}

pub fn stop(ctx: &Context) -> Result<()> {
systemd::restart(&ctx.config.resolver)
}

pub fn restart(ctx: &Context) -> Result<()> {
step("Restarting resolver...", || {
systemd::restart(&ctx.config.resolver)
})
}

pub fn status(config: &Config) -> Result<String> {
Expand Down
2 changes: 1 addition & 1 deletion src/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ impl Display for Status {
self.system
.system_id
.as_ref()
.map(|id| style(format!("{id:x}")).cyan().bright())
.map(|id| style(format!("{id:016x}")).cyan().bright())
.unwrap_or(style("N/A".to_string()).red().bright()),
));
rows.push(Content::field(
Expand Down

0 comments on commit 3bf437f

Please sign in to comment.