From c1fd88ee70802f238893d698466c66c2f8917a3d Mon Sep 17 00:00:00 2001 From: Tim Mensch Date: Tue, 3 Dec 2024 14:57:25 -0700 Subject: [PATCH] Issue #1694 --- cargo-pgrx/src/command/new.rs | 18 +++++++++++++++++ cargo-pgrx/src/templates/ci_yaml | 34 ++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 cargo-pgrx/src/templates/ci_yaml diff --git a/cargo-pgrx/src/command/new.rs b/cargo-pgrx/src/command/new.rs index ecbefc4c40..bdab9dc8ff 100644 --- a/cargo-pgrx/src/command/new.rs +++ b/cargo-pgrx/src/command/new.rs @@ -54,6 +54,7 @@ pub(crate) fn create_crate_template( create_directory_structure(path.clone())?; create_control_file(path.clone(), name)?; create_cargo_toml(path.clone(), name)?; + create_github_ci_yaml(path.clone())?; create_dotcargo_config_toml(path.clone(), name)?; create_lib_rs(path.clone(), name, is_bgworker)?; create_git_ignore(path.clone(), name)?; @@ -76,6 +77,12 @@ fn create_directory_structure(mut src_dir: PathBuf) -> Result<(), std::io::Error std::fs::create_dir_all(&src_dir)?; src_dir.pop(); + src_dir.push(".github"); + src_dir.push("workflow"); + std::fs::create_dir_all(&src_dir)?; + src_dir.pop(); + src_dir.pop(); + src_dir.push("sql"); std::fs::create_dir_all(&src_dir)?; src_dir.pop(); @@ -101,6 +108,17 @@ fn create_cargo_toml(mut filename: PathBuf, name: &str) -> Result<(), std::io::E Ok(()) } +fn create_github_ci_yaml(mut filename: PathBuf) -> Result<(), std::io::Error> { + filename.push(".github"); + filename.push("workflow"); + filename.push("ci.yaml"); + let mut file = std::fs::File::create(filename)?; + + file.write_all(include_bytes!("../templates/ci_yaml"))?; + + Ok(()) +} + fn create_dotcargo_config_toml(mut filename: PathBuf, _name: &str) -> Result<(), std::io::Error> { filename.push(".cargo"); filename.push("config.toml"); diff --git a/cargo-pgrx/src/templates/ci_yaml b/cargo-pgrx/src/templates/ci_yaml new file mode 100644 index 0000000000..c4e233c822 --- /dev/null +++ b/cargo-pgrx/src/templates/ci_yaml @@ -0,0 +1,34 @@ +name: CI + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + release: + types: [ published ] + workflow_dispatch: + +defaults: + run: + shell: bash + +jobs: + test: + name: Test + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: Swatinem/rust-cache@v2 + if: github.event_name != 'release' && github.event_name != 'workflow_dispatch' + # fmt test can be done before installing pgrx + - run: cargo fmt --all -- --check + # PRGX must be installed in order to compile pgrx-pg-sys + # PRGX version must match the version in Cargo.toml + - run: cargo install cargo-pgrx --version $(sed -ne 's/pgrx = *\"=\(.*\)\"/\1/p' Cargo.toml) --locked --force + - run: cargo pgrx init + - run: RUSTFLAGS='-D warnings' cargo build --workspace --all-targets --bins --tests --lib --benches --examples + - run: RUSTDOCFLAGS="-D warnings" cargo doc --no-deps + - run: cargo clippy -- -D warnings + - run: cargo clippy --workspace --all-targets --bins --tests --lib --benches --examples -- -D warnings + - run: cargo pgrx test \ No newline at end of file