-
Notifications
You must be signed in to change notification settings - Fork 5
178 lines (174 loc) · 6.24 KB
/
build-tailscale.yaml
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
name: Build smaller Tailscale binary
on:
schedule:
- cron: '30 0/12 * * *'
workflow_dispatch:
env:
SOFTWARE_NAME: "Tailscale"
FILE_NAME: "tailscaled"
REPO: "tailscale/tailscale"
REPO_SMALL: "Admonstrator/glinet-tailscale-updater"
GIT_AUTHOR_NAME: "Admonstator"
jobs:
check-versions:
runs-on: ubuntu-latest
permissions:
contents: read
outputs:
TAG: ${{ steps.tag.outputs.TAG }}
TAG_SMALL: ${{ steps.tag_small.outputs.TAG_SMALL }}
steps:
- name: Get latest ${{ env.SOFTWARE_NAME }} tag
id: tag
run: |
latest_tag=$(
curl -s "https://api.github.com/repos/${{ env.REPO }}/releases" \
| jq -r 'sort_by(.published_at) | last | .tag_name'
)
echo "TAG=$latest_tag" >> "$GITHUB_OUTPUT"
echo "Latest ${{ env.SOFTWARE_NAME }} Tag: $latest_tag"
- name: Get latest ${{ env.SOFTWARE_NAME }} Small tag
id: tag_small
run: |
latest_tag_small=$(
curl -s "https://api.github.com/repos/${{ env.REPO_SMALL }}/releases/latest" \
| grep -oP '"tag_name": "\K(.*)(?=")' || echo ""
)
echo "TAG_SMALL=$latest_tag_small" >> "$GITHUB_OUTPUT"
echo "Latest ${{ env.SOFTWARE_NAME }} Small Tag: $latest_tag_small"
build:
runs-on: ubuntu-latest
permissions:
contents: write
needs: check-versions
if: needs.check-versions.outputs.TAG_SMALL != needs.check-versions.outputs.TAG
env:
TAG: ${{ needs.check-versions.outputs.TAG }}
strategy:
matrix:
go-version: [stable]
os: [linux]
platform:
- arm
- arm64
- mips
- mipsle
- mips64
- mips64le
steps:
- name: Checkout ${{ env.SOFTWARE_NAME }} repository
uses: actions/checkout@v4
with:
repository: ${{ env.REPO }}
ref: ${{ env.TAG }}
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go-version }}
- name: Download Go modules
run: go mod download
- name: Cross-compile
run: |
if [[ "${{ matrix.platform }}" == "mipsle" ]]; then
GOOS=${{ matrix.os }} GOARCH=${{ matrix.platform }} GOMIPS=softfloat ./build_dist.sh \
--extra-small --box \
-o "${{ env.FILE_NAME }}-${{ matrix.os }}-${{ matrix.platform }}" ./cmd/${{ env.FILE_NAME }}
else
GOOS=${{ matrix.os }} GOARCH=${{ matrix.platform }} ./build_dist.sh \
--extra-small --box \
-o "${{ env.FILE_NAME }}-${{ matrix.os }}-${{ matrix.platform }}" ./cmd/${{ env.FILE_NAME }}
fi
- name: Upload built binary
uses: actions/upload-artifact@v4
with:
name: ${{ env.FILE_NAME }}-${{ matrix.os }}-${{ matrix.platform }}
path: ./${{ env.FILE_NAME }}-${{ matrix.os }}-${{ matrix.platform }}
publish:
runs-on: ubuntu-latest
permissions:
contents: write
needs:
- build
- check-versions
if: needs.check-versions.outputs.TAG_SMALL != needs.check-versions.outputs.TAG
env:
TAG: ${{ needs.check-versions.outputs.TAG }}
steps:
- name: Get UPX latest version
id: get-upx-version
run: |
echo "UPX_VERSION=$(
curl -s https://api.github.com/repos/upx/upx/releases/latest \
| jq -r '.tag_name' \
| cut -c 2-
)" >> "$GITHUB_ENV"
- name: Download UPX
run: |
wget -q "https://github.com/upx/upx/releases/latest/download/upx-${{ env.UPX_VERSION }}-amd64_linux.tar.xz"
tar --to-stdout -xf "upx-${{ env.UPX_VERSION }}-amd64_linux.tar.xz" \
"upx-${{ env.UPX_VERSION }}-amd64_linux/upx" > "${PWD}/upx"
chmod -v +x "${PWD}/upx"
- name: Download built binaries
uses: actions/download-artifact@v4
with:
pattern: ${{ env.FILE_NAME }}-*
- name: Moving files
run: |
for dir in "${{ env.FILE_NAME }}-"*; do
mv -v "${dir}" "${dir}.d"
mv -v "${dir}.d/${{ env.FILE_NAME }}-"* .
rmdir -v "${dir}.d"
done
chmod -v +x "${{ env.FILE_NAME }}-"*
- name: Compress Binary with UPX
run: |
for file in "${{ env.FILE_NAME }}-"*; do
if [[ "$file" == *"mips64"* || "$file" == *"mips64le"* ]]; then
echo "Skipping UPX compression for $file due to unsupported format"
else
"${PWD}/upx" --lzma --best --no-progress "$file"
fi
done
- name: Create checksums
run: |
sha256sum "${{ env.FILE_NAME }}-"* > "checksums.txt"
- name: Create version file
run: |
echo "${{ env.TAG }}" > "version.txt"
- name: Checkout ${{ env.SOFTWARE_NAME }} Small repository
uses: actions/checkout@v4
with:
path: tools
repository: ${{ env.REPO_SMALL }}
- name: Create tag in ${{ env.SOFTWARE_NAME }} Small repository
run: |
cd tools
if git rev-parse --quiet --verify "refs/tags/${{ env.TAG }}"; then
echo "Tag already exists"
exit 0
else
echo "Tag does not exist, creating"
git tag "${{ env.TAG }}"
git push --tags
fi
- name: Create Release
if: github.ref == 'refs/tags/${{ env.TAG }}'
uses: ncipollo/release-action@v1
with:
name: Small ${{ env.SOFTWARE_NAME }} ${{ env.TAG }}
tag: ${{ env.TAG }}
token: ${{ secrets.GITHUB_TOKEN }}
draft: false
prerelease: false
artifacts: |
${{ env.FILE_NAME }}-*
checksums.txt
version.txt
body: |
Small ${{ env.SOFTWARE_NAME }} build ${{ env.TAG }}
For a complete changelog go to https://github.com/${{ env.REPO }}/releases/tag/${{ env.TAG }}
This release was created by:
* Building a combined binary of `tailscale` and `tailscaled`
* Using the build option `--extra-small`
* Compressing the binary with UPX
To use both programs, rename `tailscaled-OS-ARCH` to `tailscaled` and create a symbolic (`ln -sv tailscaled tailscale`) link.