Release CLI #8
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Create an incremental tag (like `cli-v1.2.0`) on Github using SemVer https://semver.org: x.y.z | |
# Create the Release (like `cli-v1.2.0`) related to the tag and with the same name. | |
# Build the CLI for all OS and upload them to the release as assets. | |
name: Release CLI | |
on: | |
workflow_dispatch: | |
inputs: | |
choice: | |
type: choice | |
description: "Release types (x.y.patch / x.minor.z / major.y.z)" | |
options: | |
- patch | |
- minor | |
- major | |
jobs: | |
build-cli: | |
# if: ${{ github.ref == 'refs/heads/main' }} | |
name: Build CLI | |
strategy: | |
matrix: | |
include: | |
- goarch: amd64 | |
goos: linux | |
- goarch: amd64 | |
goos: windows | |
- goarch: arm64 | |
goos: darwin | |
- goarch: amd64 | |
goos: darwin | |
runs-on: ubuntu-latest | |
env: | |
OSNAME: ${{matrix.goos == 'darwin' && 'macos' || matrix.goos }} | |
GOARCH: ${{ matrix.goarch }} | |
GOOS: ${{ matrix.goos }} | |
ARCHNAME: ${{ matrix.goarch == 'amd64' && 'x86-64' || matrix.goarch }} | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Last version | |
id: last-version | |
# last tag that starts with 'cli-v', eg: cli-v1.2.0 | |
run: echo "LASTVERSION=$(git tag --list 'cli-v*' | sort -V | tail -n1)" >> $GITHUB_ENV | |
- name: Set env var | |
run: echo "ZIPFILE=sqlitecloud-go-${{ env.LASTVERSION }}-${{ env.OSNAME }}-${{ env.ARCHNAME }}.zip" >> $GITHUB_ENV | |
- name: Build CLI | |
run: | | |
cd cli | |
go build -o ../sqlc | |
cd .. | |
zip ${{ env.ZIPFILE }} sqlc | |
# Upload assets to be used in the last job | |
- name: Upload binary artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: ${{ env.ZIPFILE }} | |
path: ./${{ env.ZIPFILE }} | |
if-no-files-found: error | |
release-cli: | |
name: Release CLI | |
needs: build-cli | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
with: | |
# download tags | |
fetch-depth: 0 | |
- name: Last version | |
id: last-version | |
run: echo "LASTVERSION=$(git tag --list 'cli-v*' | sort -V | tail -n1 | sed 's/cli-v//')" >> $GITHUB_ENV | |
- name: Bump version | |
id: bump-version | |
uses: olegsu/semver-action@v1 | |
with: | |
version: ${{ env.LASTVERSION }} | |
bump: ${{ inputs.choice }} | |
- name: Set tag and release name | |
id: tag-and-release | |
# eg: cli-v1.2.0 | |
run: echo "RELEASENAME=cli-v${{ env.LASTVERSION }}" >> $GITHUB_ENV | |
- name: Create Release for CLI | |
id: release | |
uses: softprops/action-gh-release@v2 | |
with: | |
tag_name: ${{ env.RELEASENAME }} | |
name: Release ${{ env.RELEASENAME }} | |
draft: false | |
generate_release_notes: true | |
make_latest: true | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Set release upload url | |
run: echo "UPLOADURL=${{ steps.release.outputs.upload_url }}" >> $GITHUB_OUTPUT | |
upload-artifacts: | |
needs: release-cli | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
include: | |
- goarch: amd64 | |
goos: linux | |
- goarch: amd64 | |
goos: windows | |
- goarch: arm64 | |
goos: darwin | |
- goarch: amd64 | |
goos: darwin | |
env: | |
OSNAME: ${{matrix.goos == 'darwin' && 'macos' || matrix.goos }} | |
GOARCH: ${{ matrix.goarch }} | |
GOOS: ${{ matrix.goos }} | |
ARCHNAME: ${{ matrix.goarch == 'amd64' && 'x86-64' || matrix.goarch }} | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Last version | |
id: last-version | |
run: echo "LASTVERSION=$(git tag --list 'cli-v*' | sort -V | tail -n1)" >> $GITHUB_ENV | |
- name: Set zip filename | |
run: echo "ZIPFILE=sqlitecloud-go-${{ env.LASTVERSION }}-${{ env.OSNAME }}-${{ env.ARCHNAME }}.zip" >> $GITHUB_ENV | |
- name: Download artifact | |
uses: actions/download-artifact@v4 | |
with: | |
name: ${{ env.ZIPFILE }} | |
- name: Upload Release Asset | |
id: upload-release-asset | |
uses: actions/upload-release-asset@v1 | |
if: matrix.goos != 'darwin' | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
upload_url: ${{ needs.release-cli.outputs.UPLOADURL }} | |
asset_path: ./${{ env.ZIPFILE }} | |
asset_name: ${{ env.ZIPFILE }} | |
asset_content_type: application/zip |