Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #1694/Github Actions ci.yaml file create #1959

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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