Skip to content

Initial version of SerpApi CLI #2

Initial version of SerpApi CLI

Initial version of SerpApi CLI #2

Workflow file for this run

name: CI/CD Pipeline
on:
push:
branches: [main, develop]
tags: ["v*"]
pull_request:
branches: [main]
env:
CARGO_TERM_COLOR: always
jobs:
lint-and-test:
name: Lint + Unit Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Rust stable
uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: stable
components: rustfmt, clippy
- name: Cache cargo registry
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-
- name: Check formatting
run: cargo fmt -- --check
- name: Run clippy
run: cargo clippy -- -D warnings
- name: Run unit tests
run: cargo test --lib --bins
e2e-test:
name: E2E Test
runs-on: ubuntu-latest
needs: lint-and-test
steps:
- uses: actions/checkout@v4
- name: Install Rust stable
uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: stable
- name: Cache cargo registry
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-
- name: Run E2E tests
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository
env:
SERPAPI_KEY: ${{ secrets.SERPAPI_KEY }}
run: cargo test -- --ignored
- name: Skip E2E tests (fork PR)
if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name != github.repository
run: echo "Skipping E2E tests - SERPAPI_KEY unavailable in fork PRs"
release:
name: Cross-Compile Release
runs-on: ${{ matrix.os }}
needs: [lint-and-test, e2e-test]
if: startsWith(github.ref, 'refs/tags/v')
strategy:
matrix:
include:
- os: ubuntu-latest
target: x86_64-unknown-linux-gnu
use_cross: false
- os: ubuntu-latest
target: aarch64-unknown-linux-gnu
use_cross: true
- os: macos-latest
target: x86_64-apple-darwin
use_cross: false
- os: macos-latest
target: aarch64-apple-darwin
use_cross: false
- os: windows-latest
target: x86_64-pc-windows-msvc
use_cross: false
steps:
- uses: actions/checkout@v4
- name: Install Rust stable
uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: stable
target: ${{ matrix.target }}
- name: Install cross
if: matrix.use_cross
run: cargo install cross --git https://github.com/cross-rs/cross
- name: Build release binary (cross)
if: matrix.use_cross
run: cross build --release --target ${{ matrix.target }}
- name: Build release binary (native)
if: "!matrix.use_cross"
run: cargo build --release --target ${{ matrix.target }}
- name: Prepare artifacts (Unix)
if: runner.os != 'Windows'
run: |
cd target/${{ matrix.target }}/release
BINARY_NAME="serpapi-${{ matrix.target }}"
cp serpapi "$BINARY_NAME"
shasum -a 256 "$BINARY_NAME" > "$BINARY_NAME.sha256"
tar czf "$BINARY_NAME.tar.gz" "$BINARY_NAME"
shasum -a 256 "$BINARY_NAME.tar.gz" > "$BINARY_NAME.tar.gz.sha256"
- name: Prepare artifacts (Windows)
if: runner.os == 'Windows'
shell: pwsh
run: |
cd target/${{ matrix.target }}/release
$BINARY_NAME = "serpapi-${{ matrix.target }}.exe"
Copy-Item serpapi.exe $BINARY_NAME
(Get-FileHash -Algorithm SHA256 $BINARY_NAME).Hash.ToLower() + " $BINARY_NAME" | Out-File -FilePath "$BINARY_NAME.sha256" -Encoding ASCII
Compress-Archive -Path $BINARY_NAME -DestinationPath "$BINARY_NAME.zip"
(Get-FileHash -Algorithm SHA256 "$BINARY_NAME.zip").Hash.ToLower() + " $BINARY_NAME.zip" | Out-File -FilePath "$BINARY_NAME.zip.sha256" -Encoding ASCII
- name: Upload artifacts (Unix)
if: runner.os != 'Windows'
uses: actions/upload-artifact@v4
with:
name: serpapi-${{ matrix.target }}
path: |
target/${{ matrix.target }}/release/serpapi-${{ matrix.target }}
target/${{ matrix.target }}/release/serpapi-${{ matrix.target }}.sha256
target/${{ matrix.target }}/release/serpapi-${{ matrix.target }}.tar.gz
target/${{ matrix.target }}/release/serpapi-${{ matrix.target }}.tar.gz.sha256
- name: Upload artifacts (Windows)
if: runner.os == 'Windows'
uses: actions/upload-artifact@v4
with:
name: serpapi-${{ matrix.target }}
path: |
target/${{ matrix.target }}/release/serpapi-${{ matrix.target }}.exe
target/${{ matrix.target }}/release/serpapi-${{ matrix.target }}.exe.sha256
target/${{ matrix.target }}/release/serpapi-${{ matrix.target }}.exe.zip
target/${{ matrix.target }}/release/serpapi-${{ matrix.target }}.exe.zip.sha256
create-release:
name: Create GitHub Release
runs-on: ubuntu-latest
needs: release
if: startsWith(github.ref, 'refs/tags/v')
permissions:
contents: write
steps:
- uses: actions/checkout@v4
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: artifacts
- name: Create release
uses: softprops/action-gh-release@v1
with:
draft: false
prerelease: false
generate_release_notes: true
files: |
artifacts/serpapi-x86_64-unknown-linux-gnu/*
artifacts/serpapi-aarch64-unknown-linux-gnu/*
artifacts/serpapi-x86_64-apple-darwin/*
artifacts/serpapi-aarch64-apple-darwin/*
artifacts/serpapi-x86_64-pc-windows-msvc/*