Skip to content

Commit 88b7bd6

Browse files
committed
ci: updates github workflow for using go's cross compilation feature
1 parent 9344700 commit 88b7bd6

File tree

1 file changed

+42
-77
lines changed

1 file changed

+42
-77
lines changed

.github/workflows/release.yml

Lines changed: 42 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -23,125 +23,90 @@ permissions:
2323

2424
jobs:
2525
build-binary:
26-
strategy:
27-
fail-fast: true
28-
matrix:
29-
os: [ubuntu-latest, macos-14, macos-13]
30-
arch: [amd64, arm64]
31-
include:
32-
- os: ubuntu-latest
33-
platform: linux
34-
35-
- os: macos-13
36-
platform: darwin
37-
38-
- os: macos-14
39-
platform: darwin
40-
exclude:
41-
- os: macos-14
42-
arch: amd64
43-
- os: macos-13
44-
arch: arm64
45-
46-
name: Building run-${{ matrix.platform }}-${{ matrix.arch }}
47-
runs-on: ${{ matrix.os }}
26+
# strategy:
27+
# fail-fast: true
28+
# matrix:
29+
# runner: ubuntu-latest
30+
# arch:
31+
# - amd64
32+
# - arm64
33+
# os:
34+
# - linux
35+
# - darwin
36+
# - windows
37+
38+
name: Building runfile
39+
runs-on: ubuntu-latest
4840
steps:
4941
- uses: actions/checkout@v4
5042

5143
- uses: nxtcoder17/actions/setup-cache-go@v1
5244
with:
53-
cache_key: "run-${{ matrix.platform }}-${{ matrix.arch }}"
45+
cache_key: "run"
5446
working_directory: .
5547

56-
- uses: nxtcoder17/actions/generate-image-tag@v1
57-
5848
- uses: nxtcoder17/actions/setup-nix-cachix@v1
5949
with:
6050
flake_lock: "./flake.lock"
6151
nix_develop_arguments: ".#default"
6252
cachix_cache_name: ${{ secrets.CACHIX_CACHE_NAME }}
6353
cachix_auth_token: ${{ secrets.CACHIX_AUTH_TOKEN }}
6454

55+
- uses: nxtcoder17/actions/metadata@main
56+
id: meta
57+
6558
- name: Build Binary
6659
shell: bash
6760
env:
6861
CGO_ENABLED: 0
6962
run: |+
70-
binary=bin/run-${{ matrix.platform }}-${{ matrix.arch }}
71-
go build -o $binary -ldflags="-s -w" -tags urfave_cli_no_docs ./cmd/run
63+
arch_list=("amd64" "arm64")
64+
os_list=("linux" "darwin")
7265
73-
if [ "${{ matrix.platform }}" = "linux" ]; then
74-
upx $binary
75-
fi
66+
for os in "${os_list[@]}"; do
67+
for arch in "${arch_list[@]}"; do
68+
echo "🚧 building binary for os=$os arch=$arch"
69+
export GOARCH=$arch
70+
export GOOS=$os
7671
77-
- name: Upload Artifact
78-
uses: actions/upload-artifact@v4
79-
with:
80-
name: run-${{ matrix.platform }}-${{ matrix.arch }}
81-
path: bin/*
82-
83-
release:
84-
needs: build-binary
85-
runs-on: ubuntu-latest
86-
steps:
87-
- name: Download all artifacts
88-
uses: actions/download-artifact@v4
89-
with:
90-
path: ${{ github.workspace }}/binaries
91-
pattern: "run-*"
92-
93-
- name: flattening all the executable artifacts
94-
shell: bash
95-
run: |+
96-
ls -R ${{ github.workspace }}/binaries
97-
mkdir -p ${{ github.workspace }}/upload/binaries
98-
shopt -s globstar
99-
file ./** | grep 'executable,' | awk -F: '{print $1}' | xargs -I {} cp {} ${{ github.workspace }}/upload/binaries
100-
shopt -u globstar
101-
102-
- uses: nxtcoder17/actions/generate-image-tag@v1
72+
binary=bin/run-$GOOS-$GOARCH
73+
go build -o $binary -ldflags="-s -w -X main.Version=${{ steps.meta.outputs.version }}-${{steps.meta.outputs.short_sha}}" -tags urfave_cli_no_docs ./cmd/run
74+
done
75+
done
10376
10477
- name: running for master branch
105-
if: startsWith(github.ref, 'refs/heads/master')
78+
if: startsWith(github.ref, 'refs/heads/')
10679
env:
10780
GH_TOKEN: ${{ github.token }}
81+
version: ${{steps.meta.outputs.version}}
10882
run: |+
109-
echo "running for master branch, will delete nightly release, and recreate in case it exists"
110-
IMAGE_TAG=nightly
111-
echo "IMAGE_TAG=$IMAGE_TAG" | tee -a $GITHUB_ENV | tee -a $GITHUB_OUTPUT
112-
gh release list -R ${{ github.repository }} | grep -i $IMAGE_TAG
113-
exit_code=$?
114-
if [ $exit_code -eq 0 ]; then
115-
gh release delete $IMAGE_TAG -y --cleanup-tag -R ${{ github.repository }}
116-
fi
83+
echo "running for a branch, will delete it's nightly release"
84+
gh release delete ${{steps.meta.outputs.version}} -y --cleanup-tag -R ${{ github.repository }} || echo "cleaned up nightly tag"
11785
11886
- name: ensure github release exists
11987
shell: bash
12088
env:
12189
GH_TOKEN: ${{ github.token }}
90+
version: ${{steps.meta.outputs.version}}
12291
run: |+
123-
set +e
124-
gh release list -R ${{ github.repository }} | grep -i $IMAGE_TAG
125-
exit_code=$?
126-
if [ $exit_code -ne 0 ]; then
127-
gh release create $IMAGE_TAG -R ${{ github.repository }} --generate-notes --prerelease --draft=false
128-
fi
92+
echo "🔖 creating release for tag $version"
93+
gh release create $version -R ${{ github.repository }} --generate-notes --prerelease --draft=false || echo "release ($version) already exists, will use that one"
12994
13095
- name: upload to github release
13196
shell: bash
13297
env:
13398
GH_TOKEN: ${{ github.token }}
99+
version: ${{steps.meta.outputs.version}}
134100
run: |+
135-
extra_args=""
136-
if [ "$IMAGE_TAG" = "nightly" ]; then
137-
extra_args="--clobber"
138-
fi
139-
gh release upload $IMAGE_TAG -R ${{github.repository}} $extra_args ${{github.workspace}}/upload/binaries/*
101+
gh release upload $version -R ${{github.repository}} bin/*
102+
echo "🚀 updated binaries to github release"
140103
141104
- name: mark release as latest
142105
if: startsWith(github.ref, 'refs/tags/')
143106
env:
144107
GH_TOKEN: ${{ github.token }}
108+
version: ${{steps.meta.outputs.version}}
145109
shell: bash
146110
run: |+
147-
gh release edit $IMAGE_TAG -R ${{ github.repository }} --latest
111+
gh release edit $version -R ${{ github.repository }} --latest
112+

0 commit comments

Comments
 (0)