|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + version: |
| 7 | + description: "Version to release (e.g., v1.2.3) - tag must already exist" |
| 8 | + required: true |
| 9 | + type: string |
| 10 | + workflow_call: |
| 11 | + inputs: |
| 12 | + version: |
| 13 | + description: "Version to release (e.g., v1.2.3) - tag must already exist" |
| 14 | + required: true |
| 15 | + type: string |
| 16 | + |
| 17 | +permissions: |
| 18 | + contents: write |
| 19 | + |
| 20 | +jobs: |
| 21 | + # =========================================================================== |
| 22 | + # Validate that tag exists before build |
| 23 | + # =========================================================================== |
| 24 | + validate: |
| 25 | + runs-on: ubuntu-latest |
| 26 | + steps: |
| 27 | + - name: Validate version format |
| 28 | + env: |
| 29 | + VERSION: ${{ inputs.version }} |
| 30 | + run: | |
| 31 | + if [[ ! "$VERSION" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then |
| 32 | + echo "Error: Invalid version format '$VERSION'" |
| 33 | + echo "Expected format: vX.Y.Z (e.g., v1.2.3)" |
| 34 | + exit 1 |
| 35 | + fi |
| 36 | + echo "Version format valid: $VERSION" |
| 37 | +
|
| 38 | + - name: Check tag exists |
| 39 | + env: |
| 40 | + VERSION: ${{ inputs.version }} |
| 41 | + GH_TOKEN: ${{ github.token }} |
| 42 | + run: | |
| 43 | + if ! git ls-remote --tags https://github.com/${{ github.repository }} | grep -q "refs/tags/${VERSION}$"; then |
| 44 | + echo "Error: Tag '$VERSION' does not exist" |
| 45 | + echo "Please create the tag first using the 'Tag' workflow" |
| 46 | + exit 1 |
| 47 | + fi |
| 48 | + echo "Tag exists: $VERSION" |
| 49 | +
|
| 50 | + # =========================================================================== |
| 51 | + # Build: All platforms (no CGO required) |
| 52 | + # =========================================================================== |
| 53 | + build: |
| 54 | + needs: [validate] |
| 55 | + runs-on: ubuntu-latest |
| 56 | + steps: |
| 57 | + - name: Checkout |
| 58 | + uses: actions/checkout@v4 |
| 59 | + with: |
| 60 | + ref: ${{ inputs.version }} |
| 61 | + fetch-depth: 0 |
| 62 | + |
| 63 | + - name: Set up Go |
| 64 | + uses: actions/setup-go@v5 |
| 65 | + with: |
| 66 | + go-version-file: go.mod |
| 67 | + |
| 68 | + - name: Build all platforms |
| 69 | + uses: goreleaser/goreleaser-action@v6 |
| 70 | + with: |
| 71 | + distribution: goreleaser |
| 72 | + version: "~> v2" |
| 73 | + args: build --clean |
| 74 | + env: |
| 75 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 76 | + |
| 77 | + - name: Upload artifacts |
| 78 | + uses: actions/upload-artifact@v4 |
| 79 | + with: |
| 80 | + name: dist |
| 81 | + path: dist/ |
| 82 | + retention-days: 1 |
| 83 | + |
| 84 | + # =========================================================================== |
| 85 | + # Release: Create packages and publish |
| 86 | + # =========================================================================== |
| 87 | + release: |
| 88 | + needs: [build] |
| 89 | + runs-on: ubuntu-latest |
| 90 | + steps: |
| 91 | + - name: Checkout |
| 92 | + uses: actions/checkout@v4 |
| 93 | + with: |
| 94 | + ref: ${{ inputs.version }} |
| 95 | + fetch-depth: 0 |
| 96 | + |
| 97 | + - name: Set up Go |
| 98 | + uses: actions/setup-go@v5 |
| 99 | + with: |
| 100 | + go-version-file: go.mod |
| 101 | + |
| 102 | + - name: Download artifacts |
| 103 | + uses: actions/download-artifact@v4 |
| 104 | + with: |
| 105 | + name: dist |
| 106 | + path: dist |
| 107 | + |
| 108 | + - name: List dist contents |
| 109 | + run: find dist -type f | sort |
| 110 | + |
| 111 | + - name: Create archives |
| 112 | + env: |
| 113 | + VERSION: ${{ inputs.version }} |
| 114 | + run: | |
| 115 | + VERSION="${VERSION#v}" |
| 116 | + mkdir -p releases |
| 117 | +
|
| 118 | + for dir in dist/*/; do |
| 119 | + [[ -d "$dir" ]] || continue |
| 120 | + build_name=$(basename "$dir") |
| 121 | + goos=$(echo "$build_name" | cut -d'_' -f2) |
| 122 | + goarch=$(echo "$build_name" | cut -d'_' -f3) |
| 123 | +
|
| 124 | + staging="staging_${build_name}" |
| 125 | + mkdir -p "$staging" |
| 126 | +
|
| 127 | + if [[ "$goos" == "windows" ]]; then |
| 128 | + archive_name="sql-http-proxy_${VERSION}_${goos}_${goarch}.zip" |
| 129 | + cp "$dir/sql-http-proxy.exe" "$staging/" |
| 130 | + cp README.md LICENSE SCHEMA.md "$staging/" |
| 131 | + (cd "$staging" && zip -r "../releases/${archive_name}" .) |
| 132 | + else |
| 133 | + archive_name="sql-http-proxy_${VERSION}_${goos}_${goarch}.tar.gz" |
| 134 | + cp "$dir/sql-http-proxy" "$staging/" |
| 135 | + cp README.md LICENSE SCHEMA.md "$staging/" |
| 136 | + tar -czvf "releases/${archive_name}" -C "$staging" . |
| 137 | + fi |
| 138 | + rm -rf "$staging" |
| 139 | + done |
| 140 | +
|
| 141 | + ls -la releases/ |
| 142 | +
|
| 143 | + - name: Create Linux packages (.deb, .rpm) |
| 144 | + env: |
| 145 | + VERSION: ${{ inputs.version }} |
| 146 | + run: | |
| 147 | + set -euo pipefail |
| 148 | + VERSION="${VERSION#v}" |
| 149 | +
|
| 150 | + # Install nfpm |
| 151 | + go install github.com/goreleaser/nfpm/v2/cmd/nfpm@v2.41.1 |
| 152 | + export PATH="$(go env GOPATH)/bin:$PATH" |
| 153 | +
|
| 154 | + for arch in amd64 arm64; do |
| 155 | + case "$arch" in |
| 156 | + amd64) deb_arch="amd64"; rpm_arch="x86_64" ;; |
| 157 | + arm64) deb_arch="arm64"; rpm_arch="aarch64" ;; |
| 158 | + esac |
| 159 | +
|
| 160 | + export VERSION="${VERSION}" |
| 161 | + export GOARCH="${arch}" |
| 162 | +
|
| 163 | + # Find the binary |
| 164 | + bin_dir=$(find dist -maxdepth 1 -type d -name "sql-http-proxy_linux_${arch}*" | head -1) |
| 165 | + if [[ -z "$bin_dir" || ! -d "$bin_dir" ]]; then |
| 166 | + echo "Error: Binary directory not found for ${arch}" |
| 167 | + find dist -maxdepth 1 -type d |
| 168 | + exit 1 |
| 169 | + fi |
| 170 | + cp "${bin_dir}/sql-http-proxy" ./sql-http-proxy |
| 171 | +
|
| 172 | + echo "=== Generating packages for ${arch} ===" |
| 173 | + nfpm pkg --config .github/templates/nfpm.yaml --packager deb --target "releases/sql-http-proxy_${VERSION}-1_${deb_arch}.deb" |
| 174 | + nfpm pkg --config .github/templates/nfpm.yaml --packager rpm --target "releases/sql-http-proxy-${VERSION}-1.${rpm_arch}.rpm" |
| 175 | + rm ./sql-http-proxy |
| 176 | + done |
| 177 | +
|
| 178 | + echo "=== Generated packages ===" |
| 179 | + ls -la releases/*.deb releases/*.rpm |
| 180 | +
|
| 181 | + - name: Generate checksums |
| 182 | + run: | |
| 183 | + cd releases |
| 184 | + sha256sum * > checksums.txt |
| 185 | + cat checksums.txt |
| 186 | +
|
| 187 | + - name: Create GitHub Release |
| 188 | + env: |
| 189 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 190 | + TAG: ${{ inputs.version }} |
| 191 | + run: | |
| 192 | + gh release create "$TAG" \ |
| 193 | + --title "$TAG" \ |
| 194 | + --generate-notes \ |
| 195 | + releases/* |
| 196 | +
|
| 197 | + - name: Update Homebrew formula |
| 198 | + env: |
| 199 | + HOMEBREW_TAP_TOKEN: ${{ secrets.HOMEBREW_TAP_TOKEN }} |
| 200 | + TAG: ${{ inputs.version }} |
| 201 | + run: | |
| 202 | + if [[ -z "$HOMEBREW_TAP_TOKEN" ]]; then |
| 203 | + echo "HOMEBREW_TAP_TOKEN not set, skipping Homebrew update" |
| 204 | + exit 0 |
| 205 | + fi |
| 206 | +
|
| 207 | + export VERSION="${TAG#v}" |
| 208 | + export SHA256_DARWIN_AMD64=$(grep "darwin_amd64.tar.gz" releases/checksums.txt | cut -d' ' -f1) |
| 209 | + export SHA256_DARWIN_ARM64=$(grep "darwin_arm64.tar.gz" releases/checksums.txt | cut -d' ' -f1) |
| 210 | + export SHA256_LINUX_AMD64=$(grep -E "sql-http-proxy_[0-9.]+_linux_amd64\.tar\.gz$" releases/checksums.txt | cut -d' ' -f1) |
| 211 | + export SHA256_LINUX_ARM64=$(grep -E "sql-http-proxy_[0-9.]+_linux_arm64\.tar\.gz$" releases/checksums.txt | cut -d' ' -f1) |
| 212 | +
|
| 213 | + envsubst < .github/templates/homebrew-formula.rb > sql-http-proxy.rb |
| 214 | + echo "=== sql-http-proxy.rb ===" && cat sql-http-proxy.rb |
| 215 | +
|
| 216 | + git clone "https://x-access-token:${HOMEBREW_TAP_TOKEN}@github.com/mpyw/homebrew-tap.git" |
| 217 | + mkdir -p homebrew-tap/Formula |
| 218 | + cp sql-http-proxy.rb homebrew-tap/Formula/ |
| 219 | + cd homebrew-tap |
| 220 | + git config user.name "github-actions[bot]" |
| 221 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 222 | + git add Formula/sql-http-proxy.rb |
| 223 | + git commit -m "Update sql-http-proxy to ${VERSION}" |
| 224 | + git push |
| 225 | +
|
| 226 | + - name: Update Scoop manifest |
| 227 | + env: |
| 228 | + SCOOP_BUCKET_TOKEN: ${{ secrets.SCOOP_BUCKET_TOKEN }} |
| 229 | + TAG: ${{ inputs.version }} |
| 230 | + run: | |
| 231 | + if [[ -z "$SCOOP_BUCKET_TOKEN" ]]; then |
| 232 | + echo "SCOOP_BUCKET_TOKEN not set, skipping Scoop update" |
| 233 | + exit 0 |
| 234 | + fi |
| 235 | +
|
| 236 | + export VERSION="${TAG#v}" |
| 237 | + export SHA256_WINDOWS_AMD64=$(grep "windows_amd64.zip" releases/checksums.txt | cut -d' ' -f1) |
| 238 | + export SHA256_WINDOWS_ARM64=$(grep "windows_arm64.zip" releases/checksums.txt | cut -d' ' -f1) |
| 239 | +
|
| 240 | + if [[ -z "$SHA256_WINDOWS_AMD64" || -z "$SHA256_WINDOWS_ARM64" ]]; then |
| 241 | + echo "Error: Could not find SHA256 checksums for Windows builds" |
| 242 | + cat releases/checksums.txt |
| 243 | + exit 1 |
| 244 | + fi |
| 245 | +
|
| 246 | + envsubst < .github/templates/scoop-manifest.json > sql-http-proxy.json |
| 247 | + cat sql-http-proxy.json |
| 248 | +
|
| 249 | + git clone "https://x-access-token:${SCOOP_BUCKET_TOKEN}@github.com/mpyw/scoop-bucket.git" |
| 250 | + cp sql-http-proxy.json scoop-bucket/ |
| 251 | + cd scoop-bucket |
| 252 | + git config user.name "github-actions[bot]" |
| 253 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 254 | + git add sql-http-proxy.json |
| 255 | + git commit -m "Update sql-http-proxy to ${VERSION}" |
| 256 | + git push |
0 commit comments