|
| 1 | +name: Release 19_webprox |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - 'webprox-v*' |
| 7 | + paths: |
| 8 | + - 'examples/19_webprox/**' |
| 9 | + - '.github/workflows/release-19-webprox.yml' |
| 10 | + workflow_dispatch: |
| 11 | + |
| 12 | +jobs: |
| 13 | + detect-changes: |
| 14 | + name: Detect 19_webprox Changes |
| 15 | + runs-on: ubuntu-latest |
| 16 | + outputs: |
| 17 | + should_build: ${{ steps.detect.outputs.should_build }} |
| 18 | + steps: |
| 19 | + - name: Checkout code |
| 20 | + uses: actions/checkout@v4 |
| 21 | + with: |
| 22 | + fetch-depth: 2 |
| 23 | + |
| 24 | + - name: Decide whether to build |
| 25 | + id: detect |
| 26 | + shell: bash |
| 27 | + run: | |
| 28 | + set -euo pipefail |
| 29 | +
|
| 30 | + if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then |
| 31 | + echo "Manual run requested; enabling build." |
| 32 | + echo "should_build=true" >> "$GITHUB_OUTPUT" |
| 33 | + exit 0 |
| 34 | + fi |
| 35 | +
|
| 36 | + if git rev-parse "${GITHUB_SHA}^" >/dev/null 2>&1; then |
| 37 | + changed_files="$(git diff --name-only "${GITHUB_SHA}^" "${GITHUB_SHA}")" |
| 38 | + else |
| 39 | + changed_files="$(git show --pretty='' --name-only "${GITHUB_SHA}")" |
| 40 | + fi |
| 41 | +
|
| 42 | + echo "Changed files in tagged commit:" |
| 43 | + echo "$changed_files" |
| 44 | +
|
| 45 | + if echo "$changed_files" | grep -Eq '^(examples/19_webprox/|\.github/workflows/release-19-webprox\.yml$)'; then |
| 46 | + echo "should_build=true" >> "$GITHUB_OUTPUT" |
| 47 | + else |
| 48 | + echo "should_build=false" >> "$GITHUB_OUTPUT" |
| 49 | + fi |
| 50 | +
|
| 51 | + validate-versions: |
| 52 | + name: Validate Tag vs Crate Versions |
| 53 | + needs: detect-changes |
| 54 | + if: needs.detect-changes.outputs.should_build == 'true' |
| 55 | + runs-on: ubuntu-latest |
| 56 | + steps: |
| 57 | + - name: Checkout code |
| 58 | + uses: actions/checkout@v4 |
| 59 | + |
| 60 | + - name: Validate versions |
| 61 | + shell: bash |
| 62 | + run: | |
| 63 | + set -euo pipefail |
| 64 | +
|
| 65 | + if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then |
| 66 | + echo "Manual run requested; skipping tag/version validation." |
| 67 | + exit 0 |
| 68 | + fi |
| 69 | +
|
| 70 | + tag="${GITHUB_REF_NAME}" |
| 71 | + if [[ ! "$tag" =~ ^webprox-v(.+)$ ]]; then |
| 72 | + echo "Tag '$tag' does not match required format 'webprox-v<version>'." >&2 |
| 73 | + exit 1 |
| 74 | + fi |
| 75 | + tag_version="${BASH_REMATCH[1]}" |
| 76 | +
|
| 77 | + server_version="$(sed -n 's/^version = \"\\([^\"]*\\)\"/\\1/p' examples/19_webprox/cloud-proxy-server/Cargo.toml | head -n1)" |
| 78 | + client_version="$(sed -n 's/^version = \"\\([^\"]*\\)\"/\\1/p' examples/19_webprox/minimal-tui-client/Cargo.toml | head -n1)" |
| 79 | +
|
| 80 | + if [ -z "$server_version" ] || [ -z "$client_version" ]; then |
| 81 | + echo "Failed to read crate version(s) from Cargo.toml." >&2 |
| 82 | + exit 1 |
| 83 | + fi |
| 84 | +
|
| 85 | + echo "Tag version: $tag_version" |
| 86 | + echo "cloud-proxy-server version: $server_version" |
| 87 | + echo "minimal-tui-client version: $client_version" |
| 88 | +
|
| 89 | + if [ "$tag_version" != "$server_version" ]; then |
| 90 | + echo "Tag version does not match cloud-proxy-server version." >&2 |
| 91 | + exit 1 |
| 92 | + fi |
| 93 | +
|
| 94 | + if [ "$tag_version" != "$client_version" ]; then |
| 95 | + echo "Tag version does not match minimal-tui-client version." >&2 |
| 96 | + exit 1 |
| 97 | + fi |
| 98 | +
|
| 99 | + build-and-release: |
| 100 | + name: Build and Release |
| 101 | + needs: [detect-changes, validate-versions] |
| 102 | + if: needs.detect-changes.outputs.should_build == 'true' |
| 103 | + runs-on: ${{ matrix.os }} |
| 104 | + permissions: |
| 105 | + contents: write |
| 106 | + strategy: |
| 107 | + fail-fast: false |
| 108 | + matrix: |
| 109 | + include: |
| 110 | + - os: ubuntu-latest |
| 111 | + target: x86_64-unknown-linux-gnu |
| 112 | + asset_name: webprox-linux-amd64 |
| 113 | + archive_ext: tar.gz |
| 114 | + - os: macos-latest |
| 115 | + target: x86_64-apple-darwin |
| 116 | + asset_name: webprox-macos-amd64 |
| 117 | + archive_ext: tar.gz |
| 118 | + - os: macos-latest |
| 119 | + target: aarch64-apple-darwin |
| 120 | + asset_name: webprox-macos-arm64 |
| 121 | + archive_ext: tar.gz |
| 122 | + - os: windows-latest |
| 123 | + target: x86_64-pc-windows-msvc |
| 124 | + asset_name: webprox-windows-amd64 |
| 125 | + archive_ext: zip |
| 126 | + |
| 127 | + steps: |
| 128 | + - name: Checkout code |
| 129 | + uses: actions/checkout@v4 |
| 130 | + |
| 131 | + - name: Install Rust |
| 132 | + uses: dtolnay/rust-toolchain@stable |
| 133 | + with: |
| 134 | + targets: ${{ matrix.target }} |
| 135 | + |
| 136 | + - name: Rust Cache |
| 137 | + uses: Swatinem/rust-cache@v2 |
| 138 | + with: |
| 139 | + workspaces: | |
| 140 | + examples/19_webprox |
| 141 | +
|
| 142 | + - name: Build workspace in release mode |
| 143 | + run: cargo build --manifest-path examples/19_webprox/Cargo.toml --workspace --release --target ${{ matrix.target }} |
| 144 | + |
| 145 | + - name: Create archive (Unix) |
| 146 | + if: runner.os != 'Windows' |
| 147 | + shell: bash |
| 148 | + run: | |
| 149 | + set -euo pipefail |
| 150 | +
|
| 151 | + BIN_DIR="examples/19_webprox/target/${{ matrix.target }}/release" |
| 152 | + ASSET="${{ matrix.asset_name }}.${{ matrix.archive_ext }}" |
| 153 | +
|
| 154 | + bins=() |
| 155 | + for bin in cloud-proxy-server minimal-tui-client; do |
| 156 | + if [ -f "$BIN_DIR/$bin" ]; then |
| 157 | + bins+=("$bin") |
| 158 | + fi |
| 159 | + done |
| 160 | +
|
| 161 | + if [ "${#bins[@]}" -eq 0 ]; then |
| 162 | + echo "No binaries found in $BIN_DIR" >&2 |
| 163 | + exit 1 |
| 164 | + fi |
| 165 | +
|
| 166 | + tar czf "$ASSET" -C "$BIN_DIR" "${bins[@]}" |
| 167 | +
|
| 168 | + - name: Create archive (Windows) |
| 169 | + if: runner.os == 'Windows' |
| 170 | + shell: pwsh |
| 171 | + run: | |
| 172 | + $binDir = "examples/19_webprox/target/${{ matrix.target }}/release" |
| 173 | + $asset = "${{ matrix.asset_name }}.${{ matrix.archive_ext }}" |
| 174 | +
|
| 175 | + $candidates = @("cloud-proxy-server.exe", "minimal-tui-client.exe") |
| 176 | + $files = @() |
| 177 | + foreach ($candidate in $candidates) { |
| 178 | + $path = Join-Path $binDir $candidate |
| 179 | + if (Test-Path $path) { |
| 180 | + $files += $path |
| 181 | + } |
| 182 | + } |
| 183 | +
|
| 184 | + if ($files.Count -eq 0) { |
| 185 | + Write-Error "No binaries found in $binDir" |
| 186 | + } |
| 187 | +
|
| 188 | + Compress-Archive -Path $files -DestinationPath $asset -Force |
| 189 | +
|
| 190 | + - name: Upload assets to release |
| 191 | + uses: softprops/action-gh-release@v2 |
| 192 | + with: |
| 193 | + files: | |
| 194 | + ${{ matrix.asset_name }}.${{ matrix.archive_ext }} |
| 195 | + env: |
| 196 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments