Skip to content

Commit

Permalink
Multi arch build
Browse files Browse the repository at this point in the history
  • Loading branch information
adamaziz15 committed Nov 9, 2023
1 parent 5b50c9e commit 1f82a7a
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 6 deletions.
21 changes: 15 additions & 6 deletions .github/workflows/build-and-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@ jobs:
build-and-release:
runs-on: ubuntu-latest

strategy:
matrix:
asset:
- path: ./cocli-darwin-arm64
name: cocli-darwin-arm64
- path: ./cocli-linux-arm64
name: cocli-linux-arm64
- path: ./cocli-windows-arm64.exe
name: cocli-windows-arm64.exe

steps:
- name: Checkout code
uses: actions/checkout@v2
Expand All @@ -21,8 +31,7 @@ jobs:

- name: Build CLI
run: |
go build -o cocli main.go
# Add any additional build steps if needed
./cocli_build.sh cocli
- name: Set Tag Name
id: set_tag_name
Expand All @@ -37,13 +46,13 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Upload Release Asset
id: upload-release-asset
- name: Upload Release Assets
id: upload-release-assets
uses: actions/upload-release-asset@v1
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./cocli
asset_name: cocli
asset_path: ${{ matrix.asset.path }}
asset_name: ${{ matrix.asset.name }}
asset_content_type: application/octet-stream
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
26 changes: 26 additions & 0 deletions cocli_build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env bash

package_name=$1
if [[ -z "$package_name" ]]; then
echo "usage: $0 <package-name>"
exit 1
fi

platforms=("darwin/arm64" "linux/arm64" "windows/amd64")

for platform in "${platforms[@]}"
do
platform_split=(${platform//\// })
GOOS=${platform_split[0]}
GOARCH=${platform_split[1]}
output_name=$package_name'-'$GOOS'-'$GOARCH
if [ $GOOS = "windows" ]; then
output_name+='.exe'
fi

env GOOS=$GOOS GOARCH=$GOARCH go build -o $output_name main.go
if [ $? -ne 0 ]; then
echo 'An error has occurred! Aborting the script execution...'
exit 1
fi
done

0 comments on commit 1f82a7a

Please sign in to comment.