Skip to content

Commit 7c0b00d

Browse files
Merge pull request #12 from sqlitecloud/fixing-release-cli
fix(cli): release workflow
2 parents 53fece6 + 88a5b93 commit 7c0b00d

File tree

3 files changed

+118
-41
lines changed

3 files changed

+118
-41
lines changed

.github/workflows/release-cli.yaml

Lines changed: 106 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# 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.
2+
# Create the Release (like `cli-v1.2.0`) related to the tag and with the same name.
3+
# Build the CLI for all OS and upload them to the release as assets.
44

55
name: Release CLI
66

@@ -16,9 +16,37 @@ on:
1616
- major
1717

1818
jobs:
19-
release-cli:
20-
if: ${{ github.ref == 'refs/heads/main' }}
21-
name: Release CLI
19+
set-releasename:
20+
runs-on: ubuntu-latest
21+
name: New release name
22+
outputs:
23+
RELEASENAME: ${{ steps.set-outputs.outputs.RELEASENAME }}
24+
steps:
25+
- name: Checkout code
26+
uses: actions/checkout@v4
27+
with:
28+
# download tags
29+
fetch-depth: 0
30+
31+
- name: Last version
32+
id: last-version
33+
run: echo "LASTVERSION=$(git tag --list 'cli-v*' | sort -V | tail -n1 | sed 's/cli-v//')" >> $GITHUB_ENV
34+
35+
- name: Bump version
36+
id: bump-version
37+
uses: olegsu/semver-action@v1
38+
with:
39+
version: ${{ env.LASTVERSION }}
40+
bump: ${{ inputs.choice }}
41+
42+
- name: Output release name
43+
id: set-outputs
44+
run: echo "RELEASENAME=cli-v${{ steps.bump-version.outputs.version }}" >> "$GITHUB_OUTPUT"
45+
46+
build-cli:
47+
# if: ${{ github.ref == 'refs/heads/main' }}
48+
needs: set-releasename
49+
name: Build CLI
2250
strategy:
2351
matrix:
2452
include:
@@ -36,69 +64,112 @@ jobs:
3664

3765
runs-on: ubuntu-latest
3866
env:
67+
RELEASENAME: ${{ needs.set-releasename.outputs.RELEASENAME }}
3968
OSNAME: ${{matrix.goos == 'darwin' && 'macos' || matrix.goos }}
4069
GOARCH: ${{ matrix.goarch }}
4170
GOOS: ${{ matrix.goos }}
4271
ARCHNAME: ${{ matrix.goarch == 'amd64' && 'x86-64' || matrix.goarch }}
72+
outputs:
73+
RELEASENAME: ${{ steps.set-outputs.outputs.RELEASENAME }}
4374
steps:
4475
- name: Checkout code
45-
uses: actions/checkout@v3
76+
uses: actions/checkout@v4
4677

47-
- name: Set env var
48-
run: echo "ZIPFILE=sqlitecloud-go-${{ steps.tag-and-release.outputs.name }}-${{ env.OSNAME }}-${{ env.ARCHNAME }}.zip" >> $GITHUB_ENV
78+
- name: Set zipfile name
79+
run: echo "ZIPFILE=sqlitecloud-go-${{ env.RELEASENAME }}-${{ env.OSNAME }}-${{ env.ARCHNAME }}.zip" >> $GITHUB_ENV
4980

5081
- name: Build CLI
5182
run: |
52-
cd GO/cli
83+
cd cli
5384
go build -o ../sqlc
5485
cd ..
5586
zip ${{ env.ZIPFILE }} sqlc
5687
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
88+
# Upload assets to be used in the last job
89+
- name: Upload binary artifact
90+
uses: actions/upload-artifact@v4
6591
with:
66-
version: ${{ steps.last-version.outputs.number }}
67-
bump: ${{ inputs.choice }}
92+
name: ${{ env.ZIPFILE }}
93+
path: ./${{ env.ZIPFILE }}
94+
if-no-files-found: error
95+
96+
- name: Set outputs
97+
id: set-outputs
98+
run: |
99+
echo "RELEASENAME=${{ env.RELEASENAME }}" >> "$GITHUB_OUTPUT"
68100
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)"
101+
release-cli:
102+
name: Release CLI
103+
needs: build-cli
104+
runs-on: ubuntu-latest
105+
env:
106+
RELEASENAME: ${{ needs.build-cli.outputs.RELEASENAME }}
107+
outputs:
108+
RELEASENAME: ${{ steps.set-outputs.outputs.RELEASENAME }}
109+
UPLOADURL: ${{ steps.set-outputs.outputs.UPLOADURL }}
110+
steps:
111+
- name: Checkout code
112+
uses: actions/checkout@v4
73113

