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

Build python wheels and upload to pypi #371

Merged
merged 9 commits into from
Sep 5, 2024
Merged
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
150 changes: 150 additions & 0 deletions .github/workflows/python.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
name: python

on:
push:
branches:
- master
tags:
- "**"
pull_request:
workflow_dispatch:

permissions:
contents: read

jobs:
pre_job:
runs-on: ubuntu-latest
outputs:
should_skip: ${{ steps.skip_check.outputs.should_skip }}
paths_result: ${{ steps.skip_check.outputs.paths_result }}
steps:
- id: skip_check
uses: fkirc/skip-duplicate-actions@c449d86cf33a2a6c7a4193264cc2578e2c3266d4 # pin@v4
with:
paths_ignore: '["docs/**", "*.md", "js/**"]'

linux:
needs: pre_job
if: needs.pre_job.outputs.should_skip != 'true' || startsWith(github.ref, 'refs/tags/')
runs-on: ${{ matrix.platform.runner }}
strategy:
matrix:
platform:
- runner: ubuntu-latest
target: x86_64
before-script: yum install clang llvm llvm-devel -y && python3 -m ensurepip
manylinux: manylinux_2_28
- runner: ubuntu-latest
target: aarch64-unknown-linux-gnu
maturin-options: --zig
# Use zig 0.11.0 because this version contains generic-glibc < 2.38
# after glibc >= 2.38 strchrnul available in glibc by default
# and zig cc doesn't provide mechanism to disable it in older glibc targets
before-script: |
python3 -m pip install ziglang==0.11.0
steps:
- uses: actions/checkout@v4
- name: Build wheels
uses: PyO3/maturin-action@v1
with:
target: ${{ matrix.platform.target }}
working-directory: cli
args: --release --out dist ${{ matrix.platform.maturin-options }}
manylinux: ${{ matrix.platform.manylinux }}
sccache: "true"
before-script-linux: ${{ matrix.platform.before-script }}
- name: Upload wheels
uses: actions/upload-artifact@v4
with:
name: wheels-linux-${{ matrix.platform.target }}
path: cli/dist
if-no-files-found: error

windows:
needs: pre_job
if: needs.pre_job.outputs.should_skip != 'true' || startsWith(github.ref, 'refs/tags/')
runs-on: ${{ matrix.platform.runner }}
strategy:
matrix:
platform:
- runner: windows-latest
target: x64
- runner: windows-latest
target: x86
steps:
- uses: actions/checkout@v4
- name: Build wheels
uses: PyO3/maturin-action@v1
with:
target: ${{ matrix.platform.target }}
working-directory: cli
args: --release --out dist
sccache: "true"
- name: Upload wheels
uses: actions/upload-artifact@v4
with:
name: wheels-windows-${{ matrix.platform.target }}
path: cli/dist
if-no-files-found: error

macos:
needs: pre_job
if: needs.pre_job.outputs.should_skip != 'true' || startsWith(github.ref, 'refs/tags/')
runs-on: ${{ matrix.platform.runner }}
strategy:
matrix:
platform:
- runner: macos-12
target: x86_64
- runner: macos-14
target: aarch64
steps:
- uses: actions/checkout@v4
- name: Build wheels
uses: PyO3/maturin-action@v1
with:
target: ${{ matrix.platform.target }}
working-directory: cli
args: --release --out dist
sccache: "true"
- name: Upload wheels
uses: actions/upload-artifact@v4
with:
name: wheels-macos-${{ matrix.platform.target }}
path: cli/dist
if-no-files-found: error

sdist:
needs: pre_job
if: needs.pre_job.outputs.should_skip != 'true' || startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Build sdist
uses: PyO3/maturin-action@v1
with:
command: sdist
working-directory: cli
args: --out dist
- name: Upload sdist
uses: actions/upload-artifact@v4
with:
name: wheels-sdist
path: cli/dist
if-no-files-found: error

