Skip to content

Commit 1b125b2

Browse files
committed
fix: embed release build in release-please workflow
Move all release build jobs into release-please.yml to work around GitHub Actions limitation where GITHUB_TOKEN doesn't trigger other workflows when creating tags/releases. Jobs added: - build-linux: Cross-compile for Linux amd64/arm64 - build-macos: Build for macOS amd64/arm64 - upload-assets: Create tar.gz archives and upload to release - build-docker: Build and push multi-arch Docker images Release workflow (release.yml) can now be removed or kept for manual tag pushes.
1 parent 1dfa591 commit 1b125b2

File tree

2 files changed

+188
-216
lines changed

2 files changed

+188
-216
lines changed

.github/workflows/release-please.yml

Lines changed: 188 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,17 @@ on:
99
permissions:
1010
contents: write
1111
pull-requests: write
12+
packages: write
13+
14+
env:
15+
GO_VERSION: '1.25'
1216

1317
jobs:
1418
release-please:
1519
runs-on: ubuntu-latest
20+
outputs:
21+
release_created: ${{ steps.release.outputs.release_created }}
22+
tag_name: ${{ steps.release.outputs.tag_name }}
1623
steps:
1724
- uses: googleapis/release-please-action@v4
1825
id: release
@@ -37,14 +44,184 @@ jobs:
3744
if: ${{ steps.release.outputs.release_created }}
3845
run: mage ci
3946