74114
- name: Create Release for CLI
75115
id: release
76116
uses: softprops/action-gh-release@v2
77117
with:
78-
tag_name: ${{ steps.tag-and-release.outputs.name }}
79-
name: Release ${{ steps.tag-and-release.outputs.name }}
118+
tag_name: ${{ env.RELEASENAME }}
119+
name: Release ${{ env.RELEASENAME }}
80120
draft: false
81121
generate_release_notes: true
82122
make_latest: true
83123
env:
84124
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
85125

126+
- name: Set outputs
127+
id: set-outputs
128+
run: |
129+
echo "RELEASENAME=${{ env.RELEASENAME }}" >> "$GITHUB_OUTPUT"
130+
echo "UPLOADURL=${{ steps.release.outputs.upload_url }}" >> "$GITHUB_OUTPUT"
131+
132+
upload-artifacts:
133+
needs: release-cli
134+
runs-on: ubuntu-latest
135+
strategy:
136+
matrix:
137+
include:
138+
- goarch: amd64
139+
goos: linux
140+
141+
- goarch: amd64
142+
goos: windows
143+
144+
- goarch: arm64
145+
goos: darwin
146+
147+
- goarch: amd64
148+
goos: darwin
149+
env:
150+
RELEASENAME: ${{ needs.release-cli.outputs.RELEASENAME }}
151+
UPLOADURL: ${{ needs.release-cli.outputs.UPLOADURL }}
152+
OSNAME: ${{matrix.goos == 'darwin' && 'macos' || matrix.goos }}
153+
GOARCH: ${{ matrix.goarch }}
154+
GOOS: ${{ matrix.goos }}
155+
ARCHNAME: ${{ matrix.goarch == 'amd64' && 'x86-64' || matrix.goarch }}
156+
steps:
157+
- name: Set zip filename
158+
run: echo "ZIPFILE=sqlitecloud-go-${{ env.RELEASENAME }}-${{ env.OSNAME }}-${{ env.ARCHNAME }}.zip" >> $GITHUB_ENV
159+
160+
- name: Download artifact
161+
uses: actions/download-artifact@v4
162+
with:
163+
name: ${{ env.ZIPFILE }}
164+
86165
- name: Upload Release Asset
87166
id: upload-release-asset
88167
uses: actions/upload-release-asset@v1
89168
if: matrix.goos != 'darwin'
90169
env:
91170
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
92171
with:
93-
upload_url: ${{ steps.release.outputs.upload_url }}
94-
asset_path: ./GO/${{ env.ZIPFILE }}
172+
upload_url: ${{ env.UPLOADURL }}
173+
asset_path: ./${{ env.ZIPFILE }}
95174
asset_name: ${{ env.ZIPFILE }}
96175
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

.github/workflows/release.yaml renamed to .github/workflows/release-sdk.yaml

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# A tag is a release version on pkg.go.dev, which is
33
# notified with the publishing go command.
44

5-
name: Release
5+
name: Release SDK
66

77
on:
88
workflow_dispatch:
@@ -16,30 +16,35 @@ on:
1616
- major
1717

1818
jobs:
19-
release:
19+
release-sdk:
2020
if: ${{ github.ref == 'refs/heads/main' }}
2121
runs-on: ubuntu-latest
2222
name: Tag for release
2323
steps:
2424
- name: Checkout code
25-
uses: actions/checkout@v2
25+
uses: actions/checkout@v4
2626
with:
27+
# download tags
2728
fetch-depth: 0
29+
2830
- name: Last version
2931
id: last-version
30-
# last tag that starts with 'v', eg: v1.0.3
31-
run: echo "::set-output name=tag::$(git tag --list 'v*' | sort -V | tail -n1)"
32+
# last tag that starts with 'v', eg: v1.0.3 but outputs it as: 1.0.3
33+
run: echo "LASTVERSION=$(git tag --list 'v*' | sort -V | tail -n1 | sed 's/v//')" >> $GITHUB_ENV
34+
3235
- name: Bump version
3336
id: bump-version
3437
uses: olegsu/semver-action@v1
3538
with:
36-
version: ${{ steps.last-version.outputs.tag }}
39+
version: ${{ env.LASTVERSION }}
3740
bump: ${{ inputs.choice }}
41+
3842
- name: Create tag as version for the package
3943
run: |
4044
git config --global user.email "github-actions[bot]@users.noreply.github.com"
4145
git config --global user.name "GitHub Actions"
4246
git tag v${{ steps.bump-version.outputs.version }}
4347
git push origin v${{ steps.bump-version.outputs.version }}
48+
4449
- name: Publish on pkg.go.dev
4550
run: GOPROXY=proxy.golang.org go list -m github.com/sqlitecloud/sqlitecloud-go@v${{ steps.bump-version.outputs.version }}

.github/workflows/testing.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,4 @@ jobs:
4040
uses: codecov/[email protected]
4141
with:
4242
token: ${{ secrets.CODECOV_TOKEN }}
43+
files: ./test/coverage.out

0 commit comments

Comments
 (0)