Skip to content

Commit 9cc615a

Browse files
fix: Add arm64 build and release (runfinch#99)
Signed-off-by: Shubhranshu153 <[email protected]>
1 parent 0e413d7 commit 9cc615a

File tree

3 files changed

+98
-40
lines changed

3 files changed

+98
-40
lines changed

.github/workflows/release-automation.yaml

Lines changed: 67 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,16 @@ jobs:
2222
uses: "WyriHaximus/github-action-get-previous-tag@04e8485ecb6487243907e330d522ff60f02283ce" # v1.4.0
2323
generate-artifacts:
2424
needs: get-latest-tag
25-
runs-on: ubuntu-20.04
25+
runs-on: ${{ matrix.os }}
26+
strategy:
27+
matrix:
28+
os: [ubuntu-20.04]
29+
arch: [amd64, arm64]
2630
env:
27-
# Set during setup.
2831
RELEASE_TAG: ${{ needs.get-latest-tag.outputs.tag }}
2932
DYNAMIC_BINARY_NAME: ''
3033
STATIC_BINARY_NAME: ''
34+
RELEASE_VERSION: ''
3135
steps:
3236
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
3337
with:
@@ -42,68 +46,104 @@ jobs:
4246
run: |
4347
export release_tag=${{ env.RELEASE_TAG }}
4448
export release_version=${release_tag/v/} # Remove v from tag name
45-
echo "DYNAMIC_BINARY_NAME=finch-daemon-${release_version}-linux-amd64.tar.gz" >> $GITHUB_ENV
46-
echo "STATIC_BINARY_NAME=finch-daemon-${release_version}-linux-amd64-static.tar.gz" >> $GITHUB_ENV
47-
49+
echo "DYNAMIC_BINARY_NAME=finch-daemon-${release_version}-linux-${{ matrix.arch }}.tar.gz" >> $GITHUB_ENV
50+
echo "STATIC_BINARY_NAME=finch-daemon-${release_version}-linux-${{ matrix.arch }}-static.tar.gz" >> $GITHUB_ENV
51+
echo "RELEASE_VERSION=${release_version}" >> $GITHUB_ENV
4852
mkdir release
4953
- name: Install Go licenses
5054
run: go install github.com/google/go-licenses@latest
55+
- name: Install Cross Arch dependencies
56+
run: |
57+
if [ "${{ matrix.arch }}" = "arm64" ]; then
58+
sudo apt update
59+
sudo apt install -y gcc-aarch64-linux-gnu g++-aarch64-linux-gnu
60+
fi
5161
- name: Create Third Party Licences File
5262
run: make licenses
53-
- name: setup static dependecies
63+
- name: setup static dependencies
5464
run: |
5565
sudo apt-get update
5666
sudo apt-get install libc6-dev -f
5767
- name: Create release binaries
58-
run: make RELEASE_TAG=${{ env.RELEASE_TAG }} release
59-
- name: Verify Release version
6068
run: |
61-
mkdir -p output/static output/dynamic
62-
tar -xzf release/${{ env.DYNAMIC_BINARY_NAME }} -C ./output/dynamic
63-
tar -xzf release/${{ env.STATIC_BINARY_NAME }} -C ./output/static
64-
DYNAMIC_BINARY_VERSION=$(./output/dynamic/finch-daemon --version | grep -oP '\d+\.\d+\.\d+')
65-
STATIC_BINARY_VERSION=$(./output/static/finch-daemon --version | grep -oP '\d+\.\d+\.\d+')
66-
export release_tag=${{ env.RELEASE_TAG }}
67-
export release_version=${release_tag/v/}
68-
if ["$STATIC_BINARY_VERSION" != "$release_version"] || ["$DYNAMIC_BINARY_VERSION" != "$release_version"]; then
69-
echo "Version mismatch"
70-
exit 1
69+
if [ "${{ matrix.arch }}" = "amd64" ]; then
70+
make TARGET_ARCH=${{ matrix.arch }} RELEASE_TAG=${{ env.RELEASE_TAG }} release
71+
elif [ "${{ matrix.arch }}" = "arm64" ]; then
72+
make CC=aarch64-linux-gnu-gcc TARGET_ARCH=${{ matrix.arch }} RELEASE_TAG=${{ env.RELEASE_TAG }} release
7173
fi
74+
- name: Verify Release version
75+
run: |
76+
export HOST_ARCH=''
77+
case $(uname -m) in
78+
x86_64) HOST_ARCH="amd64" ;;
79+
aarch64) HOST_ARCH="arm64" ;;
80+
*) echo "Error: Unsupported arch $(uname -m)"; exit 1 ;;
81+
esac
82+
echo "Host Arch: $HOST_ARCH"
83+
if [ "${{ matrix.arch }}" = "$HOST_ARCH" ]; then
84+
mkdir -p output/static output/dynamic
85+
tar -xzf release/${{ env.DYNAMIC_BINARY_NAME }} -C ./output/dynamic
86+
tar -xzf release/${{ env.STATIC_BINARY_NAME }} -C ./output/static
87+
DYNAMIC_BINARY_VERSION=$(./output/dynamic/finch-daemon --version | grep -oP '\d+\.\d+\.\d+')
88+
STATIC_BINARY_VERSION=$(./output/static/finch-daemon --version | grep -oP '\d+\.\d+\.\d+')
89+
export release_tag=${{ env.RELEASE_TAG }}
90+
export release_version=${release_tag/v/}
91+
echo "Dynamic version $DYNAMIC_BINARY_VERSION"
92+
else
93+
echo "Architecture mismatch: Cross Arch validation is not supported. Skipping version verification"
94+
fi
7295
shell: bash
7396
- uses: actions/upload-artifact@v4
7497
with:
75-
name: artifacts
98+
name: artifacts-${{ matrix.arch }}
7699
path: release/
77100
if-no-files-found: error
78101
outputs:
79102
release_tag: ${{ env.RELEASE_TAG }}
103+
release_version: ${{ env.RELEASE_VERSION }}
80104
dynamic_binary_name: ${{ env.DYNAMIC_BINARY_NAME }}
81105
static_binary_name: ${{ env.STATIC_BINARY_NAME }}
106+
82107
validate-artifacts:
83108
needs: generate-artifacts
84-
runs-on: ubuntu-latest
109+
runs-on: ${{ matrix.os }}
110+
strategy:
111+
matrix:
112+
os: [ubuntu-latest]
113+
arch: [amd64, arm64]
85114
steps:
86115
- uses: actions/checkout@v4
87116
- uses: actions/download-artifact@v4
88117
with:
89-
name: artifacts
118+
name: artifacts-${{ matrix.arch }}
90119
path: release/
91120
- run: bash scripts/verify-release-artifacts.sh ${{ needs.generate-artifacts.outputs.release_tag }}
121+
env:
122+
TARGET_ARCH: ${{ matrix.arch }}
92123
create-release:
93124
needs: [generate-artifacts, validate-artifacts]
94125
runs-on: ubuntu-latest
95126
steps:
96127
- uses: actions/checkout@v4
97-
- uses: actions/download-artifact@v4
128+
- name: Download Artifact amd64
129+
uses: actions/download-artifact@v4
130+
with:
131+
name: artifacts-amd64
132+
- name: Download Artifact arm64
133+
uses: actions/download-artifact@v4
98134
with:
99-
name: artifacts
135+
name: artifacts-arm64
100136
- uses: softprops/action-gh-release@v2
101137
with:
102138
tag_name: ${{ needs.generate-artifacts.outputs.release_tag }}
103139
prerelease: false
104140
generate_release_notes: false
105141
files: |
106-
${{ needs.generate-artifacts.outputs.dynamic_binary_name }}
107-
${{ needs.generate-artifacts.outputs.dynamic_binary_name }}.sha256sum
108-
${{ needs.generate-artifacts.outputs.static_binary_name }}
109-
${{ needs.generate-artifacts.outputs.static_binary_name }}.sha256sum
142+
finch-daemon-${{ needs.generate-artifacts.outputs.release_version }}-linux-amd64.tar.gz
143+
finch-daemon-${{ needs.generate-artifacts.outputs.release_version }}-linux-amd64.tar.gz.sha256sum
144+
finch-daemon-${{ needs.generate-artifacts.outputs.release_version }}-linux-amd64-static.tar.gz
145+
finch-daemon-${{ needs.generate-artifacts.outputs.release_version }}-linux-amd64-static.tar.gz.sha256sum
146+
finch-daemon-${{ needs.generate-artifacts.outputs.release_version }}-linux-arm64.tar.gz
147+
finch-daemon-${{ needs.generate-artifacts.outputs.release_version }}-linux-arm64.tar.gz.sha256sum
148+
finch-daemon-${{ needs.generate-artifacts.outputs.release_version }}-linux-arm64-static.tar.gz
149+
finch-daemon-${{ needs.generate-artifacts.outputs.release_version }}-linux-arm64-static.tar.gz.sha256sum