40-
- name: Trigger Release workflow
41-
if: ${{ steps.release.outputs.release_created }}
42-
env:
43-
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
44-
run: |
45-
# Re-push the tag to trigger the Release workflow
46-
# (release-please creates tags via API which doesn't fire push:tags)
47-
TAG="${{ steps.release.outputs.tag_name }}"
48-
git push origin ":refs/tags/$TAG" || true
49-
git tag -f "$TAG"
50-
git push origin "$TAG"
47+
build-linux:
48+
needs: release-please
49+
if: ${{ needs.release-please.outputs.release_created }}
50+
runs-on: ubuntu-latest
51+
strategy:
52+
matrix:
53+
goarch: [amd64, arm64]
54+
55+
steps:
56+
- uses: actions/checkout@v5
57+
58+
- name: Set up Go
59+
uses: actions/setup-go@v6
60+
with:
61+
go-version: ${{ env.GO_VERSION }}
62+
63+
- name: Install cross-compiler for ARM64
64+
if: matrix.goarch == 'arm64'
65+
run: |
66+
sudo apt-get update
67+
sudo apt-get install -y gcc-aarch64-linux-gnu g++-aarch64-linux-gnu
68+
69+
- name: Build Linux ${{ matrix.goarch }}
70+
run: |
71+
if [ "${{ matrix.goarch }}" = "amd64" ]; then
72+
CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build \
73+
-o ore-linux-amd64 \
74+
-ldflags="-s -w -X main.version=${{ needs.release-please.outputs.tag_name }} -X main.buildCommit=${GITHUB_SHA} -X main.buildTime=$(date -u +%Y-%m-%dT%H:%M:%SZ)" \
75+
./cmd/ore
76+
else
77+
CGO_ENABLED=1 CC=aarch64-linux-gnu-gcc GOOS=linux GOARCH=arm64 go build \
78+
-o ore-linux-arm64 \
79+
-ldflags="-s -w -X main.version=${{ needs.release-please.outputs.tag_name }} -X main.buildCommit=${GITHUB_SHA} -X main.buildTime=$(date -u +%Y-%m-%dT%H:%M:%SZ)" \
80+
./cmd/ore
81+
fi
82+
83+
- name: Upload artifact
84+
uses: actions/upload-artifact@v5
85+
with:
86+
name: ore-linux-${{ matrix.goarch }}
87+
path: ore-linux-${{ matrix.goarch }}
88+
retention-days: 1
89+
90+
build-macos:
91+
needs: release-please
92+
if: ${{ needs.release-please.outputs.release_created }}
93+
strategy:
94+
matrix:
95+
include:
96+
- runner: macos-15-intel
97+
goarch: amd64
98+
- runner: macos-15
99+
goarch: arm64
100+
101+
runs-on: ${{ matrix.runner }}
102+
103+
steps:
104+
- uses: actions/checkout@v5
105+
106+
- name: Set up Go
107+
uses: actions/setup-go@v6
108+
with:
109+
go-version: ${{ env.GO_VERSION }}
110+
111+
- name: Build macOS ${{ matrix.goarch }}
112+
run: |
113+
CGO_ENABLED=1 GOOS=darwin GOARCH=${{ matrix.goarch }} go build \
114+
-o ore-darwin-${{ matrix.goarch }} \
115+
-ldflags="-s -w -X main.version=${{ needs.release-please.outputs.tag_name }} -X main.buildCommit=${GITHUB_SHA} -X main.buildTime=$(date -u +%Y-%m-%dT%H:%M:%SZ)" \
116+
./cmd/ore
117+
118+
- name: Upload artifact
119+
uses: actions/upload-artifact@v5
120+
with:
121+
name: ore-darwin-${{ matrix.goarch }}
122+
path: ore-darwin-${{ matrix.goarch }}
123+
retention-days: 1
124+
125+
upload-assets:
126+
needs: [release-please, build-linux, build-macos]
127+
if: ${{ needs.release-please.outputs.release_created }}
128+
runs-on: ubuntu-latest
129+
130+
steps:
131+
- name: Download Linux AMD64
132+
uses: actions/download-artifact@v6
133+
with:
134+
name: ore-linux-amd64
135+
path: dist
136+
137+
- name: Download Linux ARM64
138+
uses: actions/download-artifact@v6
139+
with:
140+
name: ore-linux-arm64
141+
path: dist
142+
143+
- name: Download macOS AMD64
144+
uses: actions/download-artifact@v6
145+
with:
146+
name: ore-darwin-amd64
147+
path: dist
148+
149+
- name: Download macOS ARM64
150+
uses: actions/download-artifact@v6
151+
with:
152+
name: ore-darwin-arm64
153+
path: dist
154+
155+
- name: Create tar.gz archives and checksums
156+
run: |
157+
cd dist
158+
159+
# Create tar.gz archives with go-github-selfupdate compatible naming
160+
for binary in ore-*; do
161+
# Extract OS and arch from filename (ore-{os}-{arch})
162+
os_arch=$(echo $binary | sed 's/ore-//')
163+
os=$(echo $os_arch | cut -d'-' -f1)
164+
arch=$(echo $os_arch | cut -d'-' -f2)
165+
166+
# Create archive with naming: ore_{os}_{arch}.tar.gz
167+
archive_name="ore_${os}_${arch}.tar.gz"
168+
tar -czf "$archive_name" "$binary"
169+
170+
# Generate individual SHA256 checksum for the archive
171+
sha256sum "$archive_name" | cut -d' ' -f1 > "${archive_name}.sha256"
172+
173+
echo "Created $archive_name and ${archive_name}.sha256"
174+
done
175+
176+
# Create checksums.txt for all archives (backward compatibility)
177+
sha256sum ore_*.tar.gz > checksums.txt
178+
179+
echo "=== Contents of dist/ ==="
180+
ls -lh
181+
182+
- name: Upload release assets
183+
uses: softprops/action-gh-release@v2
184+
with:
185+
tag_name: ${{ needs.release-please.outputs.tag_name }}
186+
files: dist/*
187+
188+
build-docker:
189+
needs: [release-please, build-linux]
190+
if: ${{ needs.release-please.outputs.release_created }}
191+
runs-on: ubuntu-latest
192+
193+
steps:
194+
- name: Checkout repository
195+
uses: actions/checkout@v5
196+
197+
- name: Set up Docker Buildx
198+
uses: docker/setup-buildx-action@v3
199+
200+
- name: Log in to Container Registry
201+
uses: docker/login-action@v3
202+
with:
203+
registry: ghcr.io
204+
username: ${{ github.actor }}
205+
password: ${{ secrets.GITHUB_TOKEN }}
206+
207+
- name: Extract metadata
208+
id: meta
209+
uses: docker/metadata-action@v5
210+
with:
211+
images: ghcr.io/${{ github.repository }}
212+
tags: |
213+
type=semver,pattern={{version}},value=${{ needs.release-please.outputs.tag_name }}
214+
type=semver,pattern={{major}}.{{minor}},value=${{ needs.release-please.outputs.tag_name }}
215+
type=semver,pattern={{major}},value=${{ needs.release-please.outputs.tag_name }}
216+
type=sha
217+
218+
- name: Build and push Docker image
219+
uses: docker/build-push-action@v6
220+
with:
221+
context: .
222+
platforms: linux/amd64,linux/arm64
223+
push: true
224+
tags: ${{ steps.meta.outputs.tags }}
225+
labels: ${{ steps.meta.outputs.labels }}
226+
cache-from: type=gha
227+
cache-to: type=gha,mode=max

0 commit comments

Comments
 (0)