Skip to content

Commit

Permalink
Update regenerate_providers (#147)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrzejressel authored May 1, 2024
1 parent 1f17428 commit d42a2b8
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 15 deletions.
11 changes: 7 additions & 4 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@ install-requirements:

build-wasm-components:
cargo component build -p pulumi_wasm \
-p pulumi_wasm_random_provider \
-p pulumi_wasm_docker_provider \
-p pulumi_wasm_example_simple \
-p pulumi_wasm_example_docker
# DO NOT EDIT - BUILD-WASM-COMPONENTS - START
cargo component build \
-p pulumi_wasm_docker_provider \
-p pulumi_wasm_random_provider \
# DO NOT EDIT - BUILD-WASM-COMPONENTS - END
cargo run -p cargo-pulumi -- -p pulumi_wasm_example_simple
cargo run -p cargo-pulumi -- -p pulumi_wasm_example_docker

Expand All @@ -36,13 +39,13 @@ fmt-clippy:
regenerate-provider-list:
cargo run -p regenerate_providers

# DO NOT EDIT - START
# DO NOT EDIT - REGENERATE-PROVIDERS - START
regenerate-providers:
cargo run -p cargo-pulumi-gen -- gen-provider --remove true --schema providers/docker.json --output providers/pulumi_wasm_provider_docker
cargo run -p cargo-pulumi-gen -- gen-rust --remove true --schema providers/docker.json --output providers/pulumi_wasm_provider_docker_rust
cargo run -p cargo-pulumi-gen -- gen-provider --remove true --schema providers/random.json --output providers/pulumi_wasm_provider_random
cargo run -p cargo-pulumi-gen -- gen-rust --remove true --schema providers/random.json --output providers/pulumi_wasm_provider_random_rust
# DO NOT EDIT - END
# DO NOT EDIT - REGENERATE-PROVIDERS - END

test:
cargo nextest run --workspace
Expand Down
41 changes: 30 additions & 11 deletions regenerate_providers/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@ use std::fs;
use std::process::Command;

#[derive(Debug)]
struct Provider {
name: String,
version: String,
struct Provider<'a> {
name: &'a str,
version: &'a str,
}

fn main() {
let providers = vec![
Provider {
name: String::from("docker"),
version: String::from("4.5.3"),
name: "docker",
version: "4.5.3",
},
Provider {
name: String::from("random"),
version: String::from("4.15.0"),
name: "random",
version: "4.15.0",
},
];

Expand Down Expand Up @@ -63,18 +63,37 @@ fn update_cargo_toml(providers: &[Provider]) {

fn update_justfile(providers: &[Provider]) {
let content = fs::read_to_string("justfile").expect("Failed to read justfile");
let content = replace_regenerate_providers(providers, &content);
let content = replace_build_wasm_components(providers, &content);

fs::write("justfile", content).expect("Failed to write to justfile");
}

fn replace_regenerate_providers(providers: &[Provider], content: &str) -> String {
let mut replacement = String::new();
for provider in providers {
replacement.push_str(&format!(" cargo run -p cargo-pulumi-gen -- gen-provider --remove true --schema providers/{}.json --output providers/pulumi_wasm_provider_{}\n", provider.name, provider.name));
replacement.push_str(&format!(" cargo run -p cargo-pulumi-gen -- gen-rust --remove true --schema providers/{}.json --output providers/pulumi_wasm_provider_{}_rust\n", provider.name, provider.name));
}

let start_marker = "# DO NOT EDIT - START\nregenerate-providers:";
let end_marker = "# DO NOT EDIT - END";
let new_content = replace_between_markers(&content, start_marker, end_marker, &replacement);
let start_marker = "# DO NOT EDIT - REGENERATE-PROVIDERS - START\nregenerate-providers:";
let end_marker = "# DO NOT EDIT - REGENERATE-PROVIDERS - END";
replace_between_markers(content, start_marker, end_marker, &replacement)
}

fn replace_build_wasm_components(providers: &[Provider], content: &str) -> String {
let mut replacement = String::new();
for provider in providers {
replacement.push_str(&format!(
" -p pulumi_wasm_{}_provider \\\n",
provider.name
));
}

fs::write("justfile", new_content).expect("Failed to write to justfile");
let start_marker =
" # DO NOT EDIT - BUILD-WASM-COMPONENTS - START\n cargo component build \\";
let end_marker = " # DO NOT EDIT - BUILD-WASM-COMPONENTS - END";
replace_between_markers(content, start_marker, end_marker, &replacement)
}

fn replace_between_markers(
Expand Down

0 comments on commit d42a2b8

Please sign in to comment.