Off Context Cli Release #3
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: Off Context Cli Release | |
| on: | |
| push: | |
| tags: | |
| - 'v*' | |
| workflow_dispatch: | |
| inputs: | |
| version: | |
| description: 'Release version (e.g., v1.0.1)' | |
| required: true | |
| default: 'v1.0.1' | |
| type: string | |
| release_name: | |
| description: 'Release name (optional)' | |
| required: false | |
| type: string | |
| prerelease: | |
| description: 'Mark as pre-release' | |
| required: false | |
| default: false | |
| type: boolean | |
| build_linux: | |
| description: 'Build Linux version' | |
| required: false | |
| default: true | |
| type: boolean | |
| build_macos: | |
| description: 'Build macOS version' | |
| required: false | |
| default: true | |
| type: boolean | |
| env: | |
| CARGO_TERM_COLOR: always | |
| permissions: | |
| contents: write | |
| jobs: | |
| prepare: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| matrix: ${{ steps.set-matrix.outputs.matrix }} | |
| steps: | |
| - id: set-matrix | |
| run: | | |
| matrix="{" | |
| builds=() | |
| # Check if Linux build is enabled (default true for tag pushes) | |
| if [[ "${{ github.event.inputs.build_linux }}" == "true" || ("${{ github.event_name }}" == "push" && "${{ github.event.inputs.build_linux }}" != "false") ]]; then | |
| builds+=('{"os":"ubuntu-latest","target":"x86_64-unknown-linux-musl","artifact_name":"off-context","asset_name":"off-context-linux-x86_64.tar.gz"}') | |
| builds+=('{"os":"ubuntu-latest","target":"aarch64-unknown-linux-musl","artifact_name":"off-context","asset_name":"off-context-linux-arm64.tar.gz"}') | |
| fi | |
| # Check if macOS build is enabled (default true for tag pushes) | |
| if [[ "${{ github.event.inputs.build_macos }}" == "true" || ("${{ github.event_name }}" == "push" && "${{ github.event.inputs.build_macos }}" != "false") ]]; then | |
| builds+=('{"os":"macos-latest","target":"x86_64-apple-darwin","artifact_name":"off-context","asset_name":"off-context-macos-x86_64.tar.gz"}') | |
| builds+=('{"os":"macos-latest","target":"aarch64-apple-darwin","artifact_name":"off-context","asset_name":"off-context-macos-arm64.tar.gz"}') | |
| fi | |
| # Join builds with commas | |
| IFS=',' | |
| matrix="\"include\":[${builds[*]}]}" | |
| echo "matrix={$matrix}" >> $GITHUB_OUTPUT | |
| echo "Generated matrix: {$matrix}" | |
| build: | |
| name: Build and Release | |
| needs: prepare | |
| runs-on: ${{ matrix.os }} | |
| timeout-minutes: 30 | |
| strategy: | |
| matrix: ${{ fromJson(needs.prepare.outputs.matrix) }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Install dependencies | |
| run: | | |
| if [[ "${{ matrix.target }}" == "x86_64-unknown-linux-musl" ]]; then | |
| sudo apt-get update | |
| sudo apt-get install -y musl-tools | |
| elif [[ "${{ matrix.target }}" == "aarch64-unknown-linux-musl" ]]; then | |
| sudo apt-get update | |
| sudo apt-get install -y musl-tools gcc-aarch64-linux-gnu | |
| fi | |
| - name: Install Rust | |
| uses: dtolnay/rust-toolchain@stable | |
| with: | |
| targets: ${{ matrix.target }} | |
| - name: Build | |
| run: | | |
| if [[ "${{ matrix.target }}" == "aarch64-unknown-linux-musl" ]]; then | |
| export CC_aarch64_unknown_linux_musl=aarch64-linux-gnu-gcc | |
| export CXX_aarch64_unknown_linux_musl=aarch64-linux-gnu-g++ | |
| export AR_aarch64_unknown_linux_musl=aarch64-linux-gnu-ar | |
| export CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_LINKER=aarch64-linux-gnu-gcc | |
| fi | |
| cargo build --release --target ${{ matrix.target }} | |
| - name: Debug and create tarball | |
| run: | | |
| echo "=== Debugging binary location ===" | |
| echo "Looking for: ${{ matrix.artifact_name }}" | |
| echo "Target: ${{ matrix.target }}" | |
| echo "" | |
| echo "Directory structure:" | |
| find target -type f -name "*off-context*" || echo "No off-context files found" | |
| echo "" | |
| echo "All files in target/:" | |
| ls -la target/ || echo "No target directory" | |
| echo "" | |
| echo "Checking specific paths:" | |
| echo "1. target/${{ matrix.target }}/release/${{ matrix.artifact_name }}" | |
| ls -la "target/${{ matrix.target }}/release/" || echo "Path 1 not found" | |
| echo "2. target/release/${{ matrix.artifact_name }}" | |
| ls -la "target/release/" || echo "Path 2 not found" | |
| echo "" | |
| mkdir -p dist | |
| # Handle different build output paths | |
| if [ -f "target/${{ matrix.target }}/release/${{ matrix.artifact_name }}" ]; then | |
| echo "Found binary at target/${{ matrix.target }}/release/${{ matrix.artifact_name }}" | |
| cp target/${{ matrix.target }}/release/${{ matrix.artifact_name }} dist/off-context | |
| elif [ -f "target/release/${{ matrix.artifact_name }}" ]; then | |
| echo "Found binary at target/release/${{ matrix.artifact_name }}" | |
| cp target/release/${{ matrix.artifact_name }} dist/off-context | |
| else | |
| echo "Binary not found in expected locations, searching..." | |
| BINARY_PATH=$(find target -name "${{ matrix.artifact_name }}" -type f | head -1) | |
| if [ -n "$BINARY_PATH" ]; then | |
| echo "Found binary at: $BINARY_PATH" | |
| cp "$BINARY_PATH" dist/off-context | |
| else | |
| echo "Binary ${{ matrix.artifact_name }} not found anywhere in target/" | |
| exit 1 | |
| fi | |
| fi | |
| cd dist | |
| tar -czf ${{ matrix.asset_name }} off-context | |
| - name: Upload Release Asset | |
| uses: softprops/action-gh-release@v1 | |
| with: | |
| tag_name: ${{ github.event.inputs.version || github.ref_name }} | |
| name: ${{ github.event.inputs.release_name || github.event.inputs.version || github.ref_name }} | |
| files: dist/${{ matrix.asset_name }} | |
| prerelease: ${{ github.event.inputs.prerelease || false }} | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |