-
Notifications
You must be signed in to change notification settings - Fork 23
223 lines (196 loc) · 7.93 KB
/
release.yml
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
name: Release
on:
workflow_dispatch:
inputs:
version:
description: 'Version of zbox to release'
required: true
default: '1.0.0'
tag:
description: 'Tag of zbox to release'
required: true
default: 'v1.0.0'
draft:
description: 'Create release as draft'
required: false
default: 'true'
prerelease:
description: 'Create release as prerelease'
required: false
default: 'false'
env:
GITHUB_TOKEN: ${{ secrets.GOSDK }}
VERSION: ${{ github.event.inputs.version }}
APP_NAME: zbox
GO_VERSION: 1.21
jobs:
create_release:
runs-on: ubuntu-latest
outputs:
release_id: ${{ steps.create_release.outputs.id }}
upload_url: ${{ steps.create_release.outputs.upload_url }}
steps:
- name: Create GitHub Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.event.inputs.tag }}
release_name: ${{ github.event.inputs.tag }}
draft: ${{ github.event.inputs.draft }}
prerelease: ${{ github.event.inputs.prerelease }}
linux:
runs-on: ubuntu-latest
needs: create_release
env:
SRC_DIR: ${{ github.workspace }}/src
OUTPUT_DIR: ${{ github.workspace }}/output
steps:
- name: Checkout code
uses: actions/checkout@v2
with:
path: ${{ env.SRC_DIR }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
with:
platforms: linux/amd64,linux/arm64
- name: Install zip
uses: montudor/action-zip@v1
- name: Setup
run : |
mkdir -p ${{ env.OUTPUT_DIR }}
cp ${{ env.SRC_DIR }}/cmd/config.yaml ${{ env.OUTPUT_DIR }}
- name: Build Docker image for linux/amd64
run: |
docker buildx create --use
docker buildx build \
--platform linux/amd64 \
--build-arg VERSION=${{ env.VERSION }} \
--tag ${{ env.APP_NAME }}-amd64 \
--load \
--output type=docker,dest=${{ env.OUTPUT_DIR }}/${{ env.APP_NAME }}-amd64.tar \
-f ${{ env.SRC_DIR }}/scripts/debian/Dockerfile.build ${{ env.SRC_DIR }}
- name: Load image ${{ env.APP_NAME }}-amd64 & Extract binary ${{ env.APP_NAME }} from container
run: |
docker load -i ${{ env.OUTPUT_DIR }}/${{ env.APP_NAME }}-amd64.tar
CONTAINER_ID=$(docker create ${{ env.APP_NAME }}-amd64)
docker cp ${CONTAINER_ID}:/zbox ${{ env.OUTPUT_DIR }}/${{ env.APP_NAME }}
docker rm ${CONTAINER_ID}
- name: Create Zip File for linux/amd64
run: |
cd ${{ env.OUTPUT_DIR }}
zip -qq -r ${{ env.APP_NAME }}-linux-amd64.zip ${{ env.APP_NAME }} config.yaml
- name: Upload Zip for Darwin/amd64
uses: actions/upload-artifact@v3
with:
name: ${{ env.APP_NAME }}-linux-amd64
path: ${{ env.OUTPUT_DIR }}/${{ env.APP_NAME }}-linux-amd64.zip
- name: Build Docker image for linux/arm64
run: |
docker buildx create --use
docker buildx build \
--platform linux/arm64 \
--build-arg VERSION=${{ env.VERSION }} \
--tag ${{ env.APP_NAME }}-arm64 \
--load \
--output type=docker,dest=${{ env.OUTPUT_DIR }}/${{ env.APP_NAME }}-arm64.tar \
-f ${{ env.SRC_DIR }}/scripts/debian/Dockerfile.build ${{ env.SRC_DIR }}
- name: Load image ${{ env.APP_NAME }}-arm64 & Extract binary from container
run: |
docker load -i ${{ env.OUTPUT_DIR }}/${{ env.APP_NAME }}-arm64.tar
CONTAINER_ID=$(docker create ${{ env.APP_NAME }}-arm64)
docker cp ${CONTAINER_ID}:/zbox ${{ env.OUTPUT_DIR }}/${{ env.APP_NAME }}
docker rm ${CONTAINER_ID}
- name: Create Zip File for linux/arm64
run: |
cd ${{ env.OUTPUT_DIR }}
zip -qq -r ${{ env.APP_NAME }}-linux-arm64.zip ${{ env.APP_NAME }} config.yaml
- name: Upload Zip for Darwin/arm64
uses: actions/upload-artifact@v3
with:
name: ${{ env.APP_NAME }}-linux-arm64
path: ${{ env.OUTPUT_DIR }}/${{ env.APP_NAME }}-linux-arm64.zip
- name: Upload Release Asset for Linux/amd64
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ needs.create_release.outputs.upload_url }}
asset_path: ${{ env.OUTPUT_DIR }}/${{ env.APP_NAME }}-linux-amd64.zip
asset_name: ${{ env.APP_NAME }}-linux-amd64.zip
asset_content_type: application/zip
- name: Upload Release Asset for Linux/arm64
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ needs.create_release.outputs.upload_url }}
asset_path: ${{ env.OUTPUT_DIR }}/${{ env.APP_NAME }}-linux-arm64.zip
asset_name: ${{ env.APP_NAME }}-linux-arm64.zip
asset_content_type: application/zip
darwin:
runs-on: macos-latest
needs: create_release
env:
SRC_DIR: ${{ github.workspace }}/src
OUTPUT_DIR: ${{ github.workspace }}/output
steps:
- name: Checkout code
uses: actions/checkout@v2
with:
path: ${{ env.SRC_DIR }}
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.21'
- name: Setup
run : |
mkdir -p ${{ env.OUTPUT_DIR }}/amd64
mkdir -p ${{ env.OUTPUT_DIR }}/arm64
cp ${{ env.SRC_DIR }}/cmd/config.yaml ${{ env.OUTPUT_DIR }}/amd64/
cp ${{ env.SRC_DIR }}/cmd/config.yaml ${{ env.OUTPUT_DIR }}/arm64/
- name: Build ${{ env.APP_NAME }} for arm64
run: |
cd ${{ env.SRC_DIR }}
CGO_ENABLED=1 CGO_CFLAGS="-mmacosx-version-min=12.0" CGO_LDFLAGS="-mmacosx-version-min=12.0" GOOS=darwin GOARCH=arm64 SDKROOT=$(xcrun --sdk macosx --show-sdk-path) go build -x -v -tags bn256 -ldflags "-X main.VersionStr=v${{ env.VERSION }}" -o ${{ env.OUTPUT_DIR }}/arm64/${{ env.APP_NAME }} .
- name: Build ${{ env.APP_NAME }} for amd64
run: |
cd ${{ env.SRC_DIR }}
CGO_ENABLED=1 CGO_CFLAGS="-mmacosx-version-min=12.0" CGO_LDFLAGS="-mmacosx-version-min=12.0" GOOS=darwin GOARCH=amd64 SDKROOT=$(xcrun --sdk macosx --show-sdk-path) go build -x -v -tags bn256 -ldflags "-X main.VersionStr=v${{ env.VERSION }}" -o ${{ env.OUTPUT_DIR }}/amd64/${{ env.APP_NAME }} .
- name: Create Zip File for darwin/amd64
run: |
cd ${{ env.OUTPUT_DIR }}/amd64
zip -qq -r ${{ env.APP_NAME }}-darwin-amd64.zip ${{ env.APP_NAME }} config.yaml
- name: Upload Zip for Darwin/amd64
uses: actions/upload-artifact@v3
with:
name: ${{ env.APP_NAME }}-darwin-amd64
path: ${{ env.OUTPUT_DIR }}/amd64/${{ env.APP_NAME }}-darwin-amd64.zip
- name: Create Zip File for darwin/arm64
run: |
cd ${{ env.OUTPUT_DIR }}/arm64
zip -qq -r ${{ env.APP_NAME }}-darwin-arm64.zip ${{ env.APP_NAME }} config.yaml
- name: Upload Zip for Darwin/arm64
uses: actions/upload-artifact@v3
with:
name: ${{ env.APP_NAME }}-darwin-arm64
path: ${{ env.OUTPUT_DIR }}/arm64/${{ env.APP_NAME }}-darwin-arm64.zip
- name: Upload Release Asset for Darwin/amd64
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ needs.create_release.outputs.upload_url }}
asset_path: ${{ env.OUTPUT_DIR }}/amd64/${{ env.APP_NAME }}-darwin-amd64.zip
asset_name: ${{ env.APP_NAME }}-darwin-amd64.zip
asset_content_type: application/zip
- name: Upload Release Asset for Darwin/arm64
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ needs.create_release.outputs.upload_url }}
asset_path: ${{ env.OUTPUT_DIR }}/arm64/${{ env.APP_NAME }}-darwin-arm64.zip
asset_name: ${{ env.APP_NAME }}-darwin-arm64.zip
asset_content_type: application/zip