-
Notifications
You must be signed in to change notification settings - Fork 0
194 lines (165 loc) · 6.21 KB
/
release-binaries.yml
File metadata and controls
194 lines (165 loc) · 6.21 KB
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
name: Release Binaries
on:
push:
tags:
- "v*"
permissions:
contents: write
packages: write
concurrency:
group: release-binaries-${{ github.ref }}
cancel-in-progress: false
env:
GO_VERSION: "1.22"
REGISTRY_IMAGE: ghcr.io/agentworkforce/relayfile
jobs:
build:
name: Build ${{ matrix.os }}-${{ matrix.arch }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
os: [linux, darwin]
arch: [amd64, arm64]
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Go 1.22
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
cache: true
- name: Cross-compile release binaries
env:
CGO_ENABLED: "0"
GOOS: ${{ matrix.os }}
GOARCH: ${{ matrix.arch }}
run: |
mkdir -p dist
go build -o "dist/relayfile-${GOOS}-${GOARCH}" ./cmd/relayfile
go build -o "dist/relayfile-mount-${GOOS}-${GOARCH}" ./cmd/relayfile-mount
go build -o "dist/relayfile-cli-${GOOS}-${GOARCH}" ./cmd/relayfile-cli
- name: Create tarballs for Homebrew/install.sh
working-directory: dist
run: |
for bin in relayfile relayfile-mount relayfile-cli; do
cp "${bin}-${{ matrix.os }}-${{ matrix.arch }}" "${bin}"
tar -czf "${bin}_${{ matrix.os }}_${{ matrix.arch }}.tar.gz" "${bin}"
rm "${bin}"
done
- name: Generate SHA256 checksums
working-directory: dist
run: |
sha256sum \
"relayfile_${{ matrix.os }}_${{ matrix.arch }}.tar.gz" \
"relayfile-mount_${{ matrix.os }}_${{ matrix.arch }}.tar.gz" \
"relayfile-cli_${{ matrix.os }}_${{ matrix.arch }}.tar.gz" \
"relayfile-${{ matrix.os }}-${{ matrix.arch }}" \
"relayfile-mount-${{ matrix.os }}-${{ matrix.arch }}" \
"relayfile-cli-${{ matrix.os }}-${{ matrix.arch }}" \
> "checksums-${{ matrix.os }}-${{ matrix.arch }}.txt"
- name: Upload build artifacts
uses: actions/upload-artifact@v4
with:
name: release-${{ matrix.os }}-${{ matrix.arch }}
path: |
dist/relayfile_${{ matrix.os }}_${{ matrix.arch }}.tar.gz
dist/relayfile-mount_${{ matrix.os }}_${{ matrix.arch }}.tar.gz
dist/relayfile-cli_${{ matrix.os }}_${{ matrix.arch }}.tar.gz
dist/relayfile-${{ matrix.os }}-${{ matrix.arch }}
dist/relayfile-mount-${{ matrix.os }}-${{ matrix.arch }}
dist/relayfile-cli-${{ matrix.os }}-${{ matrix.arch }}
dist/checksums-${{ matrix.os }}-${{ matrix.arch }}.txt
release:
name: Publish GitHub Release
runs-on: ubuntu-latest
needs: build
steps:
- name: Download release artifacts
uses: actions/download-artifact@v4
with:
path: release-assets
merge-multiple: true
- name: Merge per-platform checksums into checksums.txt
run: |
cat release-assets/checksums-*.txt > release-assets/checksums.txt
rm release-assets/checksums-*.txt
- name: Show release assets
run: ls -lah release-assets
- name: Upload to GitHub Release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ github.ref_name }}
files: release-assets/*
generate_release_notes: true
update-homebrew:
name: Update Homebrew Formula
runs-on: ubuntu-latest
needs: release
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: main
- name: Download release artifacts
uses: actions/download-artifact@v4
with:
path: release-assets
merge-multiple: true
- name: Update Formula/relayfile.rb
run: |
VERSION="${GITHUB_REF_NAME#v}"
DARWIN_ARM64_SHA=$(sha256sum release-assets/relayfile-cli_darwin_arm64.tar.gz | awk '{print $1}')
DARWIN_AMD64_SHA=$(sha256sum release-assets/relayfile-cli_darwin_amd64.tar.gz | awk '{print $1}')
LINUX_ARM64_SHA=$(sha256sum release-assets/relayfile-cli_linux_arm64.tar.gz | awk '{print $1}')
LINUX_AMD64_SHA=$(sha256sum release-assets/relayfile-cli_linux_amd64.tar.gz | awk '{print $1}')
sed -i 's/version ".*"/version "'"${VERSION}"'"/' Formula/relayfile.rb
export DARWIN_ARM64_SHA DARWIN_AMD64_SHA LINUX_ARM64_SHA LINUX_AMD64_SHA
python3 << 'PYEOF'
import re, os
sha_map = {
"darwin_arm64": os.environ["DARWIN_ARM64_SHA"],
"darwin_amd64": os.environ["DARWIN_AMD64_SHA"],
"linux_arm64": os.environ["LINUX_ARM64_SHA"],
"linux_amd64": os.environ["LINUX_AMD64_SHA"],
}
with open("Formula/relayfile.rb") as f:
content = f.read()
for key, sha in sha_map.items():
pattern = r'(url ".*' + key + r'.*"\n\s+sha256 )"[^"]*"'
content = re.sub(pattern, r'\1"' + sha + '"', content)
with open("Formula/relayfile.rb", "w") as f:
f.write(content)
PYEOF
- name: Commit and push formula update
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add Formula/relayfile.rb
git commit -m "chore: update Homebrew formula for ${GITHUB_REF_NAME}"
git push
docker:
name: Build and Push Docker Image
runs-on: ubuntu-latest
needs: release
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
context: .
file: ./Dockerfile
platforms: linux/amd64,linux/arm64
push: true
tags: |
${{ env.REGISTRY_IMAGE }}:latest
${{ env.REGISTRY_IMAGE }}:${{ github.ref_name }}