Skip to content

Commit

Permalink
Issue #1694
Browse files Browse the repository at this point in the history
  • Loading branch information
TimMensch committed Dec 3, 2024
1 parent eda7549 commit c1fd88e
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
18 changes: 18 additions & 0 deletions cargo-pgrx/src/command/new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
Expand All @@ -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();
Expand All @@ -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");
Expand Down
34 changes: 34 additions & 0 deletions cargo-pgrx/src/templates/ci_yaml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit c1fd88e

Please sign in to comment.