pgrx icon indicating copy to clipboard operation
pgrx copied to clipboard

`prgx new` should generate `.github/workflow/ci.yaml` file

Open nyurik opened this issue 1 year ago • 3 comments

I think there should be a simple CI generated as part of the prgx new. Since most people tend to use github anyway, might as well give a github CI example - and it can be easily adjusted for other CI platforms if needed.

P.S. I think an example of packaging (on the release page) would also be very helpful, as it would save a lot of time for developers on figuring out how to package for different platforms.

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 0.11.4 --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

nyurik avatar May 06 '24 03:05 nyurik

This idea has come up before. Your example .yml file isn't quite enough.

It really needs to figure out the pgrx version used in Cargo.toml and cargo install cargo-pgrx --version $THAT_VERSION --locked. Ideally it would also configure a matrix for all the supported postgres versions, use apt to install that version of postgres and cargo pgrx init --pgXX=/path/to/$PGVER/bin/pg_config.

It might be useful to have macos included in the build matrix too. macos is a bit more difficult to configure, but it's doable.

eeeebbbbrrrr avatar May 06 '24 13:05 eeeebbbbrrrr

@eeeebbbbrrrr I agree it doesn't do everything - but we should start somewhere, right? :) Let's start from some documentation, e.g. something like my YAML above can be added to the README.md file - maybe under <detail> tag to make it collapsed by default - and we can slowly grow it to include different platforms and recommended packaging method.

In any case - having nothing is much worse than having a working example that only covers some of the usecases - so... let's do iterative approach?

nyurik avatar May 06 '24 17:05 nyurik

P.S. I have used this approach for MSRV reuse before -- perhaps we can adapt it for PRGX version copying too? This code uses regex to get rust-version from Cargo.toml, and uses it in another workflow step:

- name: Read crate metadata
  id: metadata
  run: echo "rust-version=$(sed -ne 's/rust-version *= *\"\(.*\)\"/\1/p' Cargo.toml)" >> $GITHUB_OUTPUT

- name: Install Rust
  uses: dtolnay/rust-toolchain@stable
  with:
    toolchain: ${{ steps.metadata.outputs.rust-version }}
    components: clippy,rustfmt

nyurik avatar May 06 '24 17:05 nyurik

closing based on https://github.com/pgcentralfoundation/pgrx/pull/1959#issuecomment-2566535202

workingjubilee avatar Jan 01 '25 06:01 workingjubilee