forked from cloudflare/cloudflared
-
Notifications
You must be signed in to change notification settings - Fork 0
127 lines (115 loc) · 4.35 KB
/
BuildAll.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
name: Build-All
on:
schedule:
- cron: '0 0 * * 0'
workflow_dispatch:
push:
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
Build-All:
# The type of runner that the job will run on
runs-on: ubuntu-latest
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
- uses: actions/checkout@v3
- name: Setup Go environment
uses: actions/[email protected]
with:
# Set this option to true if you want the action to always check for the latest available version that satisfies the version spec
go-version: 'stable'
check-latest: true
- name: Checkout new tags to branches
id: checkout-tags
uses: chachako/checkout-tags@v1
with:
base: cloudflare/cloudflared
token: ${{ github.token }}
overwrite: false
- name: Cache Go modules
uses: actions/cache@v3
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Install UPX
uses: crazy-max/ghaction-upx@v3
with:
install-only: true
- name: build cf-go
if: ${{ steps.checkout-tags.outputs.up-to-date }}
run: |
git clone https://github.com/cloudflare/go --depth 1
cd go/src
./make.bash
chmod +x ../bin/go
- name: build all-cloudflared
if: ${{ steps.checkout-tags.outputs.up-to-date }}
run: |
cd /home/runner/work/cloudflared/cloudflared
git clone https://github.com/cloudflare/cloudflared --depth 1
cd cloudflared/cmd/cloudflared
# Get the list of supported architectures
supported_platforms=$(go tool dist list)
# Loop through each platform
for platform in $supported_platforms; do
# Extract GOOS and GOARCH from the platform string
IFS='/' read -ra parts <<< "$platform"
GOOS=${parts[0]}
GOARCH=${parts[1]}
# Build the binary
echo "Building for $GOOS/$GOARCH..."
# Set CGO_ENABLED=1 for iOS and Android platforms
if [ "$GOOS" = "ios" ] || [ "$GOOS" = "android" ]; then
CGO_ENABLED=1
else
CGO_ENABLED=0
fi
# Set GOMIPS=softfloat for MIPS architectures
if [ "$GOARCH" = "mips" ] || [ "$GOARCH" = "mipsle" ]; then
GOMIPS=softfloat
else
GOMIPS=""
fi
GOOS=$GOOS GOARCH=$GOARCH CGO_ENABLED=$CGO_ENABLED GOMIPS=$GOMIPS /home/runner/work/cloudflared/cloudflared/go/bin/go build -a -trimpath -installsuffix cgo -ldflags "-s -w -extldflags \"-static\"" . || {
echo "Warning: Build failed for $GOOS/$GOARCH" >&2
continue
}
# Rename the binary
if [ "$GOOS" = "windows" ]; then
binary_name="cloudflared-$GOOS-$GOARCH.exe"
mv cloudflared.exe "$binary_name"
else
binary_name="cloudflared-$GOOS-$GOARCH"
mv cloudflared "$binary_name"
fi
# Compress the binary using UPX
upx --best "$binary_name" -qq || {
echo "Warning: UPX compression failed for $GOOS/$GOARCH" >&2
continue
}
done
cd /home/runner/work/cloudflared/cloudflared
- uses: actions/upload-artifact@v4
with:
name: cloudflared-all
path: /home/runner/work/cloudflared/cloudflared/cloudflared/cmd/cloudflared/cloudflared-*
compression-level: 0
- name: Get latest tag
id: latest_tag
uses: anothrNick/[email protected]
env:
DEFAULT_BUMP: patch
WITH_V: true
DEFAULT_BRANCH: main
RELEASE_BRANCHES: main
GITHUB_TOKEN: ${{ github.token }}
- name: Release
uses: softprops/action-gh-release@v2
if: steps.latest_tag.outputs.new_tag
with:
make_latest: "true"
tag_name: ${{ steps.latest_tag.outputs.new_tag }}
files: /home/runner/work/cloudflared/cloudflared/cloudflared/cmd/cloudflared/cloudflared-*
token: ${{ github.token }}
fail_on_unmatched_files: false