Skip to content

Commit 9c5b914

Browse files
authored
Merge pull request #9 from golemcloud/ci
CI
2 parents 4afde97 + 75d615a commit 9c5b914

File tree

5 files changed

+87
-12
lines changed

5 files changed

+87
-12
lines changed

.github/workflows/ci.yaml

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
name: CI
2+
on:
3+
push:
4+
tags:
5+
- "v*.*.*"
6+
branches:
7+
- main
8+
pull_request:
9+
10+
concurrency:
11+
group: ${{ github.workflow }}-${{ github.ref }}
12+
cancel-in-progress: true
13+
14+
jobs:
15+
build:
16+
runs-on: ubuntu-latest
17+
steps:
18+
- name: Checkout
19+
uses: actions/checkout@v3
20+
with:
21+
submodules: true
22+
- uses: actions/cache@v3
23+
with:
24+
path: |
25+
~/.cargo/bin/
26+
~/.cargo/registry/index/
27+
~/.cargo/registry/cache/
28+
~/.cargo/git/db/
29+
target/
30+
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
31+
32+
- name: Setup Rust
33+
uses: actions-rs/toolchain@v1
34+
with:
35+
toolchain: stable
36+
override: true
37+
- name: Check formatting
38+
run: cargo fmt -- --check
39+
- name: Clippy
40+
run: cargo clippy -- -Dwarnings
41+
- name: Tests
42+
run: cargo test
43+
publish:
44+
needs: [build]
45+
if: "startsWith(github.ref, 'refs/tags/v')"
46+
runs-on: ubuntu-latest
47+
steps:
48+
- name: Checkout
49+
uses: actions/checkout@v3
50+
with:
51+
submodules: true
52+
- uses: actions/cache@v3
53+
with:
54+
path: |
55+
~/.cargo/bin/
56+
~/.cargo/registry/index/
57+
~/.cargo/registry/cache/
58+
~/.cargo/git/db/
59+
target/
60+
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
61+
62+
- name: Setup Rust
63+
uses: actions-rs/toolchain@v1
64+
with:
65+
toolchain: stable
66+
- id: get_version
67+
uses: battila7/get-version-action@v2
68+
- name: Publish crate
69+
env:
70+
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
71+
run: |
72+
export VERSION="${{ steps.get_version.outputs.version-without-v }}"
73+
sed -i "s/0.0.0/$VERSION/g" Cargo.toml
74+
cargo publish -p golem-openapi-client-generator --all-features --allow-dirty

.rustfmt.toml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,2 @@
1-
normalize_comments = true
2-
reorder_imports = true
3-
group_imports = "StdExternalCrate"
1+
reorder_imports = true
42
newline_style = "Unix"
5-
imports_granularity = "Module"

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Client generator for golem projects
22

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

55
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.

src/printer.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -227,8 +227,7 @@ impl<C: PrintContext> Add<NewLine> for TreePrinter<C> {
227227

228228
#[cfg(test)]
229229
mod tests {
230-
231-
use crate::printer::{PrintContext, Printer, TreePrinter};
230+
use crate::printer::{PrintContext, TreePrinter};
232231

233232
struct StringContext {
234233
ctx: String,
@@ -252,7 +251,7 @@ mod tests {
252251

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

255-
p.printer().print(&mut ctx);
254+
p.print(&mut ctx);
256255

257256
assert_eq!(ctx.ctx, "abc")
258257
}
@@ -265,7 +264,7 @@ mod tests {
265264

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

268-
p.printer().print(&mut ctx);
267+
p.print(&mut ctx);
269268

270269
assert_eq!(ctx.ctx, "abcdef")
271270
}

src/rust/printer.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,13 @@ pub fn line<T: IntoRustTree>(code: T) -> TreePrinter<RustContext> {
123123
}
124124

125125
pub fn rust_name(import: &str, name: &str) -> TreePrinter<RustContext> {
126+
let import_name = if name.ends_with('!') {
127+
&name[0..name.len() - 1]
128+
} else {
129+
name
130+
};
126131
TreePrinter::leaf(RustCode {
127-
imports: HashSet::from([RustUse(format!("{import}::{name}"))]),
132+
imports: HashSet::from([RustUse(format!("{import}::{import_name}"))]),
128133
code: name.to_string(),
129134
})
130135
}
@@ -155,10 +160,10 @@ mod tests {
155160
let error = rust_name("trace", "error!");
156161

157162
#[rustfmt::skip]
158-
let p = unit()
163+
let p = unit()
159164
+ line("pub fn m() {")
160165
+ indented(
161-
line(info + "(\"abc\");")
166+
line(info + "(\"abc\");")
162167
+ line(error + "(\"def\")"))
163168
+ line("}");
164169

0 commit comments

Comments
 (0)