[Refactor] Improve error handling with contexts (#3) #1
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*.*.*' | |
| workflow_dispatch: | |
| inputs: | |
| version: | |
| description: 'Version to release (e.g., v1.0.0)' | |
| required: true | |
| env: | |
| CARGO_TERM_COLOR: always | |
| jobs: | |
| create-release: | |
| name: Create Release | |
| runs-on: ubuntu-latest | |
| outputs: | |
| upload_url: ${{ steps.create_release.outputs.upload_url }} | |
| version: ${{ steps.get_version.outputs.version }} | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Get version | |
| id: get_version | |
| run: | | |
| if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then | |
| VERSION="${{ github.event.inputs.version }}" | |
| else | |
| VERSION=${GITHUB_REF#refs/tags/} | |
| fi | |
| echo "version=$VERSION" >> $GITHUB_OUTPUT | |
| - name: Create Release | |
| id: create_release | |
| uses: actions/create-release@v1 | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| with: | |
| tag_name: ${{ steps.get_version.outputs.version }} | |
| release_name: S3 Vectors CLI ${{ steps.get_version.outputs.version }} | |
| body: | | |
| ## Installation | |
| ### Quick Install (Recommended) | |
| ```bash | |
| curl -sSL https://raw.githubusercontent.com/${{ github.repository }}/main/install.sh | bash | |
| ``` | |
| ### Manual Download | |
| Download the appropriate binary for your platform below. | |
| ## Changelog | |
| - See [CHANGELOG.md](https://github.com/${{ github.repository }}/blob/main/CHANGELOG.md) for details | |
| ## Checksums | |
| SHA256 checksums are provided for each binary. | |
| draft: false | |
| prerelease: false | |
| build-release: | |
| name: Build Release | |
| needs: create-release | |
| strategy: | |
| matrix: | |
| include: | |
| # Linux | |
| - os: ubuntu-latest | |
| target: x86_64-unknown-linux-gnu | |
| binary_name: s3-vectors | |
| asset_name: s3-vectors-linux-x86_64 | |
| - os: ubuntu-latest | |
| target: aarch64-unknown-linux-gnu | |
| binary_name: s3-vectors | |
| asset_name: s3-vectors-linux-aarch64 | |
| use_cross: true | |
| # macOS | |
| - os: macos-latest | |
| target: x86_64-apple-darwin | |
| binary_name: s3-vectors | |
| asset_name: s3-vectors-darwin-x86_64 | |
| - os: macos-latest | |
| target: aarch64-apple-darwin | |
| binary_name: s3-vectors | |
| asset_name: s3-vectors-darwin-aarch64 | |
| # Windows | |
| - os: windows-latest | |
| target: x86_64-pc-windows-msvc | |
| binary_name: s3-vectors.exe | |
| asset_name: s3-vectors-windows-x86_64.exe | |
| runs-on: ${{ matrix.os }} | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Install Rust | |
| uses: dtolnay/rust-toolchain@stable | |
| with: | |
| targets: ${{ matrix.target }} | |
| - name: Install cross | |
| if: matrix.use_cross | |
| run: | | |
| cargo install cross --git https://github.com/cross-rs/cross | |
| - name: Build | |
| run: | | |
| if [ "${{ matrix.use_cross }}" = "true" ]; then | |
| cross build --release --target ${{ matrix.target }} | |
| else | |
| cargo build --release --target ${{ matrix.target }} | |
| fi | |
| shell: bash | |
| - name: Strip binary (Linux and macOS) | |
| if: matrix.os != 'windows-latest' | |
| run: | | |
| strip target/${{ matrix.target }}/release/${{ matrix.binary_name }} | |
| - name: Create checksum | |
| run: | | |
| cd target/${{ matrix.target }}/release | |
| if [ "${{ matrix.os }}" = "windows-latest" ]; then | |
| certutil -hashfile ${{ matrix.binary_name }} SHA256 > ${{ matrix.asset_name }}.sha256 | |
| else | |
| if command -v sha256sum > /dev/null; then | |
| sha256sum ${{ matrix.binary_name }} > ${{ matrix.asset_name }}.sha256 | |
| else | |
| shasum -a 256 ${{ matrix.binary_name }} > ${{ matrix.asset_name }}.sha256 | |
| fi | |
| fi | |
| shell: bash | |
| - name: Upload Release Asset | |
| uses: actions/upload-release-asset@v1 | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| with: | |
| upload_url: ${{ needs.create-release.outputs.upload_url }} | |
| asset_path: target/${{ matrix.target }}/release/${{ matrix.binary_name }} | |
| asset_name: ${{ matrix.asset_name }} | |
| asset_content_type: application/octet-stream | |
| - name: Upload Checksum | |
| uses: actions/upload-release-asset@v1 | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| with: | |
| upload_url: ${{ needs.create-release.outputs.upload_url }} | |
| asset_path: target/${{ matrix.target }}/release/${{ matrix.asset_name }}.sha256 | |
| asset_name: ${{ matrix.asset_name }}.sha256 | |
| asset_content_type: text/plain | |
| publish-crates: | |
| name: Publish to crates.io | |
| needs: create-release | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Install Rust | |
| uses: dtolnay/rust-toolchain@stable | |
| - name: Update version in Cargo.toml | |
| run: | | |
| VERSION="${{ needs.create-release.outputs.version }}" | |
| VERSION="${VERSION#v}" # Remove 'v' prefix | |
| sed -i "s/^version = .*/version = \"$VERSION\"/" Cargo.toml | |
| - name: Publish to crates.io | |
| run: cargo publish --token ${{ secrets.CRATES_IO_TOKEN }} | |
| continue-on-error: true # Don't fail the whole release if crates.io publish fails |