-
Notifications
You must be signed in to change notification settings - Fork 66
148 lines (143 loc) · 4.95 KB
/
build.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
name: Build Cube Release
on:
push:
tags:
- "v*" # triggers only if push new tag version, like `0.8.4` or else
jobs:
build:
name: Build Binary
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [windows-latest, macos-latest, ubuntu-latest]
arch: [amd64, '386']
include:
- os: windows-latest
goos: windows
bin: 'cube.exe'
args: -9
strip: true
releaseos: windows
- os: macos-latest
goos: darwin
bin: 'cube'
args: -9
strip: false
releaseos: osx
- os: ubuntu-latest
goos: linux
bin: 'cube'
args: -9
strip: true
releaseos: linux
exclude:
- os: macos-latest
arch: '386'
steps:
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.17
- if: matrix.os == 'ubuntu-latest'
run: sudo apt-get update && sudo apt-get install -y gcc-multilib
- if: matrix.arch == '386'
run: echo "RELEASE=cube${{ github.event.release.tag_name}}-${{ matrix.releaseos}}-32" >> $GITHUB_ENV
- if: matrix.arch == 'amd64'
run: echo "RELEASE=cube${{ github.event.release.tag_name}}-${{ matrix.releaseos}}-64" >> $GITHUB_ENV
- if: matrix.os == 'windows-latest' && matrix.arch == 'amd64'
shell: powershell
run: echo "RELEASE=cube${{ github.event.release.tag_name}}-${{ matrix.releaseos}}-64" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append
- if: matrix.os == 'windows-latest' && matrix.arch == '386'
shell: powershell
run: echo "RELEASE=cube${{ github.event.release.tag_name}}-${{ matrix.releaseos}}-32" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append
- uses: actions/checkout@v2
- name: Build ${{ matrix.goos }}/${{ matrix.arch }}
run: go build -trimpath -ldflags '-w -s' -o ${{ matrix.bin }}
env:
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.arch }}
CGO_ENABLED: 0
- uses: svenstaro/upx-action@v2
with:
args: ${{ matrix.args }}
file: ${{ matrix.bin }}
strip: ${{ matrix.strip }}
- name: Upload to artifacts
uses: actions/upload-artifact@v2
with:
name: ${{ env.RELEASE }}
path: ${{ matrix.bin }}
package:
name: Package Assets
runs-on: ubuntu-latest
needs: build
steps:
- uses: actions/checkout@v2
- uses: actions/download-artifact@v2
with:
path: bin
- name: Set env
run: echo "TAG_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
- name: Package Releases
run: |
echo $TAG_VERSION
mkdir releases;
mv bin/cube-linux-32/cube releases/cube_linux_386
mv bin/cube-linux-64/cube releases/cube_linux_amd64
mv bin/cube-osx-64/cube releases/cube_darwin_amd64
mv bin/cube-windows-32/cube.exe releases/cube_windows_386.exe
mv bin/cube-windows-64/cube.exe releases/cube_windows_amd64.exe
# for RELEASE_DIR in bin/*
# do
# echo "Creating release $RELEASE_DIR"
# for BINARY in $RELEASE_DIR/*
# do
# chmod +x $BINARY;
# cp $BINARY .;
# cp $(basename ${BINARY}) releases/$(basename $RELEASE_DIR);
# rm $BINARY;
# tree
# done
# done
- name: Upload to artifacts
uses: actions/upload-artifact@v2
with:
name: releases
path: releases/
upload:
name: Upload to the Release
runs-on: ubuntu-latest
needs: package
steps:
- uses: actions/download-artifact@v2
with:
name: releases
path: releases/
- name: Create Release
id: create_release
uses: monkeyWie/create-release@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: Release ${{ github.ref }}
draft: false
prerelease: false
- name: Upload Archives to Release
env:
UPLOAD_URL: ${{ steps.create_release.outputs.upload_url }}
API_HEADER: "Accept: application/vnd.github.v3+json"
AUTH_HEADER: "Authorization: token ${{ secrets.GITHUB_TOKEN }}"
run: |
UPLOAD_URL=$(echo -n $UPLOAD_URL | sed s/\{.*//g)
for FILE in releases/*
do
chmod +x $FILE
echo "Uploading ${FILE}";
curl \
-H "${API_HEADER}" \
-H "${AUTH_HEADER}" \
-H "Content-Type: $(file -b --mime-type ${FILE})" \
--data-binary "@${FILE}" \
"${UPLOAD_URL}?name=$(basename ${FILE})";
done