From d97fa0d34ea25e5e776cec74d8e8533fe084f297 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9mentine=20Urquizar?= Date: Tue, 28 Jul 2020 17:40:03 +0200 Subject: [PATCH] Add CI to publish to crates.io (#24) --- .editorconfig | 3 +++ .github/scripts/check-release.sh | 13 +++++++++++++ .github/workflows/publish.yml | 24 ++++++++++++++++++++++++ Cargo.toml | 6 +++--- 4 files changed, 43 insertions(+), 3 deletions(-) create mode 100644 .github/scripts/check-release.sh create mode 100644 .github/workflows/publish.yml diff --git a/.editorconfig b/.editorconfig index 6755c698..6a3209ca 100644 --- a/.editorconfig +++ b/.editorconfig @@ -11,3 +11,6 @@ indent_style = space [*.rs] indent_style = space indent_size = 4 + +[*.{yml,yaml}] +indent_size = 2 diff --git a/.github/scripts/check-release.sh b/.github/scripts/check-release.sh new file mode 100644 index 00000000..125e7f43 --- /dev/null +++ b/.github/scripts/check-release.sh @@ -0,0 +1,13 @@ +#!/bin/sh + +# Checking if current tag matches the package version +current_tag=$(echo $GITHUB_REF | tr -d 'refs/tags/v') +file_tag=$(grep '^version = ' Cargo.toml | cut -d '=' -f 2 | tr -d '"' | tr -d ' ') +if [ "$current_tag" != "$file_tag" ]; then + echo "Error: the current tag does not match the version in package file(s)." + echo "$current_tag vs $file_tag" + exit 1 +fi + +echo 'OK' +exit 0 diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 00000000..48107828 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,24 @@ +name: Publish to crates.io +on: + push: + tags: + - v* + +jobs: + publish: + runs-on: ubuntu-latest + name: Rust project + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: hecrj/setup-rust-action@master + with: + rust-version: stable + - name: Check release validity + run: sh .github/scripts/check-release.sh + - name: Build + run: cargo build --release + - name: Login + run: cargo login ${{ secrets.CRATES_TOKEN }} + - name: Publish to crates.io + run: cargo publish diff --git a/Cargo.toml b/Cargo.toml index 1d5ba797..ef546f3a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,17 +11,17 @@ repository = "https://github.com/Mubelotix/meilisearch-sdk" [dependencies] serde_json = "1.0" log = "0.4" -serde = {version="1.0", features=["derive"]} +serde = { version = "1.0", features = ["derive"] } urlencoding = "1.0" [target.'cfg(not(target_arch = "wasm32"))'.dependencies] reqwest = "0.10" [target.'cfg(target_arch = "wasm32")'.dependencies] -web-sys = {version="0.3", features=["RequestInit", "Headers", "Window", "Response", "console"]} +web-sys = { version = "0.3", features = ["RequestInit", "Headers", "Window", "Response", "console"] } wasm-bindgen = "0.2" wasm-bindgen-futures = "0.4" [dev-dependencies] env_logger = "0.7" -tokio = { version = "0.2", features=["macros"] } +tokio = { version = "0.2", features = ["macros"] }