Skip to content

Commit 4865b81

Browse files
josharianbradfitz
authored andcommitted
[tailscale1.20] .github/workflows: add Tailscale workflows
When cherry-picking this commit, be sure to add additional tailscale.go1.NN branches to build.yml as needed. Co-authored-by: Brad Fitzpatrick <[email protected]> Co-authored-by: Josh Bleecher Snyder <[email protected]> Co-authored-by: David Crawshaw <[email protected]> Co-authored-by: Maisem Ali <[email protected]> Change-Id: Ic5f993914ff91ad072d50eb694b3ab200c3034b3 (cherry picked from commit 9aa6452)
1 parent 1f57025 commit 4865b81

File tree

2 files changed

+217
-0
lines changed

2 files changed

+217
-0
lines changed

.github/workflows/build.yml

Lines changed: 193 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,193 @@
1+
name: Build toolchain
2+
3+
permissions:
4+
contents: write
5+
6+
on:
7+
push:
8+
branches:
9+
- tailscale
10+
- 'tailscale.go1.19'
11+
- 'tailscale.go1.20'
12+
pull_request:
13+
branches:
14+
- '*'
15+
16+
jobs:
17+
test:
18+
runs-on: ubuntu-20.04
19+
steps:
20+
- name: checkout
21+
uses: actions/checkout@v2
22+
- name: test
23+
run: cd src && ./all.bash
24+
25+
linux:
26+
runs-on: ubuntu-20.04
27+
if: github.event_name == 'push'
28+
steps:
29+
- name: checkout
30+
uses: actions/checkout@v2
31+
- name: build
32+
run: cd src && ./make.bash
33+
- name: trim unnecessary bits
34+
run: |
35+
rm -rf pkg/*_*
36+
find . -type d -name 'testdata' -print0 | xargs -0 rm -rf
37+
find . -name '*_test.go' -delete
38+
- name: archive
39+
run: cd .. && tar --exclude-vcs -zcf linux.tar.gz go
40+
- name: save
41+
uses: actions/upload-artifact@v1
42+
with:
43+
name: linux
44+
path: ../linux.tar.gz
45+
46+
darwin:
47+
runs-on: ubuntu-20.04
48+
if: github.event_name == 'push'
49+
steps:
50+
- name: checkout
51+
uses: actions/checkout@v2
52+
- name: build
53+
run: cd src && ./make.bash
54+
env:
55+
GOOS: darwin
56+
- name: trim unnecessary bits
57+
run: |
58+
rm -rf pkg/*_* pkg/tool/linux_amd64 bin/go bin/gofmt
59+
mv bin/darwin_amd64/* bin/
60+
find . -type d -name 'testdata' -print0 | xargs -0 rm -rf
61+
find . -name '*_test.go' -delete
62+
- name: archive
63+
run: cd .. && tar --exclude-vcs -zcf darwin.tar.gz go
64+
- name: save
65+
uses: actions/upload-artifact@v1
66+
with:
67+
name: darwin
68+
path: ../darwin.tar.gz
69+
70+
linux-arm64:
71+
runs-on: ubuntu-20.04
72+
if: github.event_name == 'push'
73+
steps:
74+
- name: checkout
75+
uses: actions/checkout@v2
76+
- name: build
77+
run: cd src && ./make.bash
78+
env:
79+
GOOS: linux
80+
GOARCH: arm64
81+
- name: trim unnecessary bits
82+
run: |
83+
rm -rf pkg/*_* pkg/tool/linux_amd64 bin/go bin/gofmt
84+
mv bin/linux_arm64/* bin/
85+
find . -type d -name 'testdata' -print0 | xargs -0 rm -rf
86+
find . -name '*_test.go' -delete
87+
- name: archive
88+
run: cd .. && tar --exclude-vcs -zcf linux-arm64.tar.gz go
89+
- name: save
90+
uses: actions/upload-artifact@v1
91+
with:
92+
name: linux-arm64
93+
path: ../linux-arm64.tar.gz
94+
95+
96+
darwin-arm64:
97+
runs-on: ubuntu-20.04
98+
if: github.event_name == 'push'
99+
steps:
100+
- name: checkout
101+
uses: actions/checkout@v2
102+
- name: build
103+
run: cd src && ./make.bash
104+
env:
105+
GOOS: darwin
106+
GOARCH: arm64
107+
- name: trim unnecessary bits
108+
run: |
109+
rm -rf pkg/*_* pkg/tool/linux_amd64 bin/go bin/gofmt
110+
mv bin/darwin_arm64/* bin/
111+
find . -type d -name 'testdata' -print0 | xargs -0 rm -rf
112+
find . -name '*_test.go' -delete
113+
- name: archive
114+
run: cd .. && tar --exclude-vcs -zcf darwin-arm64.tar.gz go
115+
- name: save
116+
uses: actions/upload-artifact@v1
117+
with:
118+
name: darwin-arm64
119+
path: ../darwin-arm64.tar.gz
120+
121+
122+
release:
123+
runs-on: ubuntu-20.04
124+
if: github.event_name == 'push'
125+
needs: [test, linux, darwin, darwin-arm64, linux-arm64]
126+
steps:
127+
- name: download linux
128+
uses: actions/download-artifact@v1
129+
with:
130+
name: linux
131+
- name: download darwin
132+
uses: actions/download-artifact@v1
133+
with:
134+
name: darwin
135+
- name: download darwin-arm64
136+
uses: actions/download-artifact@v1
137+
with:
138+
name: darwin-arm64
139+
- name: download linux-arm64
140+
uses: actions/download-artifact@v1
141+
with:
142+
name: linux-arm64
143+
- name: create release
144+
id: create_release
145+
uses: actions/create-release@v1
146+
env:
147+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
148+
with:
149+
# Release name can't be the same as tag name, sigh
150+
tag_name: build-${{ github.sha }}
151+
release_name: ${{ github.sha }}
152+
draft: false
153+
prerelease: true
154+
- name: upload linux tarball
155+
uses: actions/upload-release-asset@v1
156+
env:
157+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
158+
with:
159+
upload_url: ${{ steps.create_release.outputs.upload_url }}
160+
asset_path: linux/linux.tar.gz
161+
asset_name: linux.tar.gz
162+
asset_content_type: application/gzip
163+
- name: upload linux-arm64 tarball
164+
uses: actions/upload-release-asset@v1
165+
env:
166+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
167+
with:
168+
upload_url: ${{ steps.create_release.outputs.upload_url }}
169+
asset_path: linux-arm64/linux-arm64.tar.gz
170+
asset_name: linux-arm64.tar.gz
171+
asset_content_type: application/gzip
172+
- name: upload darwin tarball
173+
uses: actions/upload-release-asset@v1
174+
env:
175+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
176+
with:
177+
upload_url: ${{ steps.create_release.outputs.upload_url }}
178+
asset_path: darwin/darwin.tar.gz
179+
asset_name: darwin.tar.gz
180+
asset_content_type: application/gzip
181+
- name: upload darwin-arm64 tarball
182+
uses: actions/upload-release-asset@v1
183+
env:
184+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
185+
with:
186+
upload_url: ${{ steps.create_release.outputs.upload_url }}
187+
asset_path: darwin-arm64/darwin-arm64.tar.gz
188+
asset_name: darwin-arm64.tar.gz
189+
asset_content_type: application/gzip
190+
- name: checkout
191+
uses: actions/checkout@v2
192+
- name: Delete older builds
193+
run: ./.github/workflows/prune_old_builds.sh "${{ secrets.GITHUB_TOKEN }}"

.github/workflows/prune_old_builds.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/bin/bash
2+
3+
set -euo pipefail
4+
5+
KEEP=10
6+
GITHUB_TOKEN=$1
7+
8+
delete_release() {
9+
release_id=$1
10+
tag_name=$2
11+
set -x
12+
curl -X DELETE --header "Authorization: Bearer $GITHUB_TOKEN" "https://api.github.com/repos/tailscale/go/releases/$release_id"
13+
curl -X DELETE --header "Authorization: Bearer $GITHUB_TOKEN" "https://api.github.com/repos/tailscale/go/git/refs/tags/$tag_name"
14+
set +x
15+
}
16+
17+
curl https://api.github.com/repos/tailscale/go/releases 2>/dev/null |\
18+
jq -r '.[] | "\(.published_at) \(.id) \(.tag_name)"' |\
19+
egrep '[^ ]+ [^ ]+ build-[0-9a-f]{40}' |\
20+
sort |\
21+
head --lines=-${KEEP}|\
22+
while read date release_id tag_name; do
23+
delete_release "$release_id" "$tag_name"
24+
done

0 commit comments

Comments
 (0)