From 084a26d00135cd5275afadef9fe3220d9a0e0db4 Mon Sep 17 00:00:00 2001 From: Daniele Briggi Date: Tue, 18 Jun 2024 19:46:11 +0000 Subject: [PATCH] fix(cli): release workflow --- .github/workflows/release-cli.yaml | 132 +++++++++++++----- .../{release.yaml => release-sdk.yaml} | 17 ++- 2 files changed, 106 insertions(+), 43 deletions(-) rename .github/workflows/{release.yaml => release-sdk.yaml} (79%) diff --git a/.github/workflows/release-cli.yaml b/.github/workflows/release-cli.yaml index c85f524..e544c1a 100644 --- a/.github/workflows/release-cli.yaml +++ b/.github/workflows/release-cli.yaml @@ -1,6 +1,6 @@ # 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`) based on this tag and with the same name. -# Build the CLI for all OS and upload them as assets to the release. +# 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 @@ -16,9 +16,37 @@ on: - major jobs: - release-cli: - if: ${{ github.ref == 'refs/heads/main' }} - name: Release CLI + 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: @@ -36,53 +64,91 @@ jobs: 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@v3 - - - name: Set env var - run: echo "ZIPFILE=sqlitecloud-go-${{ steps.tag-and-release.outputs.name }}-${{ env.OSNAME }}-${{ env.ARCHNAME }}.zip" >> $GITHUB_ENV + - name: Set zipfile name + run: echo "ZIPFILE=sqlitecloud-go-${{ env.RELEASENAME }}-${{ env.OSNAME }}-${{ env.ARCHNAME }}.zip" >> $GITHUB_ENV - name: Build CLI run: | - cd GO/cli + cd cli go build -o ../sqlc cd .. zip ${{ env.ZIPFILE }} sqlc - - name: Last version - id: last-version - # last tag that starts with 'cli-v', eg: cli-v1.2.0 but outputs it as: v1.2.0 - run: echo "::set-output name=number::$(git tag --list 'cli-v*' | sort -V | tail -n1 | sed 's/cli-//')" - - - name: Bump version - id: bump-version - uses: olegsu/semver-action@v1 + # Upload assets to be used in the last job + - name: Upload binary artifact + uses: actions/upload-artifact@v4 with: - version: ${{ steps.last-version.outputs.number }} - bump: ${{ inputs.choice }} + name: ${{ env.ZIPFILE }} + path: ./${{ env.ZIPFILE }} + if-no-files-found: error - - name: Tag and Release name - id: tag-and-release - # eg: cli-v1.2.0 - run: echo "::set-output name=name::cli-v$(git tag --list 'v*' | sort -V | tail -n1)" + 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: ${{ steps.tag-and-release.outputs.name }} - name: Release ${{ steps.tag-and-release.outputs.name }} + 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 @@ -90,15 +156,7 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: - upload_url: ${{ steps.release.outputs.upload_url }} - asset_path: ./GO/${{ env.ZIPFILE }} + upload_url: ${{ env.UPLOADURL }} + asset_path: ./${{ env.ZIPFILE }} asset_name: ${{ env.ZIPFILE }} asset_content_type: application/zip - - - name: Upload binary artifact - uses: actions/upload-artifact@v3 - if: matrix.goos == 'darwin' - with: - name: ${{ env.ZIPFILE }} - path: ./GO/${{ env.ZIPFILE }} - if-no-files-found: error diff --git a/.github/workflows/release.yaml b/.github/workflows/release-sdk.yaml similarity index 79% rename from .github/workflows/release.yaml rename to .github/workflows/release-sdk.yaml index 99a65ba..757ed0b 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release-sdk.yaml @@ -2,7 +2,7 @@ # A tag is a release version on pkg.go.dev, which is # notified with the publishing go command. -name: Release +name: Release SDK on: workflow_dispatch: @@ -16,30 +16,35 @@ on: - major jobs: - release: + release-sdk: if: ${{ github.ref == 'refs/heads/main' }} runs-on: ubuntu-latest name: Tag for release steps: - name: Checkout code - uses: actions/checkout@v2 + uses: actions/checkout@v4 with: + # download tags fetch-depth: 0 + - name: Last version id: last-version - # last tag that starts with 'v', eg: v1.0.3 - run: echo "::set-output name=tag::$(git tag --list 'v*' | sort -V | tail -n1)" + # last tag that starts with 'v', eg: v1.0.3 but outputs it as: 1.0.3 + run: echo "LASTVERSION=$(git tag --list 'v*' | sort -V | tail -n1 | sed 's/v//')" >> $GITHUB_ENV + - name: Bump version id: bump-version uses: olegsu/semver-action@v1 with: - version: ${{ steps.last-version.outputs.tag }} + version: ${{ env.LASTVERSION }} bump: ${{ inputs.choice }} + - name: Create tag as version for the package run: | git config --global user.email "github-actions[bot]@users.noreply.github.com" git config --global user.name "GitHub Actions" git tag v${{ steps.bump-version.outputs.version }} git push origin v${{ steps.bump-version.outputs.version }} + - name: Publish on pkg.go.dev run: GOPROXY=proxy.golang.org go list -m github.com/sqlitecloud/sqlitecloud-go@v${{ steps.bump-version.outputs.version }}