-
Notifications
You must be signed in to change notification settings - Fork 12
318 lines (284 loc) · 10.1 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
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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
name: coredns-dnsredir auto build
on:
push:
branches: [ master, dev ]
paths:
- '**.go'
- '**.h'
- '**.c'
- '**.sh'
- '**.yml'
- '**.mod'
pull_request:
branches: [ master ]
workflow_dispatch:
branches: [ master ]
release:
types: [ created ]
jobs:
build-on-linux:
#if: 'false'
name: Build on Linux
runs-on: ubuntu-latest
steps:
- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
go-version: ^1.13
- name: Check out code into the Go module directory
uses: actions/checkout@v2
- name: Get dependencies
run: |
go get -v -t -d ./...
if [ -f Gopkg.toml ]; then
curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
dep ensure
fi
- name: Prepare CoreDNS for dnsredir plugin
run: |
set -eufxo pipefail
whoami
nproc
uname -v
DNSREDIR_DIR=$PWD
REPO_ADDR=$(git remote get-url origin | sed -e 's/^https:\/\///' -e 's/\.git//')
HEAD_COMMIT=$(git describe --dirty --always)
DNSREDIR_TAG=$(curl -sL https://api.github.com/repos/leiless/dnsredir/releases/latest | grep '"tag_name":' | cut -d'"' -f4)
COREDNS_URL=https://github.com/coredns/coredns.git
COREDNS_DIR=coredns
COREDNS_TAG=$(curl -sL https://api.github.com/repos/coredns/coredns/releases/latest | grep '"tag_name":' | cut -d'"' -f4)
git clone --branch $COREDNS_TAG --depth 1 $COREDNS_URL $COREDNS_DIR 2> /dev/null
mkdir -p ~/go/pkg/mod/github.com/leiless
# Link leiless/dnsredir to latest master tree.
ln -s $DNSREDIR_DIR ~/go/pkg/mod/github.com/leiless/dnsredir@$DNSREDIR_TAG
pushd $COREDNS_DIR
sed -i "s|forward:forward|dnsredir:$REPO_ADDR\nforward:forward|g" plugin.cfg
sed -i "s|GITCOMMIT:=|CUSTOM_FLAGS=-X $REPO_ADDR.pluginVersion=$DNSREDIR_TAG -X $REPO_ADDR.pluginHeadCommit=$HEAD_COMMIT\nGITCOMMIT:=|g" Makefile
sed -i 's|$(GITCOMMIT)|$(GITCOMMIT) $(CUSTOM_FLAGS)|g' Makefile
go generate coredns.go
git diff
git status
go get
popd
- name: Debug build ${{ env.GOOS }}-${{ env.GOARCH }}
env:
GOOS: linux
GOARCH: amd64
# Disable code optimization
CGO_CFLAGS: -g -O0 -DDEBUG
CGO_CXXFLAGS: -g -O0 -DDEBUG
run: |
set -eufxo pipefail
COREDNS_DIR=coredns
pushd $COREDNS_DIR
# Temporary fix to the 'missing go.sum entry for module providing package ...' bug
# see: https://github.com/golang/go/issues/44129#issuecomment-806400315
make CGO_ENABLED=1 BUILDOPTS="-mod=mod -race" -j$(nproc)
./coredns -plugins | grep -q dns.dnsredir$
popd
- name: Debug build for release ${{ env.GOOS }}-${{ env.GOARCH }}
if: startsWith(github.ref, 'refs/tags/')
env:
GOOS: linux
GOARCH: amd64
run: |
set -eufxo pipefail
COREDNS_DIR=coredns
pushd $COREDNS_DIR
mkdir bin
mv coredns bin/coredns-dnsredir-$GOOS-$GOARCH-debug
popd
- name: Release build ${{ env.GOOS }}-${{ env.GOARCH }}
if: startsWith(github.ref, 'refs/tags/')
env:
GOOS: linux
GOARCH: amd64
run: |
set -eufxo pipefail
COREDNS_DIR=coredns
pushd $COREDNS_DIR
make BUILDOPTS="-mod=mod" -j$(nproc)
mv coredns bin/coredns-dnsredir-$GOOS-$GOARCH
popd
- name: Release build ${{ env.GOOS }}-${{ env.GOARCH }}
if: startsWith(github.ref, 'refs/tags/')
env:
GOOS: linux
GOARCH: arm64
run: |
set -eufxo pipefail
COREDNS_DIR=coredns
pushd $COREDNS_DIR
make BUILDOPTS="-mod=mod" -j$(nproc)
mv coredns bin/coredns-dnsredir-$GOOS-$GOARCH
popd
- name: Release build ${{ env.GOOS }}-${{ env.GOARCH }}
if: startsWith(github.ref, 'refs/tags/')
env:
GOOS: windows
GOARCH: amd64
run: |
set -eufxo pipefail
COREDNS_DIR=coredns
pushd $COREDNS_DIR
make BUILDOPTS="-mod=mod" -j$(nproc)
mv coredns bin/coredns-dnsredir-$GOOS-$GOARCH.exe
popd
- name: Packaging
if: startsWith(github.ref, 'refs/tags/')
run: |
set -eufxo pipefail
COREDNS_DIR=coredns
pushd $COREDNS_DIR/bin
ls -1 | xargs -I{} bash -c "zip -qr9 {}.zip {} && shasum -a 256 {}.zip > {}.zip.shasum256 && rm {}"
ls -l
popd
- name: Upload files
if: startsWith(github.ref, 'refs/tags/')
uses: softprops/action-gh-release@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
prerelease: true
fail_on_unmatched_files: true
files: |
coredns/bin/*.zip
coredns/bin/*.zip.shasum256
build-on-darwin:
#if: 'false'
name: Build on Darwin
runs-on: macos-latest
steps:
- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
go-version: ^1.13
- name: Check out code into the Go module directory
uses: actions/checkout@v2
- name: Get dependencies
run: |
go get -v -t -d ./...
if [ -f Gopkg.toml ]; then
curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
dep ensure
fi
- name: Hack macOS 10.x to allow arm64 build support
run: |
if [ "$(sw_vers -productVersion | cut -d'.' -f1)" = 10 ]; then
pushd /Library/Developer/CommandLineTools/SDKs
sudo rm MacOSX.sdk
sudo ln -s MacOSX11.1.sdk MacOSX.sdk
sudo rm -rf MacOSX10.15.sdk
ls -l
popd
fi
- name: Prepare CoreDNS for dnsredir plugin
env:
BYPASS_GH_API_RATE_LIMIT: ${{ secrets.BYPASS_GH_API_RATE_LIMIT }}
run: |
set -eufxo pipefail
whoami
sysctl -n hw.model
sysctl -n hw.ncpu
sysctl -n hw.memsize
sysctl -n machdep.cpu.brand_string
sw_vers
uname -v
xcode-select -p
xcodebuild -version
GH_API_CRED=$GITHUB_ACTOR:$BYPASS_GH_API_RATE_LIMIT
DNSREDIR_DIR=$PWD
REPO_ADDR=$(git remote get-url origin | sed -e 's/^https:\/\///' -e 's/\.git//')
HEAD_COMMIT=$(git describe --dirty --always)
# GH#18: Fix macOS GitHub API access rate limit
DNSREDIR_TAG=$(curl -sL -u $GH_API_CRED https://api.github.com/repos/leiless/dnsredir/releases/latest | grep '"tag_name":' | cut -d'"' -f4)
pushd pf
./download-pf-headers.sh
popd
COREDNS_URL=https://github.com/coredns/coredns.git
COREDNS_DIR=coredns
COREDNS_TAG=$(curl -sL -u $GH_API_CRED https://api.github.com/repos/coredns/coredns/releases/latest | grep '"tag_name":' | cut -d'"' -f4)
git clone --branch $COREDNS_TAG --depth 1 $COREDNS_URL $COREDNS_DIR 2> /dev/null
mkdir -p ~/go/pkg/mod/github.com/leiless
# Link leiless/dnsredir to latest master tree.
ln -s $DNSREDIR_DIR ~/go/pkg/mod/github.com/leiless/dnsredir@$DNSREDIR_TAG
# BSD sed sucks!
brew install gnu-sed
pushd $COREDNS_DIR
gsed -i "s|forward:forward|dnsredir:$REPO_ADDR\nforward:forward|g" plugin.cfg
gsed -i "s|GITCOMMIT:=|CUSTOM_FLAGS=-X $REPO_ADDR.pluginVersion=$DNSREDIR_TAG -X $REPO_ADDR.pluginHeadCommit=$HEAD_COMMIT\nGITCOMMIT:=|g" Makefile
gsed -i 's|$(GITCOMMIT)|$(GITCOMMIT) $(CUSTOM_FLAGS)|g' Makefile
go generate coredns.go
git diff
git status
go get
popd
- name: Debug build ${{ env.GOOS }}-${{ env.GOARCH }}
env:
GOOS: darwin
GOARCH: amd64
CGO_CFLAGS: -g -O0 -DDEBUG
CGO_CXXFLAGS: -g -O0 -DDEBUG
run: |
set -eufxo pipefail
COREDNS_DIR=coredns
pushd $COREDNS_DIR
make CGO_ENABLED=1 BUILDOPTS="-race" -j$(sysctl -n hw.ncpu)
./coredns -plugins | grep -q dns.dnsredir$
popd
- name: Debug build for release ${{ env.GOOS }}-${{ env.GOARCH }}
if: startsWith(github.ref, 'refs/tags/')
env:
GOOS: darwin
GOARCH: amd64
run: |
set -eufxo pipefail
COREDNS_DIR=coredns
pushd $COREDNS_DIR
mkdir bin
mv coredns bin/coredns-dnsredir-$GOOS-$GOARCH-debug
popd
- name: Release build ${{ env.GOOS }}-${{ env.GOARCH }}
if: startsWith(github.ref, 'refs/tags/')
env:
GOOS: darwin
GOARCH: amd64
run: |
set -eufxo pipefail
COREDNS_DIR=coredns
pushd $COREDNS_DIR
make CGO_ENABLED=1 -j$(sysctl -n hw.ncpu)
mv coredns bin/coredns-dnsredir-$GOOS-$GOARCH
popd
- name: Release build ${{ env.GOOS }}-${{ env.GOARCH }}
if: startsWith(github.ref, 'refs/tags/')
env:
GOOS: darwin
GOARCH: arm64
run: |
set -eufxo pipefail
COREDNS_DIR=coredns
pushd $COREDNS_DIR
make CGO_ENABLED=1 -j$(sysctl -n hw.ncpu)
mv coredns bin/coredns-dnsredir-$GOOS-$GOARCH
popd
- name: Packaging
if: startsWith(github.ref, 'refs/tags/')
run: |
set -eufxo pipefail
COREDNS_DIR=coredns
pushd $COREDNS_DIR/bin
ls -1 | xargs -I{} bash -c "zip -qr9 {}.zip {} && shasum -a 256 {}.zip > {}.zip.shasum256 && rm {}"
ls -l
popd
- name: Upload files
if: startsWith(github.ref, 'refs/tags/')
uses: softprops/action-gh-release@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
prerelease: true
fail_on_unmatched_files: true
files: |
coredns/bin/*.zip
coredns/bin/*.zip.shasum256