Skip to content

Commit

Permalink
add: release workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
harshdoesdev committed Apr 28, 2024
1 parent 543de74 commit 7729a17
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 63 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
on:
release:
types: [created]

jobs:
release:
name: release ${{ matrix.target }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- target: x86_64-pc-windows-gnu
archive: zip
- target: x86_64-unknown-linux-musl
archive: tar.gz tar.xz tar.zst
- target: x86_64-apple-darwin
archive: zip
steps:
- uses: actions/checkout@master
- name: Compile and release
uses: rust-build/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
RUSTTARGET: ${{ matrix.target }}
ARCHIVE_TYPES: ${{ matrix.archive }}
STATIC_LINKING: true
TOOLCHAIN_VERSION: 1.74.0
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ resolver = "2"
thiserror = "1.0"
rayql-engine = { path = "rayql-engine" }
wasm-bindgen = "0.2"
annotate-snippets = "0.11.1"

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
tokio = { version = "1.36.0", features = ["full"] }
Expand Down
1 change: 0 additions & 1 deletion rayql-engine/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,3 @@ edition = "2021"

[dependencies]
thiserror.workspace = true
annotate-snippets.workspace = true
69 changes: 8 additions & 61 deletions rayql-engine/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,62 +1,8 @@
use annotate_snippets::{Level, Renderer, Snippet};
use rayql::{
schema::error::{ParseError, TokenizationError},
sql::error::{FunctionError, ToSQLError},
};

struct ErrorMessageBuilder<'a> {
code: &'a str,
title: String,
label: String,
line: usize,
span: std::ops::Range<usize>,
}

impl<'a> ErrorMessageBuilder<'a> {
fn new(code: &'a str) -> Self {
ErrorMessageBuilder {
code,
title: String::new(),
label: String::new(),
line: 0,
span: 0..0,
}
}

fn with_title(mut self, title: String) -> Self {
self.title = title;
self
}

fn with_label(mut self, label: String) -> Self {
self.label = label;
self
}

fn with_line(mut self, line: usize) -> Self {
self.line = line;
self
}

fn with_span(mut self, span: std::ops::Range<usize>) -> Self {
self.span = span;
self
}

fn build(self) -> String {
let message = Level::Error.title(&self.title).snippet(
Snippet::source(self.code.lines().nth(self.line - 1).unwrap())
.line_start(self.line)
.origin("schema.rayql")
.fold(true)
.annotation(Level::Error.span(self.span).label(&self.label)),
);
let renderer = Renderer::styled();
let rendered_message = renderer.render(message);
rendered_message.to_string()
}
}

pub fn pretty_error_message(error: &ParseError, code: &str) -> String {
match error {
ParseError::TokenizationError(tokenization_error) => {
Expand Down Expand Up @@ -99,16 +45,17 @@ pub fn pretty_error_message(error: &ParseError, code: &str) -> String {
}
}

fn pretty_tokenization_error_message(tokenization_error: &TokenizationError, code: &str) -> String {
fn pretty_tokenization_error_message(
tokenization_error: &TokenizationError,
_code: &str,
) -> String {
match tokenization_error {
TokenizationError::UnexpectedCharacter { char, line, column }
| TokenizationError::UnknownEscapeSequence { char, line, column } => {
ErrorMessageBuilder::new(code)
.with_title("Unexpected character".to_string())
.with_label(format!("Unexpected character '{}'", char))
.with_line(*line)
.with_span(*column - 1..*column)
.build()
format!(
"Unexpected character '{}' at line {}, column {}",
char, line, column
)
}
TokenizationError::StringLiteralOpened { line, column } => {
format!("String literal opened at line {}, column {}", line, column)
Expand Down

0 comments on commit 7729a17

Please sign in to comment.