|
| 1 | +# Create an incremental tag (like `cli-v1.2.0`) on Github using SemVer https://semver.org: x.y.z |
| 2 | +# Create the Release (like `cli-v1.2.0`) based on this tag and with the same name. |
| 3 | +# Build the CLI for all OS and upload them as assets to the release. |
| 4 | + |
| 5 | +name: Release CLI |
| 6 | + |
| 7 | +on: |
| 8 | + workflow_dispatch: |
| 9 | + inputs: |
| 10 | + choice: |
| 11 | + type: choice |
| 12 | + description: "Release types (x.y.patch / x.minor.z / major.y.z)" |
| 13 | + options: |
| 14 | + - patch |
| 15 | + - minor |
| 16 | + - major |
| 17 | + |
| 18 | +jobs: |
| 19 | + release-cli: |
| 20 | + if: ${{ github.ref == 'refs/heads/main' }} |
| 21 | + name: Release CLI |
| 22 | + strategy: |
| 23 | + matrix: |
| 24 | + include: |
| 25 | + - goarch: amd64 |
| 26 | + goos: linux |
| 27 | + |
| 28 | + - goarch: amd64 |
| 29 | + goos: windows |
| 30 | + |
| 31 | + - goarch: arm64 |
| 32 | + goos: darwin |
| 33 | + |
| 34 | + - goarch: amd64 |
| 35 | + goos: darwin |
| 36 | + |
| 37 | + runs-on: ubuntu-latest |
| 38 | + env: |
| 39 | + OSNAME: ${{matrix.goos == 'darwin' && 'macos' || matrix.goos }} |
| 40 | + GOARCH: ${{ matrix.goarch }} |
| 41 | + GOOS: ${{ matrix.goos }} |
| 42 | + ARCHNAME: ${{ matrix.goarch == 'amd64' && 'x86-64' || matrix.goarch }} |
| 43 | + steps: |
| 44 | + - name: Checkout code |
| 45 | + uses: actions/checkout@v3 |
| 46 | + |
| 47 | + - name: Set env var |
| 48 | + run: echo "ZIPFILE=sqlitecloud-go-${{ steps.tag-and-release.outputs.name }}-${{ env.OSNAME }}-${{ env.ARCHNAME }}.zip" >> $GITHUB_ENV |
| 49 | + |
| 50 | + - name: Build CLI |
| 51 | + run: | |
| 52 | + cd GO/cli |
| 53 | + go build -o ../sqlc |
| 54 | + cd .. |
| 55 | + zip ${{ env.ZIPFILE }} sqlc |
| 56 | +
|
| 57 | + - name: Last version |
| 58 | + id: last-version |
| 59 | + # last tag that starts with 'cli-v', eg: cli-v1.2.0 but outputs it as: v1.2.0 |
| 60 | + run: echo "::set-output name=number::$(git tag --list 'cli-v*' | sort -V | tail -n1 | sed 's/cli-//')" |
| 61 | + |
| 62 | + - name: Bump version |
| 63 | + id: bump-version |
| 64 | + uses: olegsu/semver-action@v1 |
| 65 | + with: |
| 66 | + version: ${{ steps.last-version.outputs.number }} |
| 67 | + bump: ${{ inputs.choice }} |
| 68 | + |
| 69 | + - name: Tag and Release name |
| 70 | + id: tag-and-release |
| 71 | + # eg: cli-v1.2.0 |
| 72 | + run: echo "::set-output name=name::cli-v$(git tag --list 'v*' | sort -V | tail -n1)" |
| 73 | + |
| 74 | + - name: Create Release for CLI |
| 75 | + id: release |
| 76 | + uses: softprops/action-gh-release@v2 |
| 77 | + with: |
| 78 | + tag_name: ${{ steps.tag-and-release.outputs.name }} |
| 79 | + name: Release ${{ steps.tag-and-release.outputs.name }} |
| 80 | + draft: false |
| 81 | + generate_release_notes: true |
| 82 | + make_latest: true |
| 83 | + env: |
| 84 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 85 | + |
| 86 | + - name: Upload Release Asset |
| 87 | + id: upload-release-asset |
| 88 | + uses: actions/upload-release-asset@v1 |
| 89 | + if: matrix.goos != 'darwin' |
| 90 | + env: |
| 91 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 92 | + with: |
| 93 | + upload_url: ${{ steps.release.outputs.upload_url }} |
| 94 | + asset_path: ./GO/${{ env.ZIPFILE }} |
| 95 | + asset_name: ${{ env.ZIPFILE }} |
| 96 | + asset_content_type: application/zip |
| 97 | + |
| 98 | + - name: Upload binary artifact |
| 99 | + uses: actions/upload-artifact@v3 |
| 100 | + if: matrix.goos == 'darwin' |
| 101 | + with: |
| 102 | + name: ${{ env.ZIPFILE }} |
| 103 | + path: ./GO/${{ env.ZIPFILE }} |
| 104 | + if-no-files-found: error |
0 commit comments