Skip to content

Commit

Permalink
Add --sync flag to use latest schemes with build subcommand
Browse files Browse the repository at this point in the history
- Simplify github action
  • Loading branch information
JamyGolden committed Jun 23, 2024
1 parent 47dc398 commit 34c7243
Show file tree
Hide file tree
Showing 9 changed files with 83 additions and 16 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## [0.9.0] - 2024-06-23

### Added

- Add `--sync` flag for the `build` subcommand to sync before building

## [0.8.0] - 2024-06-23

### Added
Expand Down Expand Up @@ -99,6 +105,8 @@
- `sync` subcommand support to sync with latest Tinted Theming schemes
- `build` subcommand to trigger theme template build

[0.9.0]: https://github.com/tinted-theming/tinted-builder-rust/compare/v0.8.0...v0.9.0
[0.8.0]: https://github.com/tinted-theming/tinted-builder-rust/compare/v0.7.0...v0.8.0
[0.7.0]: https://github.com/tinted-theming/tinted-builder-rust/compare/v0.6.1...v0.7.0
[0.6.1]: https://github.com/tinted-theming/tinted-builder-rust/compare/v0.6.0...v0.6.1
[0.6.0]: https://github.com/tinted-theming/tinted-builder-rust/compare/v0.5.0...v0.6.0
Expand Down
2 changes: 1 addition & 1 deletion 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 README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ The following is a table of the available subcommands for the CLI tool (tinted-b

| Subcommand | Description | Arguments | Example Usage | Flags |
|------------|--------------------------------------|----------------------|--------------------------------------------|-------|
| `sync` | Installs and or updates latest schemes. | - | `tinted-builder-rust sync` | `--quiet` or `-q` to silence output |
| `build` | Builds the themes of a template. | `template_path`: Path to template directory. | `tinted-builder-rust build ./path/to/base16-template` | `--quiet` or `-q` to silence output |
| `sync` | Installs and or updates latest schemes. | - | `tinted-builder-rust sync` | `--quiet` (silence stderr and stdout) |
| `build` | Builds the themes of a template. | `template_path`: Path to template directory. | `tinted-builder-rust build ./path/to/base16-template` | `--quiet` (silence stderr and stdout), `--sync` (equivalent of running `tinted-builder-rust sync` before `tinted-builder-rust build`) |

## Flags

Expand Down
12 changes: 5 additions & 7 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
name: "Tinted Builder Rust"
description: "Build all the schemes for a base16 or tinted repo"
name: 'Tinted Builder Rust'
description: 'Build all the schemes for a base16 or tinted repo'

runs:
using: "docker"
image: "Dockerfile"
entrypoint: "/bin/sh -c"
args:
- "tinted-builder-rust sync && tinted-builder-rust build ."
using: 'docker'
image: 'docker://ghcr.io/tinted-theming/tinted-builder-rust:v0.8.0'
args: 'build . --sync'
2 changes: 1 addition & 1 deletion tinted-builder-rust/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "tinted-builder-rust"
version = "0.8.0"
version = "0.9.0"
edition = "2021"
authors = ["Jamy Golden <[email protected]>", "Tinted Theming <[email protected]>"]
license = "MIT OR Apache-2.0"
Expand Down
8 changes: 4 additions & 4 deletions tinted-builder-rust/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ tinted-builder-rust build path/to/base16-template

The following is a table of the available subcommands for the CLI tool (tinted-builder-rust), including the descriptions and any notable arguments.

| Subcommand | Description | Arguments | Example Usage |
|------------|--------------------------------------|----------------------|--------------------------------------------|
| `sync` | Installs and or updates latest schemes. | - | `tinted-builder-rust sync` |
| `build` | Builds the themes of a template. | `template_path`: Path to template directory. | `tinted-builder-rust build ./path/to/base16-template` |
| Subcommand | Description | Arguments | Example Usage | Flags |
|------------|--------------------------------------|----------------------|--------------------------------------------|-------|
| `sync` | Installs and or updates latest schemes. | - | `tinted-builder-rust sync` | `--quiet` (silence stderr and stdout) |
| `build` | Builds the themes of a template. | `template_path`: Path to template directory. | `tinted-builder-rust build ./path/to/base16-template` | `--quiet` (silence stderr and stdout), `--sync` (equivalent of running `tinted-builder-rust sync` before `tinted-builder-rust build`) |

## Flags

Expand Down
6 changes: 6 additions & 0 deletions tinted-builder-rust/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ fn build_cli() -> Command {
.short('q')
.help("Silence stdout")
.action(ArgAction::SetTrue),
)
.arg(
Arg::new("sync")
.long("sync")
.help("Sync with latest schemes before build")
.action(ArgAction::SetTrue),
),
)
.subcommand(
Expand Down
7 changes: 6 additions & 1 deletion tinted-builder-rust/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,17 @@ fn main() -> Result<()> {

match matches.subcommand() {
Some(("build", sub_matches)) => {
if let (Some(template_dir), Some(is_quiet)) = (
if let (Some(template_dir), Some(is_quiet), Some(sync)) = (
sub_matches.get_one::<String>("template-dir"),
sub_matches.get_one::<bool>("quiet"),
sub_matches.get_one::<bool>("sync"),
) {
let template_path = PathBuf::from(template_dir);

if *sync {
operations::sync::sync(&schemes_path, *is_quiet)?;
}

operations::build::build(&template_path, &schemes_path, *is_quiet)?;
}
}
Expand Down
50 changes: 50 additions & 0 deletions tinted-builder-rust/tests/operation_build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,56 @@ fn test_operation_build_quiet_flag() -> Result<()> {
Ok(())
}

#[test]
fn test_operation_build_with_sync() -> Result<()> {
// -------
// Arrange
// -------
let name = "test_operation_build_with_sync";
let template_theme_path = PathBuf::from(format!("./template-{}", name));
let name = "test_operation_sync_first_time";
let expected_output = "schemes installed";
let expected_schemes_path = PathBuf::from(format!("./{}/schemes", name));
println!("expect: {:?}", expected_schemes_path);
let expected_data_path = PathBuf::from(name);
let expected_git_clone_str = format!("Cloning into '{}/schemes'", name);
if expected_data_path.exists() {
fs::remove_dir_all(&expected_data_path)?;
fs::create_dir(expected_data_path)?;
}

// ---
// Act
// ---
// Build act
let (stdout, stderr) = utils::run_command(vec![
COMMAND_NAME.to_string(),
format!("--data-dir={}", name),
"build".to_string(),
template_theme_path.display().to_string(),
"--sync".to_string(),
])
.unwrap();

// Sync act
let is_schemes_dir_empty = fs::read_dir(&expected_schemes_path)?.next().is_none();

// ------
// Assert
// ------
assert!(
stdout.contains(expected_output),
"stdout does not contain the expected output"
);
assert!(
stderr.contains(&expected_git_clone_str),
"stderr does not contain the expected output"
);
assert!(expected_schemes_path.exists() && !is_schemes_dir_empty,);

Ok(())
}

/// Tests schemes/*.yaml generation with base16 system
#[test]
fn test_operation_build_base16() -> Result<()> {
Expand Down

0 comments on commit 34c7243

Please sign in to comment.