From 99ed000614afff50dfa57139375d01bb25a4b2d8 Mon Sep 17 00:00:00 2001 From: Patric Stout Date: Thu, 25 Apr 2024 19:45:16 +0200 Subject: [PATCH] chore: add CI and release workflows (#4) --- .github/workflows/release-crate.yaml | 35 ++++++++++++++++++++ .github/workflows/release-npm.yaml | 48 ++++++++++++++++++++++++++++ .github/workflows/testing.yaml | 36 +++++++++++++++++++++ Cargo.lock | 4 +-- Cargo.toml | 4 +-- README.md | 6 ++-- src/validate.rs | 8 ++--- 7 files changed, 130 insertions(+), 11 deletions(-) create mode 100644 .github/workflows/release-crate.yaml create mode 100644 .github/workflows/release-npm.yaml create mode 100644 .github/workflows/testing.yaml diff --git a/.github/workflows/release-crate.yaml b/.github/workflows/release-crate.yaml new file mode 100644 index 0000000..9a46554 --- /dev/null +++ b/.github/workflows/release-crate.yaml @@ -0,0 +1,35 @@ +name: Release Crate + +on: + release: + types: + - published + +jobs: + registries: + name: Publish to Crates.io + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Install Rust toolchain + uses: actions-rust-lang/setup-rust-toolchain@v1 + with: + toolchain: stable + + - name: Set version + run: | + # Remove the "v" from the version. + VERSION=$(echo ${{ github.ref_name }} | cut -b2-) + echo "Version: ${VERSION}" + + sed -i 's/version = "0.0.0-git"/version = "'${VERSION}'"/' Cargo.toml + sed -i 's/version = "0.0.0-git"/version = "'${VERSION}'"/' Cargo.lock + + - name: Publish to crates.io + run: | + cargo publish --allow-dirty + env: + CARGO_REGISTRY_TOKEN: ${{ secrets.CRATES_IO_TOKEN }} diff --git a/.github/workflows/release-npm.yaml b/.github/workflows/release-npm.yaml new file mode 100644 index 0000000..5ee1a69 --- /dev/null +++ b/.github/workflows/release-npm.yaml @@ -0,0 +1,48 @@ +name: Release NPM + +on: + release: + types: + - published + +jobs: + registries: + name: Publish to GitHub NPM + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Install Node toolchain + uses: actions/setup-node@v3 + with: + node-version: '20' + + - name: Install Rust toolchain + uses: actions-rust-lang/setup-rust-toolchain@v1 + with: + toolchain: stable + + - name: Install wasm-pack + run: | + cargo install wasm-pack + + - name: Set version + run: | + # Remove the "v" from the version. + VERSION=$(echo ${{ github.ref_name }} | cut -b2-) + echo "Version: ${VERSION}" + + sed -i 's/version = "0.0.0-git"/version = "'${VERSION}'"/' Cargo.toml + + - name: Create NPM package + run: | + wasm-pack build --release + sed -i s%nile-library%@nile/library% pkg/package.json + + - uses: JS-DevTools/npm-publish@v3 + with: + token: ${{ secrets.GITHUB_TOKEN }} + registry: "https://npm.pkg.github.com" + package: pkg/package.json diff --git a/.github/workflows/testing.yaml b/.github/workflows/testing.yaml new file mode 100644 index 0000000..dab65c1 --- /dev/null +++ b/.github/workflows/testing.yaml @@ -0,0 +1,36 @@ +name: Testing + +on: + push: + branches: + - main + pull_request: + branches: + - main + +jobs: + testing: + name: Testing + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Install Rust toolchain + uses: actions-rust-lang/setup-rust-toolchain@v1 + with: + toolchain: stable + + - name: Install wasm-pack + run: | + cargo install wasm-pack + + - name: Build library + run: | + wasm-pack build --release --target web + cargo build --release + + - name: Check coding style + run: | + cargo fmt --check diff --git a/Cargo.lock b/Cargo.lock index c624deb..1571f36 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -140,8 +140,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c" [[package]] -name = "nile-validator" -version = "0.1.0" +name = "nile-library" +version = "0.0.0-git" dependencies = [ "clap", "console_error_panic_hook", diff --git a/Cargo.toml b/Cargo.toml index 6d6b8fa..d38963b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] -name = "nile-validator" -version = "0.1.0" +name = "nile-library" +version = "0.0.0-git" edition = "2021" [lib] diff --git a/README.md b/README.md index ef2385f..6004f47 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ -# nile - String Validator +# nile-library - Library supporting nile -This repository contains OpenTTD's translation string validator for `nile`. +This repository contains the libirary that supports OpenTTD's translation tool `nile`. -This tool validates if a translation is valid for a given base-string, by following all the (sometimes complex) rules for OpenTTD. +This library for example validates if a translation is valid for a given base-string, and converts base-strings into a translatable form. ## Installation diff --git a/src/validate.rs b/src/validate.rs index 0644201..dedddc7 100644 --- a/src/validate.rs +++ b/src/validate.rs @@ -24,10 +24,10 @@ pub struct ValidationError { * @returns A clear and specific error message if the translation is invalid. None otherwise. */ pub fn validate( - config: LanguageConfig, - base: String, - case: String, - translation: String, + _config: LanguageConfig, + _base: String, + _case: String, + _translation: String, ) -> Option { None }