scripts/create-releases.sh

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,22 @@ RELEASE_DIR="${FINCH_DAEMON_PROJECT_ROOT}/release"
2929
LICENSE_FILE=${FINCH_DAEMON_PROJECT_ROOT}/THIRD_PARTY_LICENSES
3030
TAG_REGEX="v[0-9]+.[0-9]+.[0-9]+"
3131

32-
ARCH=""
33-
case $(uname -m) in
34-
x86_64) ARCH="amd64" ;;
35-
*) echo "Error: Unsupported arch"; exit 1 ;;
36-
esac
37-
38-
if [ "$#" -ne 1 ]; then
39-
echo "Expected 1 parameter, got $#."
40-
echo "Usage: $0 [release_tag]"
32+
ARCH="${TARGET_ARCH:-}"
33+
34+
if [ -z "$ARCH" ]; then
35+
case $(uname -m) in
36+
x86_64) ARCH="amd64" ;;
37+
aarch64) ARCH="arm64" ;;
38+
*) echo "Error: Unsupported arch $(uname -m)"; exit 1 ;;
39+
esac
40+
fi
41+
42+
echo "Using ARCH: $ARCH"
43+
44+
if [ "$#" -lt 1 ]; then
45+
echo "Expected 1 parameter (release_tag), got $#."
46+
echo "Usage: $0 [architecture] [release_tag]"
47+
echo "Supported architectures: amd64, arm64"
4148
exit 1
4249
fi
4350

