-
Notifications
You must be signed in to change notification settings - Fork 0
165 lines (142 loc) · 4.71 KB
/
release-cli.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# 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