|
| 1 | +name: Dev/Beta Deploy to R2 |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - beta |
| 7 | + - dev |
| 8 | + - nightly |
| 9 | + |
| 10 | +env: |
| 11 | + BINARY_NAME: Cortex |
| 12 | + CARGO_TERM_COLOR: always |
| 13 | + RUST_BACKTRACE: 1 |
| 14 | + RUSTFLAGS: "-Zthreads=32" |
| 15 | + CARGO_REGISTRIES_CRATES_IO_PROTOCOL: sparse |
| 16 | + CARGO_INCREMENTAL: 0 |
| 17 | + |
| 18 | +permissions: |
| 19 | + contents: read |
| 20 | + actions: read |
| 21 | + |
| 22 | +concurrency: |
| 23 | + group: ${{ github.workflow }}-${{ github.ref }} |
| 24 | + cancel-in-progress: true |
| 25 | + |
| 26 | +jobs: |
| 27 | + # ========================================================================== |
| 28 | + # Prepare - Determine version and channel from branch |
| 29 | + # ========================================================================== |
| 30 | + prepare: |
| 31 | + name: Prepare Build |
| 32 | + runs-on: blacksmith-4vcpu-ubuntu-2404 |
| 33 | + outputs: |
| 34 | + version: ${{ steps.version.outputs.version }} |
| 35 | + channel: ${{ steps.version.outputs.channel }} |
| 36 | + cache_key: ${{ steps.cache.outputs.key }} |
| 37 | + steps: |
| 38 | + - uses: actions/checkout@v4 |
| 39 | + |
| 40 | + - name: Generate cache key |
| 41 | + id: cache |
| 42 | + run: | |
| 43 | + echo "key=rust-dev-${{ hashFiles('**/Cargo.lock', '**/Cargo.toml') }}" >> $GITHUB_OUTPUT |
| 44 | +
|
| 45 | + - name: Determine version and channel |
| 46 | + id: version |
| 47 | + run: | |
| 48 | + # Read base version from VERSION_CLI |
| 49 | + BASE_VERSION=$(cat VERSION_CLI | tr -d '\n') |
| 50 | + |
| 51 | + # Get short SHA (7 characters) |
| 52 | + SHORT_SHA=$(echo "${{ github.sha }}" | cut -c1-7) |
| 53 | + |
| 54 | + # Determine channel from branch name |
| 55 | + BRANCH="${{ github.ref_name }}" |
| 56 | + case "$BRANCH" in |
| 57 | + beta) |
| 58 | + CHANNEL="beta" |
| 59 | + ;; |
| 60 | + dev) |
| 61 | + CHANNEL="dev" |
| 62 | + ;; |
| 63 | + nightly) |
| 64 | + CHANNEL="nightly" |
| 65 | + ;; |
| 66 | + *) |
| 67 | + echo "ERROR: Unsupported branch '$BRANCH'" |
| 68 | + exit 1 |
| 69 | + ;; |
| 70 | + esac |
| 71 | + |
| 72 | + # Generate version string: {base_version}-{channel}.{short_sha} |
| 73 | + VERSION="${BASE_VERSION}-${CHANNEL}.${SHORT_SHA}" |
| 74 | + |
| 75 | + echo "Base version: $BASE_VERSION" |
| 76 | + echo "Channel: $CHANNEL" |
| 77 | + echo "Short SHA: $SHORT_SHA" |
| 78 | + echo "Full version: $VERSION" |
| 79 | + |
| 80 | + echo "version=$VERSION" >> $GITHUB_OUTPUT |
| 81 | + echo "channel=$CHANNEL" >> $GITHUB_OUTPUT |
| 82 | +
|
| 83 | + # ========================================================================== |
| 84 | + # Build CLI Binaries (32 vCPU for compilation) |
| 85 | + # ========================================================================== |
| 86 | + build-cli: |
| 87 | + name: CLI ${{ matrix.artifact }} |
| 88 | + runs-on: ${{ matrix.runner }} |
| 89 | + needs: prepare |
| 90 | + strategy: |
| 91 | + fail-fast: false |
| 92 | + matrix: |
| 93 | + include: |
| 94 | + - runner: blacksmith-32vcpu-ubuntu-2404 |
| 95 | + target: x86_64-unknown-linux-gnu |
| 96 | + artifact: cortex-cli-linux-x64 |
| 97 | + ext: "" |
| 98 | + - runner: blacksmith-32vcpu-ubuntu-2404-arm |
| 99 | + target: aarch64-unknown-linux-gnu |
| 100 | + artifact: cortex-cli-linux-arm64 |
| 101 | + ext: "" |
| 102 | + - runner: macos-latest |
| 103 | + target: x86_64-apple-darwin |
| 104 | + artifact: cortex-cli-macos-x64 |
| 105 | + ext: "" |
| 106 | + - runner: macos-latest |
| 107 | + target: aarch64-apple-darwin |
| 108 | + artifact: cortex-cli-macos-arm64 |
| 109 | + ext: "" |
| 110 | + - runner: blacksmith-32vcpu-windows-2025 |
| 111 | + target: x86_64-pc-windows-msvc |
| 112 | + artifact: cortex-cli-windows-x64 |
| 113 | + ext: .exe |
| 114 | + |
| 115 | + steps: |
| 116 | + - uses: actions/checkout@v4 |
| 117 | + |
| 118 | + - name: Install Rust nightly |
| 119 | + uses: dtolnay/rust-toolchain@nightly |
| 120 | + with: |
| 121 | + targets: ${{ matrix.target }} |
| 122 | + |
| 123 | + - name: Setup Rust cache (Blacksmith optimized) |
| 124 | + if: contains(matrix.runner, 'blacksmith') |
| 125 | + uses: useblacksmith/rust-cache@v3 |
| 126 | + with: |
| 127 | + prefix-key: "rust-dev-cli-${{ matrix.target }}" |
| 128 | + shared-key: ${{ needs.prepare.outputs.cache_key }} |
| 129 | + |
| 130 | + - name: Setup Rust cache (non-Blacksmith) |
| 131 | + if: "!contains(matrix.runner, 'blacksmith')" |
| 132 | + uses: Swatinem/rust-cache@v2 |
| 133 | + with: |
| 134 | + prefix-key: "rust-dev-cli-${{ matrix.target }}" |
| 135 | + shared-key: ${{ needs.prepare.outputs.cache_key }} |
| 136 | + |
| 137 | + - name: Build release binary |
| 138 | + run: cargo +nightly build --release --target ${{ matrix.target }} -p cortex-cli |
| 139 | + env: |
| 140 | + RUSTFLAGS: "-Zthreads=32" |
| 141 | + CARGO_PROFILE_RELEASE_LTO: thin |
| 142 | + |
| 143 | + - name: Prepare artifact (Unix) |
| 144 | + if: runner.os != 'Windows' |
| 145 | + run: | |
| 146 | + mkdir -p dist |
| 147 | + cp target/${{ matrix.target }}/release/${{ env.BINARY_NAME }}${{ matrix.ext }} dist/ |
| 148 | + cd dist |
| 149 | + tar -czvf ../${{ matrix.artifact }}.tar.gz * |
| 150 | +
|
| 151 | + - name: Prepare artifact (Windows) |
| 152 | + if: runner.os == 'Windows' |
| 153 | + shell: pwsh |
| 154 | + run: | |
| 155 | + New-Item -ItemType Directory -Force -Path dist |
| 156 | + Copy-Item "target/${{ matrix.target }}/release/${{ env.BINARY_NAME }}${{ matrix.ext }}" dist/ |
| 157 | + Compress-Archive -Path dist/* -DestinationPath "${{ matrix.artifact }}.zip" |
| 158 | +
|
| 159 | + - name: Upload artifact |
| 160 | + uses: actions/upload-artifact@v4 |
| 161 | + with: |
| 162 | + name: ${{ matrix.artifact }} |
| 163 | + path: | |
| 164 | + ${{ matrix.artifact }}.tar.gz |
| 165 | + ${{ matrix.artifact }}.zip |
| 166 | + if-no-files-found: ignore |
| 167 | + |
| 168 | + # ========================================================================== |
| 169 | + # Publish to R2 using reusable workflow |
| 170 | + # ========================================================================== |
| 171 | + publish: |
| 172 | + name: Publish to R2 |
| 173 | + needs: [prepare, build-cli] |
| 174 | + if: always() && needs.prepare.result == 'success' && needs.build-cli.result == 'success' |
| 175 | + uses: ./.github/workflows/publish-r2.yml |
| 176 | + with: |
| 177 | + version: ${{ needs.prepare.outputs.version }} |
| 178 | + channel: ${{ needs.prepare.outputs.channel }} |
| 179 | + release_notes: "Auto-deployed from ${{ github.ref_name }} branch at ${{ github.sha }}" |
| 180 | + secrets: inherit |
0 commit comments