Skip to content

Commit

Permalink
Merge pull request #1472 from messense/new-generate-ci
Browse files Browse the repository at this point in the history
Replace `CI.yml` template with `generate-ci`
  • Loading branch information
messense authored Feb 9, 2023
2 parents 5028681 + 3cc8278 commit 288c920
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 74 deletions.
6 changes: 5 additions & 1 deletion src/ci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,11 @@ impl GenerateCI {
}
}

fn generate_github(&self, project_name: &str, bridge_model: &BridgeModel) -> Result<String> {
pub(crate) fn generate_github(
&self,
project_name: &str,
bridge_model: &BridgeModel,
) -> Result<String> {
let is_abi3 = matches!(bridge_model, BridgeModel::BindingsAbi3(..));
let is_bin = bridge_model.is_bin();
let setup_python = self.pytest
Expand Down
23 changes: 20 additions & 3 deletions src/new_project.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use crate::ci::GenerateCI;
use crate::BridgeModel;
use anyhow::{bail, Context, Result};
use console::style;
use dialoguer::{theme::ColorfulTheme, Select};
Expand All @@ -18,6 +20,7 @@ struct ProjectGenerator<'a> {
crate_name: String,
bindings: String,
layout: ProjectLayout,
ci_config: String,
overwrite: bool,
}

Expand All @@ -40,14 +43,23 @@ impl<'a> ProjectGenerator<'a> {
env.add_template("main.rs", include_str!("templates/main.rs.j2"))?;
env.add_template("build.rs", include_str!("templates/build.rs.j2"))?;
env.add_template("__init__.py", include_str!("templates/__init__.py.j2"))?;
env.add_template("CI.yml", include_str!("templates/CI.yml.j2"))?;
env.add_template("example.udl", include_str!("templates/example.udl.j2"))?;

let bridge_model = match bindings.as_str() {
"bin" => BridgeModel::Bin(None),
"cffi" => BridgeModel::Cffi,
"uniffi" => BridgeModel::UniFfi,
_ => BridgeModel::Bindings(bindings.clone(), 7),
};
let ci_config = GenerateCI::default().generate_github(&project_name, &bridge_model)?;

Ok(Self {
env,
project_name,
crate_name,
bindings,
layout,
ci_config,
overwrite,
})
}
Expand All @@ -60,7 +72,7 @@ impl<'a> ProjectGenerator<'a> {
// CI configuration
let gh_action_path = project_path.join(".github").join("workflows");
fs::create_dir_all(&gh_action_path)?;
self.write_project_file(&gh_action_path, "CI.yml")?;
self.write_content(&gh_action_path, "CI.yml", self.ci_config.as_bytes())?;

let rust_project = match self.layout {
ProjectLayout::Mixed { src } => {
Expand Down Expand Up @@ -114,9 +126,14 @@ impl<'a> ProjectGenerator<'a> {
}

fn write_project_file(&self, directory: &Path, file: &str) -> Result<()> {
let content = self.render_template(file)?;
self.write_content(directory, file, content.as_bytes())
}

fn write_content(&self, directory: &Path, file: &str, content: &[u8]) -> Result<()> {
let path = directory.join(file);
if self.overwrite || !path.exists() {
fs::write(path, self.render_template(file)?)?;
fs::write(path, content)?;
}
Ok(())
}
Expand Down
70 changes: 0 additions & 70 deletions src/templates/CI.yml.j2

This file was deleted.

0 comments on commit 288c920

Please sign in to comment.