|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - "v*.*.*" |
| 7 | + |
| 8 | +env: |
| 9 | + CARGO_TERM_COLOR: always |
| 10 | + |
| 11 | +jobs: |
| 12 | + test: |
| 13 | + name: Run tests |
| 14 | + runs-on: ubuntu-latest |
| 15 | + |
| 16 | + steps: |
| 17 | + - uses: actions/checkout@v4 |
| 18 | + with: |
| 19 | + ref: ${{ github.ref }} |
| 20 | + |
| 21 | + - name: Install Rust |
| 22 | + uses: dtolnay/rust-toolchain@stable |
| 23 | + |
| 24 | + - name: Run tests |
| 25 | + run: cargo test --all-features --verbose |
| 26 | + |
| 27 | + - name: Run clippy |
| 28 | + run: cargo clippy --all-features -- -D warnings |
| 29 | + |
| 30 | + build-binaries: |
| 31 | + name: Build binaries |
| 32 | + needs: test |
| 33 | + strategy: |
| 34 | + matrix: |
| 35 | + include: |
| 36 | + # Linux |
| 37 | + - target: x86_64-unknown-linux-gnu |
| 38 | + os: ubuntu-latest |
| 39 | + name: sql-schema-x86_64-linux |
| 40 | + - target: aarch64-unknown-linux-gnu |
| 41 | + os: ubuntu-latest |
| 42 | + name: sql-schema-aarch64-linux |
| 43 | + # macOS |
| 44 | + - target: x86_64-apple-darwin |
| 45 | + os: macos-latest |
| 46 | + name: sql-schema-x86_64-macos |
| 47 | + - target: aarch64-apple-darwin |
| 48 | + os: macos-latest |
| 49 | + name: sql-schema-aarch64-macos |
| 50 | + # Windows |
| 51 | + - target: x86_64-pc-windows-msvc |
| 52 | + os: windows-latest |
| 53 | + name: sql-schema-x86_64-windows.exe |
| 54 | + - target: aarch64-pc-windows-msvc |
| 55 | + os: windows-latest |
| 56 | + name: sql-schema-aarch64-windows.exe |
| 57 | + |
| 58 | + runs-on: ${{ matrix.os }} |
| 59 | + |
| 60 | + steps: |
| 61 | + - uses: actions/checkout@v4 |
| 62 | + with: |
| 63 | + ref: ${{ github.ref }} |
| 64 | + |
| 65 | + - name: Install Rust |
| 66 | + uses: dtolnay/rust-toolchain@stable |
| 67 | + with: |
| 68 | + targets: ${{ matrix.target }} |
| 69 | + |
| 70 | + - name: Install cross-compilation tools for aarch64-linux |
| 71 | + if: matrix.target == 'aarch64-unknown-linux-gnu' |
| 72 | + run: | |
| 73 | + sudo apt-get update |
| 74 | + sudo apt-get install -y gcc-aarch64-linux-gnu |
| 75 | +
|
| 76 | + - name: Build binary |
| 77 | + run: cargo build --release --target ${{ matrix.target }} --verbose |
| 78 | + env: |
| 79 | + CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER: aarch64-linux-gnu-gcc |
| 80 | + |
| 81 | + - name: Prepare binary |
| 82 | + shell: bash |
| 83 | + run: | |
| 84 | + if [[ "${{ matrix.os }}" == "windows-latest" ]]; then |
| 85 | + cp target/${{ matrix.target }}/release/sql-schema.exe ${{ matrix.name }} |
| 86 | + else |
| 87 | + cp target/${{ matrix.target }}/release/sql-schema ${{ matrix.name }} |
| 88 | + fi |
| 89 | +
|
| 90 | + - name: Upload binary artifact |
| 91 | + uses: actions/upload-artifact@v4 |
| 92 | + with: |
| 93 | + name: ${{ matrix.name }} |
| 94 | + path: ${{ matrix.name }} |
| 95 | + |
| 96 | + create-release: |
| 97 | + name: Create GitHub Release |
| 98 | + needs: build-binaries |
| 99 | + runs-on: ubuntu-latest |
| 100 | + permissions: |
| 101 | + contents: write |
| 102 | + outputs: |
| 103 | + upload_url: ${{ steps.create_release.outputs.upload_url }} |
| 104 | + |
| 105 | + steps: |
| 106 | + - uses: actions/checkout@v4 |
| 107 | + with: |
| 108 | + ref: ${{ github.ref }} |
| 109 | + fetch-depth: 0 # Fetch all history for git-cliff |
| 110 | + |
| 111 | + - name: Get version from tag |
| 112 | + id: get_version |
| 113 | + run: echo "VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT |
| 114 | + |
| 115 | + - name: Generate changelog |
| 116 | + id: git-cliff |
| 117 | + uses: orhun/git-cliff-action@v3 |
| 118 | + with: |
| 119 | + config: cliff.toml |
| 120 | + args: --current --strip all |
| 121 | + env: |
| 122 | + OUTPUT: CHANGELOG.md |
| 123 | + |
| 124 | + - name: Download all artifacts |
| 125 | + uses: actions/download-artifact@v4 |
| 126 | + with: |
| 127 | + path: ./binaries |
| 128 | + |
| 129 | + - name: Create Release |
| 130 | + id: create_release |
| 131 | + uses: actions/create-release@v1 |
| 132 | + env: |
| 133 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 134 | + with: |
| 135 | + tag_name: ${{ github.ref }} |
| 136 | + release_name: Release ${{ steps.get_version.outputs.VERSION }} |
| 137 | + draft: false |
| 138 | + prerelease: false |
| 139 | + body: | |
| 140 | + ## Changes in ${{ steps.get_version.outputs.VERSION }} |
| 141 | +
|
| 142 | + ${{ steps.git-cliff.outputs.content }} |
| 143 | +
|
| 144 | + ### Installation |
| 145 | +
|
| 146 | + #### From crates.io |
| 147 | + ```bash |
| 148 | + cargo install sql-schema |
| 149 | + ``` |
| 150 | +
|
| 151 | + #### Binary downloads |
| 152 | + Download the appropriate binary for your platform from the assets below. |
| 153 | +
|
| 154 | + - name: Upload Linux x86_64 binary |
| 155 | + uses: actions/upload-release-asset@v1 |
| 156 | + env: |
| 157 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 158 | + with: |
| 159 | + upload_url: ${{ steps.create_release.outputs.upload_url }} |
| 160 | + asset_path: ./binaries/sql-schema-x86_64-linux/sql-schema-x86_64-linux |
| 161 | + asset_name: sql-schema-x86_64-linux |
| 162 | + asset_content_type: application/octet-stream |
| 163 | + |
| 164 | + - name: Upload Linux aarch64 binary |
| 165 | + uses: actions/upload-release-asset@v1 |
| 166 | + env: |
| 167 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 168 | + with: |
| 169 | + upload_url: ${{ steps.create_release.outputs.upload_url }} |
| 170 | + asset_path: ./binaries/sql-schema-aarch64-linux/sql-schema-aarch64-linux |
| 171 | + asset_name: sql-schema-aarch64-linux |
| 172 | + asset_content_type: application/octet-stream |
| 173 | + |
| 174 | + - name: Upload macOS x86_64 binary |
| 175 | + uses: actions/upload-release-asset@v1 |
| 176 | + env: |
| 177 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 178 | + with: |
| 179 | + upload_url: ${{ steps.create_release.outputs.upload_url }} |
| 180 | + asset_path: ./binaries/sql-schema-x86_64-macos/sql-schema-x86_64-macos |
| 181 | + asset_name: sql-schema-x86_64-macos |
| 182 | + asset_content_type: application/octet-stream |
| 183 | + |
| 184 | + - name: Upload macOS aarch64 binary |
| 185 | + uses: actions/upload-release-asset@v1 |
| 186 | + env: |
| 187 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 188 | + with: |
| 189 | + upload_url: ${{ steps.create_release.outputs.upload_url }} |
| 190 | + asset_path: ./binaries/sql-schema-aarch64-macos/sql-schema-aarch64-macos |
| 191 | + asset_name: sql-schema-aarch64-macos |
| 192 | + asset_content_type: application/octet-stream |
| 193 | + |
| 194 | + - name: Upload Windows x86_64 binary |
| 195 | + uses: actions/upload-release-asset@v1 |
| 196 | + env: |
| 197 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 198 | + with: |
| 199 | + upload_url: ${{ steps.create_release.outputs.upload_url }} |
| 200 | + asset_path: ./binaries/sql-schema-x86_64-windows.exe/sql-schema-x86_64-windows.exe |
| 201 | + asset_name: sql-schema-x86_64-windows.exe |
| 202 | + asset_content_type: application/octet-stream |
| 203 | + |
| 204 | + - name: Upload Windows aarch64 binary |
| 205 | + uses: actions/upload-release-asset@v1 |
| 206 | + env: |
| 207 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 208 | + with: |
| 209 | + upload_url: ${{ steps.create_release.outputs.upload_url }} |
| 210 | + asset_path: ./binaries/sql-schema-aarch64-windows.exe/sql-schema-aarch64-windows.exe |
| 211 | + asset_name: sql-schema-aarch64-windows.exe |
| 212 | + asset_content_type: application/octet-stream |
| 213 | + |
| 214 | + publish-crate: |
| 215 | + name: Publish to crates.io |
| 216 | + needs: create-release |
| 217 | + runs-on: ubuntu-latest |
| 218 | + |
| 219 | + steps: |
| 220 | + - uses: actions/checkout@v4 |
| 221 | + with: |
| 222 | + ref: ${{ github.ref }} |
| 223 | + |
| 224 | + - name: Install Rust |
| 225 | + uses: dtolnay/rust-toolchain@stable |
| 226 | + |
| 227 | + - name: Verify version matches tag |
| 228 | + run: | |
| 229 | + TAG_VERSION="${GITHUB_REF#refs/tags/v}" |
| 230 | + CARGO_VERSION=$(grep "^version" Cargo.toml | head -1 | cut -d'"' -f2) |
| 231 | + if [ "$TAG_VERSION" != "$CARGO_VERSION" ]; then |
| 232 | + echo "Error: Tag version ($TAG_VERSION) doesn't match Cargo.toml version ($CARGO_VERSION)" |
| 233 | + exit 1 |
| 234 | + fi |
| 235 | + echo "CARGO_VERSION=$CARGO_VERSION" >> $GITHUB_ENV |
| 236 | +
|
| 237 | + - name: Publish to crates.io |
| 238 | + run: | |
| 239 | + # Try to publish, but don't fail if the version already exists |
| 240 | + cargo publish --token ${{ secrets.CARGO_REGISTRY_TOKEN }} --verbose || { |
| 241 | + EXIT_CODE=$? |
| 242 | + # Check if it failed because the version already exists |
| 243 | + cargo search sql-schema --limit 1 | grep -q "sql-schema = \"$CARGO_VERSION\"" && { |
| 244 | + echo "Version $CARGO_VERSION already published on crates.io, skipping..." |
| 245 | + exit 0 |
| 246 | + } |
| 247 | + # If it failed for another reason, exit with the original error code |
| 248 | + exit $EXIT_CODE |
| 249 | + } |
| 250 | + env: |
| 251 | + CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }} |
0 commit comments