Skip to content

chore/tooling ci #165

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

Merged
merged 23 commits into from
Jan 6, 2025
16 changes: 16 additions & 0 deletions .github/actions/free-disk-space/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Free Disk Space
description: Free up disk space on the runner
runs:
using: composite
steps:
- name: Free Disk Space (Ubuntu)
if: runner.os == 'Linux'
uses: jlumbroso/free-disk-space@main
with:
# We need to reclaim some space, but uninstalling everyting takes
# too long. So we'll just remove some of the larger packages.
# https://github.com/jlumbroso/free-disk-space/pull/26
android: true
dotnet: true
haskell: true
large-packages: false
21 changes: 0 additions & 21 deletions .github/actions/setup-monorepo/action.yml

This file was deleted.

57 changes: 0 additions & 57 deletions .github/workflows/ci.yml

This file was deleted.

183 changes: 183 additions & 0 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
name: Pull Request

on:
workflow_dispatch:
pull_request:
paths: # Only run when changes are made to rust code or root Cargo
- "crates/**"
- "lib/**"
- "fuzz/**"
- "xtask/**"
- "Cargo.toml"
- "Cargo.lock"
- "rust-toolchain.toml"
- "rustfmt.toml"

concurrency:
group: ${{ github.workflow }}-${{ github.event_name }}-${{ github.ref }}
cancel-in-progress: true

env:
RUSTFLAGS: -A dead_code
RUST_LOG: info
RUST_BACKTRACE: 1
RUSTUP_WINDOWS_PATH_ADD_BIN: 1

jobs:
format:
name: Format
runs-on: ubuntu-latest
steps:
- name: Checkout PR branch
uses: actions/checkout@v4
- name: Free Disk Space
uses: ./.github/actions/free-disk-space
- name: Install toolchain
uses: moonrepo/setup-rust@v1
with:
components: rustfmt
bins: taplo-cli
cache-base: main
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Run format
run: |
cargo fmt --all --check
taplo format --check

