Skip to content

Commit

Permalink
Merge pull request #9 from golemcloud/ci
Browse files Browse the repository at this point in the history
CI
  • Loading branch information
vigoo authored Mar 19, 2024
2 parents 4afde97 + 75d615a commit 9c5b914
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 12 deletions.
74 changes: 74 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
name: CI
on:
push:
tags:
- "v*.*.*"
branches:
- main
pull_request:

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

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
submodules: true
- uses: actions/cache@v3
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}

- name: Setup Rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true
- name: Check formatting
run: cargo fmt -- --check
- name: Clippy
run: cargo clippy -- -Dwarnings
- name: Tests
run: cargo test
publish:
needs: [build]
if: "startsWith(github.ref, 'refs/tags/v')"
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
submodules: true
- uses: actions/cache@v3
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}

- name: Setup Rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
- id: get_version
uses: battila7/get-version-action@v2
- name: Publish crate
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
run: |
export VERSION="${{ steps.get_version.outputs.version-without-v }}"
sed -i "s/0.0.0/$VERSION/g" Cargo.toml
cargo publish -p golem-openapi-client-generator --all-features --allow-dirty
5 changes: 1 addition & 4 deletions .rustfmt.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,2 @@
normalize_comments = true
reorder_imports = true
group_imports = "StdExternalCrate"
reorder_imports = true
newline_style = "Unix"
imports_granularity = "Module"
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Client generator for golem projects

Rust client renerator for OpenAPI of [Golem](https://golem.cloud) projects.
Rust client generator for OpenAPI of [Golem](https://golem.cloud) projects.

This is not a general purpose client generator - it might be able to generate Rust clients for other OpenAPI specs produced by [Poem OpenAPI](https://crates.io/crates/poem-openapi), but this is not the goal of this project.
7 changes: 3 additions & 4 deletions src/printer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,7 @@ impl<C: PrintContext> Add<NewLine> for TreePrinter<C> {

#[cfg(test)]
mod tests {

use crate::printer::{PrintContext, Printer, TreePrinter};
use crate::printer::{PrintContext, TreePrinter};

struct StringContext {
ctx: String,
Expand All @@ -252,7 +251,7 @@ mod tests {

let mut ctx = StringContext { ctx: String::new() };

p.printer().print(&mut ctx);
p.print(&mut ctx);

assert_eq!(ctx.ctx, "abc")
}
Expand All @@ -265,7 +264,7 @@ mod tests {

let mut ctx = StringContext { ctx: String::new() };

p.printer().print(&mut ctx);
p.print(&mut ctx);

assert_eq!(ctx.ctx, "abcdef")
}
Expand Down
11 changes: 8 additions & 3 deletions src/rust/printer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,13 @@ pub fn line<T: IntoRustTree>(code: T) -> TreePrinter<RustContext> {
}

pub fn rust_name(import: &str, name: &str) -> TreePrinter<RustContext> {
let import_name = if name.ends_with('!') {
&name[0..name.len() - 1]
} else {
name
};
TreePrinter::leaf(RustCode {
imports: HashSet::from([RustUse(format!("{import}::{name}"))]),
imports: HashSet::from([RustUse(format!("{import}::{import_name}"))]),
code: name.to_string(),
})
}
Expand Down Expand Up @@ -155,10 +160,10 @@ mod tests {
let error = rust_name("trace", "error!");

#[rustfmt::skip]
let p = unit()
let p = unit()
+ line("pub fn m() {")
+ indented(
line(info + "(\"abc\");")
line(info + "(\"abc\");")
+ line(error + "(\"def\")"))
+ line("}");

Expand Down

0 comments on commit 9c5b914

Please sign in to comment.