Skip to content

Commit

Permalink
chore: initial CI configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
brianheineman committed Feb 5, 2024
1 parent ffb0aff commit a9c66ea
Show file tree
Hide file tree
Showing 9 changed files with 843 additions and 4 deletions.
56 changes: 56 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: Build & Test

env:
CARGO_TERM_COLOR: always
RUSTFLAGS: "-D warnings"

on:
workflow_call:
inputs:
ref:
default: ${{ github.ref }}
type: string

jobs:
build:
name: ${{ matrix.platform }} (${{ matrix.target }}) (${{ matrix.os }})
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
platform:
- linux-x64
- macos-arm64
- macos-x64
- windows-x64

include:
- platform: linux-x64
os: ubuntu-latest
- platform: macos-arm64
os: macos-14
- platform: macos-x64
os: macos-13
- platform: windows-x64
os: windows-latest

steps:
- name: Checkout source code
uses: actions/checkout@v4
with:
ref: ${{ inputs.ref }}

- name: Install Rust
uses: dtolnay/rust-toolchain@master
with:
toolchain: stable

- name: Tests
run: |
cargo test --package postgresql_archive
cargo test --package postgresql_archive --all-features
cargo test --package postgresql_embedded
cargo test --package postgresql_embedded --features blocking
cargo test --package postgresql_embedded --features bundled
cargo test --package postgresql_embedded --features tokio
cargo test --package postgresql_embedded --all-features
110 changes: 110 additions & 0 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
name: Fast checks

env:
CARGO_TERM_COLOR: always
RUSTFLAGS: "-D warnings"

on:
workflow_call:

jobs:
audit:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@master
with:
toolchain: stable
- name: Install cargo audit
run: cargo install cargo-audit
- name: Audit dependencies
run: cargo audit

check:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@master
with:
toolchain: stable
- name: Check the project
run: |
cargo check --workspace --all-targets --features blocking
cargo check --workspace --all-targets --features bundled
cargo check --workspace --all-targets --features tokio
cargo check --workspace --all-targets --all-features
deny:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@master
with:
toolchain: stable
- name: Install cargo deny
run: cargo install cargo-deny
- name: Check licenses
run: cargo deny check --allow duplicate

docs:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@master
with:
toolchain: stable
- name: Check documentation
env:
RUSTDOCFLAGS: -D warnings
run: cargo doc --workspace --no-deps --document-private-items --all-features

format:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@master
with:
toolchain: stable
components: rustfmt
- name: Check formatting
run: cargo fmt --all --check

lint:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@master
with:
toolchain: stable
- name: Check lints
run: |
cargo clippy --workspace --features blocking
cargo clippy --workspace --features bundled
cargo clippy --workspace --features tokio
cargo clippy --workspace --all-features
vet:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@master
with:
toolchain: stable
- name: Install cargo vet
run: cargo install cargo-vet
- name: Vet thirdparty dependencies
run: cargo vet check
41 changes: 41 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: ci

on:
push:
branches:
- main
pull_request:
branches:
- main

permissions:
contents: read

jobs:
initialize:
name: Initialize
runs-on: ubuntu-latest
steps:
- name: Get PR head ref
if: ${{ github.event_name == 'pull_request' }}
id: pr_head_ref
run: |
echo "ref=refs/pull/${{ github.event.pull_request.number }}/head" >> $GITHUB_OUTPUT
outputs:
ref: >-
${{
(github.event_name == 'pull_request' && startsWith(github.head_ref, 'release/v'))
&& steps.pr_head_ref.outputs.ref
|| github.ref
}}
checks:
name: Checks
uses: ./.github/workflows/checks.yml

build:
name: Build & Test
needs: [initialize, checks]
uses: ./.github/workflows/build.yml
with:
ref: ${{ needs.init.outputs.ref }}
6 changes: 3 additions & 3 deletions postgresql_archive/src/blocking/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ lazy_static! {

/// Gets the version of PostgreSQL for the specified [`version`](Version). If the version minor or release is not
/// specified, then the latest version is returned. If a release for the [`version`](Version) is not found, then a
/// [`ReleaseNotFound`] error is returned.
/// [`ReleaseNotFound`](crate::ArchiveError::ReleaseNotFound) error is returned.
pub fn get_version(version: &Version) -> crate::Result<Version> {
RUNTIME
.handle()
.block_on(async move { crate::get_version(version).await })
}

/// Gets the archive for a given [`version`](Version) of PostgreSQL for the current target.
/// If the [`version`](Version) is not found for this target, then an [error](Archive) is returned.
/// If the [`version`](Version) is not found for this target, then an [error](crate::ArchiveError) is returned.
///
/// Returns the archive bytes and the archive hash.
pub fn get_archive(version: &Version) -> crate::Result<(Version, Bytes, String)> {
Expand All @@ -27,7 +27,7 @@ pub fn get_archive(version: &Version) -> crate::Result<(Version, Bytes, String)>
}

/// Gets the archive for a given [`version`](Version) of PostgreSQL and `target` (e.g. `x86_64-unknown-linux-gnu`).
/// If the [`version`](Version) or `target` is not found, then an [error](ArchiveError) is returned.
/// If the [`version`](Version) or `target` is not found, then an [error](crate::ArchiveError) is returned.
///
/// Returns the archive bytes and the archive hash.
pub fn get_archive_for_target<S: AsRef<str>>(
Expand Down
2 changes: 1 addition & 1 deletion postgresql_embedded/src/command/psql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ impl PsqlBuilder {
self
}

/// database name to connect to (default: "<host user>")
/// database name to connect to
pub fn dbname<S: AsRef<OsStr>>(mut self, dbname: S) -> Self {
self.dbname = Some(dbname.as_ref().to_os_string());
self
Expand Down
1 change: 1 addition & 0 deletions postgresql_embedded/src/command/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ mod test {
assert_eq!(r#"cd "/tmp" && "foo" "-l""#, command.to_command_string(),);
}

#[cfg(feature = "tokio")]
#[tokio::test]
async fn test_standard_command_execute() -> Result<()> {
#[cfg(not(target_os = "windows"))]
Expand Down
4 changes: 4 additions & 0 deletions supply-chain/audits.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

# cargo-vet audits file

[audits]
Loading

0 comments on commit a9c66ea

Please sign in to comment.