actionlint:
name: Lint GitHub Actions
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Download actionlint
id: get_actionlint
run: bash <(curl https://raw.githubusercontent.com/rhysd/actionlint/main/scripts/download-actionlint.bash)
shell: bash
- name: Check workflow files
run: ${{ steps.get_actionlint.outputs.executable }} -color
shell: bash

lint:
name: Lint Project
runs-on: ubuntu-latest
services:
postgres:
image: postgres:latest
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: postgres
ports:
- 5432:5432
steps:
- name: Checkout PR Branch
uses: actions/checkout@v4
with:
submodules: true
- name: Free Disk Space
uses: ./.github/actions/free-disk-space
- name: Install toolchain
uses: moonrepo/setup-rust@v1
with:
components: clippy
cache-base: main
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Run clippy
run: |
cargo clippy
cargo run -p rules_check

# check-dependencies:
# name: Check Dependencies
# runs-on: ubuntu-latest
# services:
# postgres:
# image: postgres:latest
# env:
# POSTGRES_USER: postgres
# POSTGRES_PASSWORD: postgres
# POSTGRES_DB: postgres
# ports:
# - 5432:5432
# steps:
# - name: Checkout PR Branch
# uses: actions/checkout@v4
# with:
# submodules: true
# - name: Free Disk Space
# uses: ./.github/actions/free-disk-space
# - name: Install toolchain
# run: rustup toolchain install nightly
# - name: Install udeps
# run: cargo install cargo-udeps --locked
# - name: Detect unused dependencies using udeps
# run: cargo +nightly udeps --all-targets

test:
name: Test
runs-on: ${{ matrix.os }}
strategy:
matrix:
include:
# reactive once we upgrade to the latest version of pg_query that is windows-compatible
# - os: windows-latest
- os: ubuntu-latest
steps:
- name: Checkout PR branch
uses: actions/checkout@v4
with:
submodules: true
- name: Free Disk Space
uses: ./.github/actions/free-disk-space
- name: Install toolchain
uses: moonrepo/setup-rust@v1
with:
cache-base: main
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

# running containers via `services` only works on linux
# https://github.com/actions/runner/issues/1866
- name: Setup postgres
uses: ikalnytskyi/action-setup-postgres@v7
- name: Run tests
run: cargo test --workspace

codegen:
name: Check Codegen
runs-on: ubuntu-latest
services:
postgres:
image: postgres:latest
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: postgres
ports:
- 5432:5432
steps:
- name: Checkout PR branch
uses: actions/checkout@v4
with:
submodules: true
- name: Free Disk Space
uses: ./.github/actions/free-disk-space
- name: Install toolchain
uses: moonrepo/setup-rust@v1
with:
cache-base: main
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Run the analyser codegen
run: cargo run -p xtask_codegen -- analyser
- name: Run the configuration codegen
run: cargo run -p xtask_codegen -- configuration
- name: Check for git diff
run: |
if [[ $(git status --porcelain) ]]; then
git status
git diff
exit 1
fi
24 changes: 12 additions & 12 deletions crates/pg_completions/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ impl TryFrom<&str> for ClauseType {
panic!("{}", message);
}

return Err(message);
Err(message)
}
}
}
Expand Down Expand Up @@ -215,7 +215,7 @@ mod tests {

let params = crate::CompletionParams {
position: (position as u32).into(),
text: text,
text,
tree: Some(&tree),
schema: &pg_schema_cache::SchemaCache::new(),
};
Expand Down Expand Up @@ -247,7 +247,7 @@ mod tests {
let tree = get_tree(text.as_str());
let params = crate::CompletionParams {
position: (position as u32).into(),
text: text,
text,
tree: Some(&tree),
schema: &pg_schema_cache::SchemaCache::new(),
};
Expand Down Expand Up @@ -281,7 +281,7 @@ mod tests {
let tree = get_tree(text.as_str());
let params = crate::CompletionParams {
position: (position as u32).into(),
text: text,
text,
tree: Some(&tree),
schema: &pg_schema_cache::SchemaCache::new(),
};
Expand All @@ -306,14 +306,14 @@ mod tests {

let params = crate::CompletionParams {
position: (position as u32).into(),
text: text,
text,
tree: Some(&tree),
schema: &pg_schema_cache::SchemaCache::new(),
};

let ctx = CompletionContext::new(&params);

let node = ctx.ts_node.map(|n| n.clone()).unwrap();
let node = ctx.ts_node.unwrap();

assert_eq!(ctx.get_ts_node_content(node), Some("select"));

Expand All @@ -334,14 +334,14 @@ mod tests {

let params = crate::CompletionParams {
position: (position as u32).into(),
text: text,
text,
tree: Some(&tree),
schema: &pg_schema_cache::SchemaCache::new(),
};

let ctx = CompletionContext::new(&params);

let node = ctx.ts_node.map(|n| n.clone()).unwrap();
let node = ctx.ts_node.unwrap();

assert_eq!(ctx.get_ts_node_content(node), Some("from"));
assert_eq!(
Expand All @@ -360,14 +360,14 @@ mod tests {

let params = crate::CompletionParams {
position: (position as u32).into(),
text: text,
text,
tree: Some(&tree),
schema: &pg_schema_cache::SchemaCache::new(),
};

let ctx = CompletionContext::new(&params);

let node = ctx.ts_node.map(|n| n.clone()).unwrap();
let node = ctx.ts_node.unwrap();

assert_eq!(ctx.get_ts_node_content(node), Some(""));
assert_eq!(ctx.wrapping_clause_type, None);
Expand All @@ -385,14 +385,14 @@ mod tests {

let params = crate::CompletionParams {
position: (position as u32).into(),
text: text,
text,
tree: Some(&tree),
schema: &pg_schema_cache::SchemaCache::new(),
};

let ctx = CompletionContext::new(&params);

let node = ctx.ts_node.map(|n| n.clone()).unwrap();
let node = ctx.ts_node.unwrap();

assert_eq!(ctx.get_ts_node_content(node), Some("fro"));
assert_eq!(ctx.wrapping_clause_type, Some(ClauseType::Select));
Expand Down
5 changes: 2 additions & 3 deletions crates/pg_completions/src/test_helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,9 @@ pub(crate) async fn get_test_deps(
pub(crate) fn get_text_and_position(sql: &str) -> (usize, String) {
// the cursor is to the left of the `CURSOR_POS`
let position = sql
.find(|c| c == CURSOR_POS)
.find(CURSOR_POS)
.expect("Please insert the CURSOR_POS into your query.")
.checked_sub(1)
.unwrap_or(0);
.saturating_sub(1);

let text = sql.replace(CURSOR_POS, "");

Expand Down
Loading
Loading