Skip to content

Release CLI

Release CLI #14

Workflow file for this run

# 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:
set-releasename:
runs-on: ubuntu-latest
name: New release name
outputs:
RELEASENAME: ${{ steps.output-releasename.outputs.RELEASENAME }}
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: Output release name
id: output-releasename
run: echo "RELEASENAME=cli-v${{ steps.bump-version.outputs.version }}" >> $GITHUB_OUTPUT
build-cli:
# if: ${{ github.ref == 'refs/heads/main' }}
needs: set-releasename
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:
RELEASENAME: ${{ needs.set-releasename.outputs.RELEASENAME }}
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: Set zipfile name
run: echo "ZIPFILE=sqlitecloud-go-${{ env.RELEASENAME }}-${{ 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
env:
RELEASENAME: ${{ needs.set-releasename.outputs.RELEASENAME }}
outputs:
UPLOADURL: ${{ steps.set-release-upload-url.outputs.UPLOADURL }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- 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
id: 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:
UPLOADURL: ${{ needs.release-cli.outputs.UPLOADURL }}
RELEASENAME: ${{ needs.set-releasename.outputs.RELEASENAME }}
OSNAME: ${{matrix.goos == 'darwin' && 'macos' || matrix.goos }}
GOARCH: ${{ matrix.goarch }}
GOOS: ${{ matrix.goos }}
ARCHNAME: ${{ matrix.goarch == 'amd64' && 'x86-64' || matrix.goarch }}
steps:
- name: Set zip filename
run: echo "ZIPFILE=sqlitecloud-go-${{ env.RELEASENAME }}-${{ 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: ${{ env.UPLOADURL }}
asset_path: ./${{ env.ZIPFILE }}
asset_name: ${{ env.ZIPFILE }}
asset_content_type: application/zip