-
Notifications
You must be signed in to change notification settings - Fork 23
174 lines (152 loc) · 6.12 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
name: Release
on:
push: # remove push once tested
branches:
- packaging
workflow_dispatch:
inputs:
version:
description: 'Version of zboxcli to release'
required: true
default: '1.0.0'
dry_run:
description: 'Run without making changes'
required: false
default: 'false'
env:
GITHUB_TOKEN: ${{ secrets.GOSDK }}
VERSION: 1.16.0 # take as input from workflow
APP_NAME: zbox
GO_VERSION: 1.21
jobs:
darwin:
runs-on: ubuntu-latest
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: Setup
run : |
mkdir -p ${{ env.OUTPUT_DIR }}
sudo apt-get update
sudo apt-get install -y clang cmake git patch python libssl-dev lzma-dev libxml2-dev xz-utils bzip2 cpio libbz2-dev zlib1g-dev
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: ${{ env.GO_VERSION }}
- name: Set up osxcross
run: |
cd ${{ github.workspace }}
git clone https://github.com/tpoechtrager/osxcross.git
cd osxcross/tarballs
wget https://github.com/phracker/MacOSX-SDKs/releases/download/11.3/MacOSX11.3.sdk.tar.xz
cd ..
export CC=clang
export CXX=clang++
UNATTENDED=yes OSX_VERSION_MIN=10.11 ./build.sh
- name: Cross-compile for Darwin/amd64
env:
OSXCROSS_ROOT: ${{ github.workspace }}/osxcross
PATH: ${{ env.OSXCROSS_ROOT }}/target/bin:${{ env.PATH }}
VERSION: ${{ env.VERSION }}
run: |
cd ${{ env.SRC_DIR }}
echo "Building for Darwin/amd64..."
CGO_ENABLED=1 CC=o64-clang CXX=o64-clang++ GOOS=darwin GOARCH=amd64 go build -x -v -tags bn256 -ldflags "-X main.VersionStr=${VERSION} -linkmode 'external' -extldflags '-static'" -o ${{ env.OUTPUT_DIR }}/${{ env.APP_NAME }} .
echo "Build completed."
- name: Create Zip File for Darwin/amd64
uses: montudor/action-zip@v1
with:
args: zip -r ${{ env.OUTPUT_DIR }}/${{ env.APP_NAME }}-darwin-amd64.zip ${{ env.OUTPUT_DIR }}/${{ env.APP_NAME }}
- name: Upload Zip for Darwin/amd64
uses: actions/upload-artifact@v3
with:
name: ${{ env.APP_NAME }}-darwin-amd64
path: ${{ env.OUTPUT_DIR }}/${{ env.APP_NAME }}-darwin-amd64.zip
- name: Cross-compile for Darwin/arm64
env:
OSXCROSS_ROOT: ${{ github.workspace }}/osxcross
PATH: ${{ env.OSXCROSS_ROOT }}/target/bin:${{ env.PATH }}
VERSION: ${{ env.VERSION }}
run: |
cd ${{ env.SRC_DIR }}
echo "Building for Darwin/arm64..."
CGO_ENABLED=1 CC=o64-clang CXX=o64-clang++ GOOS=darwin GOARCH=arm64 go build -x -v -tags bn256 -ldflags "-X main.VersionStr=${VERSION} -linkmode 'external' -extldflags '-static'" -o ${{ env.OUTPUT_DIR }}/${{ env.APP_NAME }} .
echo "Build completed."
- name: Create Zip File for Darwin/arm64
uses: montudor/action-zip@v1
with:
args: zip -r ${{ env.OUTPUT_DIR }}/${{ env.APP_NAME }}-darwin-arm64.zip ${{ env.OUTPUT_DIR }}/${{ env.APP_NAME }}
- name: Upload Zip
uses: actions/upload-artifact@v3
with:
name: ${{ env.APP_NAME }}-darwin-arm64
path: ${{ env.OUTPUT_DIR }}/${{ env.APP_NAME }}-darwin-arm64.zip
linux:
runs-on: ubuntu-latest
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: 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 from container
run: |
docker load -i ${{ env.APP_NAME }}-amd64.tar
CONTAINER_ID=$(docker create ${{ env.APP_NAME }}-amd64.tar)
docker cp ${CONTAINER_ID}:/${{ env.APP_NAME }} ${{ env.OUTPUT_DIR }}/${{ env.APP_NAME }}
docker rm ${CONTAINER_ID}
- name: Create Zip File for linux/amd64
uses: montudor/action-zip@v1
with:
args: zip -r ${{ env.OUTPUT_DIR }}/${{ env.APP_NAME }}-linux-amd64.zip ${{ env.OUTPUT_DIR }}/${{ env.APP_NAME }}
- 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.APP_NAME }}-arm64.tar
CONTAINER_ID=$(docker create ${{ env.APP_NAME }}-arm64.tar)
docker cp ${CONTAINER_ID}:/${{ env.APP_NAME }} ${{ env.OUTPUT_DIR }}/${{ env.APP_NAME }}
docker rm ${CONTAINER_ID}
- name: Create Zip File for linux/arm64
uses: montudor/action-zip@v1
with:
args: zip -r ${{ env.OUTPUT_DIR }}/${{ env.APP_NAME }}-linux-arm64.zip ${{ env.OUTPUT_DIR }}/${{ env.APP_NAME }}
- 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