Release #18
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Release | |
| on: | |
| push: | |
| tags: | |
| - 'v[0-9]+.[0-9]+.[0-9]+*' | |
| permissions: | |
| contents: write | |
| jobs: | |
| create-release: | |
| name: Create release | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v6 | |
| - name: Verify tag matches Cargo.toml version | |
| run: | | |
| TAG="${GITHUB_REF_NAME#v}" | |
| CARGO_VERSION=$(grep '^version' Cargo.toml | head -1 | sed 's/.*"\(.*\)"/\1/') | |
| if [ "$TAG" != "$CARGO_VERSION" ]; then | |
| echo "::error::Tag $GITHUB_REF_NAME does not match Cargo.toml version $CARGO_VERSION" | |
| exit 1 | |
| fi | |
| - name: Create draft release | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| gh release create "$GITHUB_REF_NAME" \ | |
| --draft \ | |
| --title "$GITHUB_REF_NAME" \ | |
| --generate-notes | |
| build-release: | |
| name: Build (${{ matrix.target }}) | |
| needs: create-release | |
| runs-on: ${{ matrix.os }} | |
| strategy: | |
| fail-fast: true | |
| matrix: | |
| include: | |
| - target: aarch64-apple-darwin | |
| os: macos-latest | |
| - target: x86_64-apple-darwin | |
| os: macos-latest | |
| - target: aarch64-unknown-linux-gnu | |
| os: ubuntu-latest | |
| use_cross: true | |
| - target: x86_64-unknown-linux-gnu | |
| os: ubuntu-latest | |
| - target: x86_64-unknown-linux-musl | |
| os: ubuntu-latest | |
| use_cross: true | |
| - target: x86_64-pc-windows-msvc | |
| os: windows-latest | |
| steps: | |
| - uses: actions/checkout@v6 | |
| - name: Install Rust toolchain | |
| run: rustup target add ${{ matrix.target }} | |
| - name: Prepend Strawberry Perl to PATH (Windows) | |
| if: runner.os == 'Windows' | |
| run: echo "C:\Strawberry\perl\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append | |
| - name: Install cross | |
| if: matrix.use_cross | |
| uses: taiki-e/install-action@v2 | |
| with: | |
| tool: cross | |
| - name: Build | |
| if: "!matrix.use_cross" | |
| run: cargo build --release --target ${{ matrix.target }} | |
| - name: Build (cross) | |
| if: matrix.use_cross | |
| shell: bash | |
| run: cross build --release --target ${{ matrix.target }} | |
| - name: Package and checksum | |
| id: package | |
| shell: bash | |
| run: | | |
| BIN="serpapi" | |
| TARGET="${{ matrix.target }}" | |
| VERSION="${GITHUB_REF_NAME#v}" | |
| PKG="${BIN}-${VERSION}-${TARGET}" | |
| mkdir "$PKG" | |
| cp README.md LICENSE "$PKG/" | |
| if [[ "$TARGET" == *"windows"* ]]; then | |
| cp "target/${TARGET}/release/${BIN}.exe" "$PKG/" | |
| 7z a "${PKG}.zip" "$PKG" | |
| ARCHIVE="${PKG}.zip" | |
| else | |
| cp "target/${TARGET}/release/${BIN}" "$PKG/" | |
| tar czf "${PKG}.tar.gz" "$PKG" | |
| ARCHIVE="${PKG}.tar.gz" | |
| fi | |
| sha256sum "$ARCHIVE" > "${ARCHIVE}.sha256" | |
| echo "archive=$ARCHIVE" >> "$GITHUB_OUTPUT" | |
| echo "sha256=${ARCHIVE}.sha256" >> "$GITHUB_OUTPUT" | |
| - name: Upload to release | |
| shell: bash | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| gh release upload "$GITHUB_REF_NAME" \ | |
| "${{ steps.package.outputs.archive }}" \ | |
| "${{ steps.package.outputs.sha256 }}" | |
| publish-crates: | |
| name: Publish to crates.io | |
| needs: build-release | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v6 | |
| - name: Install Rust toolchain | |
| run: rustup toolchain install stable --profile minimal | |
| - name: Publish | |
| run: cargo publish --locked | |
| env: | |
| CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }} |