@@ -46,30 +53,34 @@ if ! [[ "$1" =~ $TAG_REGEX ]]; then
4653
exit 1
4754
fi
4855

56+
release_version=${1/v/} # Remove v from tag name
57+
shift # Remove the release version argument
58+
4959
if [ -d "$RELEASE_DIR" ]; then
5060
rm -rf "${RELEASE_DIR:?}"/*
5161
else
5262
mkdir "$RELEASE_DIR"
5363
fi
5464

55-
release_version=${1/v/} # Remove v from tag name
5665
dynamic_binary_name=finch-daemon-${release_version}-linux-${ARCH}.tar.gz
5766
static_binary_name=finch-daemon-${release_version}-linux-${ARCH}-static.tar.gz
5867

59-
make build
68+
# Build for the selected architecture
69+
GOARCH=$ARCH make build
6070
cp "$LICENSE_FILE" "${OUT_DIR}"
6171
pushd "$OUT_DIR"
6272
tar -czvf "$RELEASE_DIR"/"$dynamic_binary_name" -- *
6373
popd
6474
rm -rf "{$OUT_DIR:?}"/*
6575

66-
STATIC=1 make build
76+
STATIC=1 GOARCH=$ARCH make build
6777
cp "$LICENSE_FILE" "${OUT_DIR}"
6878
pushd "$OUT_DIR"
6979
tar -czvf "$RELEASE_DIR"/"$static_binary_name" -- *
7080
popd
7181
rm -rf "{$OUT_DIR:?}"/*
7282

83+
# Create checksums
7384
pushd "$RELEASE_DIR"
7485
sha256sum "$dynamic_binary_name" > "$RELEASE_DIR"/"$dynamic_binary_name".sha256sum
7586
sha256sum "$static_binary_name" > "$RELEASE_DIR"/"$static_binary_name".sha256sum

scripts/verify-release-artifacts.sh

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,14 @@ cur_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
2222
dinch_daemon_project_root="$(cd -- "$cur_dir"/.. && pwd)"
2323
release_dir="${dinch_daemon_project_root}/release"
2424

25-
arch="amd64"
25+
arch="${TARGET_ARCH:-}"
26+
if [ -z "$arch" ]; then
27+
case $(uname -m) in
28+
x86_64) arch="amd64" ;;
29+
aarch64) arch="arm64" ;;
30+
*) echo "Error: Unsupported arch $(uname -m)"; exit 1 ;;
31+
esac
32+
fi
2633

2734
function usage {
2835
echo "Usage: $0 <release_tag>"

0 commit comments

Comments
 (0)