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
55name : Release CLI
66
1616 - major
1717
1818jobs :
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
0 commit comments