Skip to content

Commit d97fa0d

Browse files
authored
Add CI to publish to crates.io (#24)
1 parent 020311b commit d97fa0d

File tree

4 files changed

+43
-3
lines changed

4 files changed

+43
-3
lines changed

.editorconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,6 @@ indent_style = space
1111
[*.rs]
1212
indent_style = space
1313
indent_size = 4
14+
15+
[*.{yml,yaml}]
16+
indent_size = 2

.github/scripts/check-release.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/sh
2+
3+
# Checking if current tag matches the package version
4+
current_tag=$(echo $GITHUB_REF | tr -d 'refs/tags/v')
5+
file_tag=$(grep '^version = ' Cargo.toml | cut -d '=' -f 2 | tr -d '"' | tr -d ' ')
6+
if [ "$current_tag" != "$file_tag" ]; then
7+
echo "Error: the current tag does not match the version in package file(s)."
8+
echo "$current_tag vs $file_tag"
9+
exit 1
10+
fi
11+
12+
echo 'OK'
13+
exit 0

.github/workflows/publish.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: Publish to crates.io
2+
on:
3+
push:
4+
tags:
5+
- v*
6+
7+
jobs:
8+
publish:
9+
runs-on: ubuntu-latest
10+
name: Rust project
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v2
14+
- uses: hecrj/setup-rust-action@master
15+
with:
16+
rust-version: stable
17+
- name: Check release validity
18+
run: sh .github/scripts/check-release.sh
19+
- name: Build
20+
run: cargo build --release
21+
- name: Login
22+
run: cargo login ${{ secrets.CRATES_TOKEN }}
23+
- name: Publish to crates.io
24+
run: cargo publish

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,17 @@ repository = "https://github.com/Mubelotix/meilisearch-sdk"
1111
[dependencies]
1212
serde_json = "1.0"
1313
log = "0.4"
14-
serde = {version="1.0", features=["derive"]}
14+
serde = { version = "1.0", features = ["derive"] }
1515
urlencoding = "1.0"
1616

1717
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
1818
reqwest = "0.10"
1919

2020
[target.'cfg(target_arch = "wasm32")'.dependencies]
21-
web-sys = {version="0.3", features=["RequestInit", "Headers", "Window", "Response", "console"]}
21+
web-sys = { version = "0.3", features = ["RequestInit", "Headers", "Window", "Response", "console"] }
2222
wasm-bindgen = "0.2"
2323
wasm-bindgen-futures = "0.4"
2424

2525
[dev-dependencies]
2626
env_logger = "0.7"
27-
tokio = { version = "0.2", features=["macros"] }
27+
tokio = { version = "0.2", features = ["macros"] }

0 commit comments

Comments
 (0)