diff --git a/.github/archive/publish-rust-sdk.yml b/.github/archive/publish-rust-sdk.yml new file mode 100644 index 00000000..9856bd77 --- /dev/null +++ b/.github/archive/publish-rust-sdk.yml @@ -0,0 +1,42 @@ +name: Publish Rust SDK + +on: [] + +env: + CRATES_IO_TOKEN: ${{ secrets.CRATES_IO_TOKEN }} + +jobs: + build-and-publish: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Set up Rust + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + default: true + profile: minimal + + - name: Install dependencies + run: cargo build --release + + - name: Run version check script + id: version_check_script + run: | + VERSION_INCREMENTED=$(cargo search --limit 1 my_crate_name | grep my_crate_name) + echo "VERSION_INCREMENTED=$VERSION_INCREMENTED" >> $GITHUB_ENV + + - name: Build the package + if: ${{ env.VERSION_INCREMENTED == 'true' }} + run: cargo package + working-directory: ./apps/rust-sdk + + - name: Publish to crates.io + if: ${{ env.VERSION_INCREMENTED == 'true' }} + env: + CARGO_REG_TOKEN: ${{ secrets.CRATES_IO_TOKEN }} + run: cargo publish + working-directory: ./apps/rust-sdk \ No newline at end of file diff --git a/.github/scripts/check_version_has_incremented.py b/.github/scripts/check_version_has_incremented.py index e437c934..6dba065f 100644 --- a/.github/scripts/check_version_has_incremented.py +++ b/.github/scripts/check_version_has_incremented.py @@ -15,6 +15,7 @@ false """ import json +import toml import os import re import sys @@ -53,6 +54,19 @@ def get_npm_version(package_name: str) -> str: version = response.json()['version'] return version.strip() +def get_rust_version(file_path: str) -> str: + """Extract version string from Cargo.toml.""" + cargo_toml = toml.load(file_path) + if 'package' in cargo_toml and 'version' in cargo_toml['package']: + return cargo_toml['package']['version'].strip() + raise RuntimeError("Unable to find version string in Cargo.toml.") + +def get_crates_version(package_name: str) -> str: + """Get latest version of Rust package from crates.io.""" + response = requests.get(f"https://crates.io/api/v1/crates/{package_name}") + version = response.json()['crate']['newest_version'] + return version.strip() + def is_version_incremented(local_version: str, published_version: str) -> bool: """Compare local and published versions.""" local_version_parsed: Version = parse_version(local_version) @@ -74,6 +88,12 @@ if __name__ == "__main__": current_version = get_js_version(os.path.join(package_path, 'package.json')) # Get published version from npm published_version = get_npm_version(package_name) + if package_type == "rust": + # Get current version from Cargo.toml + current_version = get_rust_version(os.path.join(package_path, 'Cargo.toml')) + # Get published version from crates.io + published_version = get_crates_version(package_name) + else: raise ValueError("Invalid package type. Use 'python' or 'js'.") diff --git a/.github/scripts/requirements.txt b/.github/scripts/requirements.txt index 0bfc6762..60f8e191 100644 --- a/.github/scripts/requirements.txt +++ b/.github/scripts/requirements.txt @@ -1,2 +1,3 @@ requests -packaging \ No newline at end of file +packaging +toml \ No newline at end of file diff --git a/.github/workflows/fly.yml b/.github/workflows/fly.yml index f2c5203a..9902d016 100644 --- a/.github/workflows/fly.yml +++ b/.github/workflows/fly.yml @@ -298,3 +298,38 @@ jobs: npm run build-and-publish working-directory: ./apps/js-sdk/firecrawl + build-and-publish-rust-sdk: + name: Build and publish Rust SDK + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Set up Rust + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + default: true + profile: minimal + + - name: Install dependencies + run: cargo build --release + + - name: Run version check script + id: version_check_script + run: | + VERSION_INCREMENTED=$(cargo search --limit 1 my_crate_name | grep my_crate_name) + echo "VERSION_INCREMENTED=$VERSION_INCREMENTED" >> $GITHUB_ENV + + - name: Build the package + if: ${{ env.VERSION_INCREMENTED == 'true' }} + run: cargo package + working-directory: ./apps/rust-sdk + + - name: Publish to crates.io + if: ${{ env.VERSION_INCREMENTED == 'true' }} + env: + CARGO_REG_TOKEN: ${{ secrets.CRATES_IO_TOKEN }} + run: cargo publish + working-directory: ./apps/rust-sdk \ No newline at end of file