Skip to content

Commit

Permalink
fix: Use correct source when merging JSON/YAML. (#1189)
Browse files Browse the repository at this point in the history
* Update CI.

* Fix template.
  • Loading branch information
milesj authored Nov 17, 2023
1 parent d7e239a commit dbdb37e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ jobs:
- uses: actions/checkout@v4
- uses: moonrepo/setup-rust@v1
with:
cache: false
components: rustfmt
- name: Check formatting
run: cargo fmt --all --check
Expand All @@ -52,6 +53,7 @@ jobs:
- uses: moonrepo/setup-rust@v1
with:
bins: cargo-make
cache-base: '^(master|develop-)'
components: clippy
- uses: mozilla-actions/[email protected]
- name: Run linter
Expand All @@ -70,8 +72,8 @@ jobs:
- uses: moonrepo/setup-rust@v1
with:
bins: cargo-make, cargo-nextest, cargo-llvm-cov
cache-base: '^(master|develop-)'
components: llvm-tools-preview
cache: false
- uses: mozilla-actions/[email protected]
- name: Run tests
if: ${{ env.WITH_COVERAGE == 'false' }}
Expand Down
7 changes: 5 additions & 2 deletions nextgen/codegen/src/template.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::asset_file::AssetFile;
use crate::template_file::{FileState, TemplateFile};
use crate::{filters, CodegenError};
use miette::IntoDiagnostic;
use moon_common::consts::CONFIG_TEMPLATE_FILENAME;
use moon_common::path::{to_virtual_string, RelativePathBuf};
use moon_common::Id;
Expand Down Expand Up @@ -231,7 +232,8 @@ impl Template {
match file.is_mergeable() {
Some("json") => {
let prev: json::JsonValue = json::read_file(&file.dest_path)?;
let next: json::JsonValue = json::read_file(&file.source_path)?;
let next: json::JsonValue =
json::from_str(&file.content).into_diagnostic()?;

json::write_file_with_config(
&file.dest_path,
Expand All @@ -241,7 +243,8 @@ impl Template {
}
Some("yaml") => {
let prev: yaml::YamlValue = yaml::read_file(&file.dest_path)?;
let next: yaml::YamlValue = yaml::read_file(&file.source_path)?;
let next: yaml::YamlValue =
yaml::from_str(&file.content).into_diagnostic()?;

yaml::write_file_with_config(&file.dest_path, &yaml::merge(&prev, &next))?;
}
Expand Down
1 change: 1 addition & 0 deletions packages/cli/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#### 🐞 Fixes

- Fixed an issue where codegen would merge JSON/YAML files with the incorrect source.
- Updated file traversal to not walk outside of the workspace root.

#### ⚙️ Internal
Expand Down

0 comments on commit dbdb37e

Please sign in to comment.