release:
name: Release
runs-on: ubuntu-latest
if: "startsWith(github.ref, 'refs/tags/')"
needs: [linux, windows, macos, sdist]
steps:
- uses: actions/download-artifact@v4
- name: Publish to PyPI
uses: PyO3/maturin-action@v1
env:
MATURIN_PYPI_TOKEN: ${{ secrets.PYPI_API_TOKEN }}
with:
command: upload
args: --non-interactive --skip-existing wheels-*/*
2 changes: 1 addition & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ jobs:

publish-npm:
if: startsWith(github.ref, 'refs/tags/')
needs: [build-linux-x64, build-mac]
needs: [build-linux-x64, build-mac, build-windows]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand Down
22 changes: 22 additions & 0 deletions cli/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[build-system]
requires = ["maturin>=1.7,<2.0"]
build-backend = "maturin"

[project]
name = "squawk-cli"
description = "Linter for PostgreSQL migrations"
requires-python = ">=3.8"
classifiers = [
"License :: OSI Approved :: GNU General Public License v3 (GPLv3)",
"Operating System :: MacOS",
"Operating System :: Microsoft :: Windows",
"Operating System :: POSIX :: Linux",
"Programming Language :: Python :: 3",
"Programming Language :: Rust",
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: PyPy",
]
dynamic = ["version"]

[tool.maturin]
bindings = "bin"
8 changes: 4 additions & 4 deletions cli/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,20 +149,20 @@ excluded_paths = ["example.sql"]
#[test]
fn test_load_assume_in_transaction() {
let squawk_toml = NamedTempFile::new().expect("generate tempFile");
let file = r#"
let file = r"
assume_in_transaction = false

"#;
";
fs::write(&squawk_toml, file).expect("Unable to write file");
assert_debug_snapshot!(Config::parse(Some(squawk_toml.path().to_path_buf())));
}
#[test]
fn test_load_fail_on_violations() {
let squawk_toml = NamedTempFile::new().expect("generate tempFile");
let file = r#"
let file = r"
[upload_to_github]
fail_on_violations = true
"#;
";
fs::write(&squawk_toml, file).expect("Unable to write file");
assert_debug_snapshot!(Config::parse(Some(squawk_toml.path().to_path_buf())));
}
Expand Down
11 changes: 5 additions & 6 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,10 @@ struct Opt {
/// Paths to exclude
///
/// For example:
/// --exclude-path=005_user_ids.sql --exclude-path=009_account_emails.sql
///
/// --exclude-path='*user_ids.sql'
/// `--exclude-path=005_user_ids.sql --exclude-path=009_account_emails.sql`
///
/// `--exclude-path='*user_ids.sql'`
#[structopt(long = "exclude-path", global = true)]
excluded_path: Option<Vec<String>>,
/// Exclude specific warnings
Expand Down Expand Up @@ -149,10 +150,8 @@ fn main() {
opts.assume_in_transaction
} else if opts.no_assume_in_transaction {
!opts.no_assume_in_transaction
} else if let Some(assume_in_transaction) = conf.assume_in_transaction {
assume_in_transaction
} else {
false
conf.assume_in_transaction.unwrap_or_default()
};

info!("pg version: {:?}", pg_version);
Expand Down Expand Up @@ -214,7 +213,7 @@ fn main() {
.map(|f| f.violations.len())
.sum::<usize>();
match print_violations(&mut handle, file_reports, &reporter) {
Ok(_) => {
Ok(()) => {
let exit_code = i32::from(total_violations > 0);
process::exit(exit_code);
}
Expand Down
24 changes: 12 additions & 12 deletions cli/src/reporter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -543,9 +543,9 @@ mod test_github_comment {
fn test_generating_comment_multiple_files() {
let violations = vec![ViolationContent {
filename: "alpha.sql".into(),
sql: r#"
sql: r"
SELECT 1;
"#
"
.into(),
violations: vec![ReportViolation {
file: "alpha.sql".into(),
Expand Down Expand Up @@ -627,9 +627,9 @@ mod test_check_files {

#[test]
fn test_check_files_invalid_syntax() {
let sql = r#"
let sql = r"
select \;
"#;
";
let mut buff = Vec::new();
let res = process_violations(sql, "test.sql", &[], None, false);
fmt_json(&mut buff, vec![res]).unwrap();
Expand Down Expand Up @@ -675,10 +675,10 @@ SELECT 1;
);
assert!(res.is_ok());

assert_display_snapshot!(String::from_utf8_lossy(&buff), @r###"
assert_display_snapshot!(String::from_utf8_lossy(&buff), @r"
main.sql:1:0: warning: adding-required-field Adding a NOT NULL field without a DEFAULT will fail for a populated table. Make the field nullable or add a non-VOLATILE DEFAULT (Postgres 11+).
main.sql:3:1: warning: adding-required-field Adding a NOT NULL field without a DEFAULT will fail for a populated table. Make the field nullable or add a non-VOLATILE DEFAULT (Postgres 11+).
"###);
");
}

#[test]
Expand Down Expand Up @@ -735,9 +735,9 @@ SELECT 1;
);

assert!(res.is_ok());
assert_display_snapshot!(String::from_utf8_lossy(&buff), @r###"
assert_display_snapshot!(String::from_utf8_lossy(&buff), @r#"
[{"file":"main.sql","line":1,"column":0,"level":"Warning","messages":[{"Note":"Adding a NOT NULL field without a DEFAULT will fail for a populated table."},{"Help":"Make the field nullable or add a non-VOLATILE DEFAULT (Postgres 11+)."}],"rule_name":"adding-required-field"},{"file":"main.sql","line":3,"column":1,"level":"Warning","messages":[{"Note":"Adding a NOT NULL field without a DEFAULT will fail for a populated table."},{"Help":"Make the field nullable or add a non-VOLATILE DEFAULT (Postgres 11+)."}],"rule_name":"adding-required-field"}]
"###);
"#);
}

#[test]
Expand All @@ -761,7 +761,7 @@ SELECT 1;
let sql = r#"ALTER TABLE "core_recipe" ADD COLUMN "foo" integer NOT NULL;"#;
let violations = lint_sql(sql);

assert_debug_snapshot!(violations, @r###"
assert_debug_snapshot!(violations, @r#"
[
RuleViolation {
kind: AddingRequiredField,
Expand All @@ -781,10 +781,10 @@ SELECT 1;
],
},
]
"###);
"#);

let filename = "main.sql";
assert_debug_snapshot!(pretty_violations(violations, sql, filename), @r###"
assert_debug_snapshot!(pretty_violations(violations, sql, filename), @r#"
ViolationContent {
filename: "main.sql",
sql: "ALTER TABLE \"core_recipe\" ADD COLUMN \"foo\" integer NOT NULL;",
Expand All @@ -807,6 +807,6 @@ SELECT 1;
},
],
}
"###);
"#);
}
}
5 changes: 2 additions & 3 deletions linter/src/rules/adding_field_with_default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ pub fn adding_field_with_default(

let non_volatile_funcs: HashSet<_> = NON_VOLATILE_BUILT_IN_FUNCTIONS
.split('\n')
.into_iter()
.map(|x| x.trim().to_lowercase())
.filter(|x| !x.is_empty())
.collect();
Expand Down Expand Up @@ -235,9 +234,9 @@ ALTER TABLE "core_recipe" ADD COLUMN "foo" timestamptz DEFAULT now();
#[test]
fn test_add_numbers_ok() {
// This should be okay, but we don't handle expressions like this at the moment.
let ok_sql = r#"
let ok_sql = r"
alter table account_metadata add column blah integer default 2 + 2;
"#;
";
let pg_version_11 = Some(Version::from_str("11.0.0").unwrap());
assert_debug_snapshot!(lint_sql(ok_sql, pg_version_11));
}
Expand Down
12 changes: 6 additions & 6 deletions linter/src/rules/adding_primary_key_constraint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ mod test_rules {

#[test]
fn test_serial_primary_key() {
let bad_sql = r#"
let bad_sql = r"
ALTER TABLE a ADD COLUMN b SERIAL PRIMARY KEY;
"#;
";

let expected_bad_res = lint_sql(bad_sql);
assert_ne!(expected_bad_res, vec![]);
Expand All @@ -87,17 +87,17 @@ ALTER TABLE a ADD COLUMN b SERIAL PRIMARY KEY;

#[test]
fn test_plain_primary_key() {
let bad_sql = r#"
let bad_sql = r"
ALTER TABLE items ADD PRIMARY KEY (id);
"#;
";

let expected_bad_res = lint_sql(bad_sql);
assert_ne!(expected_bad_res, vec![]);
assert_debug_snapshot!(expected_bad_res);

let ok_sql = r#"
let ok_sql = r"
ALTER TABLE items ADD CONSTRAINT items_pk PRIMARY KEY USING INDEX items_pk;
"#;
";
assert_debug_snapshot!(lint_sql(ok_sql,));
}
}
Loading
Loading