-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add github actions support for building binaries
The bulk of the work for Github Actions happens in build.sh. Additional platforms/architectures need to be specified in that file.
- Loading branch information
Adam Simpson
committed
Jul 8, 2021
1 parent
839ebab
commit f9d2a0b
Showing
2 changed files
with
42 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
name: build releases | ||
|
||
on: | ||
release: | ||
types: [published] | ||
|
||
jobs: | ||
|
||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
|
||
- name: Set up Go | ||
uses: actions/setup-go@v2 | ||
with: | ||
go-version: 1.16 | ||
|
||
- name: build binaries | ||
run: GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }} ./build.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,28 @@ | ||
#!/bin/sh | ||
|
||
GIT_TAG=$(git tag | tail -1); GOOS=darwin GOARCH=arm64 go build -o arm64-macos-sb -a -ldflags="-X 'sb/cmd.AppVersion=$GIT_TAG'" | ||
# GITHUB_EVENT_PATH documented here: | ||
# https://docs.github.com/en/actions/reference/environment-variables#default-environment-variables | ||
GIT_TAG=$(jq .release.tag_name < "${GITHUB_EVENT_PATH}" | sed -e 's/"//g') | ||
UPLOAD_URL=$(jq .release.upload_url < "${GITHUB_EVENT_PATH}" | sed -e 's/"//g' | cut -d "{" -f 1) | ||
RELEASES="arm64-darwin-sb amd64-linux-sb amd64-darwin-sb" | ||
|
||
GIT_TAG=$(git tag | tail -1); GOOS=darwin GOARCH=amd64 go build -o amd64-macos-sb -a -ldflags="-X 'sb/cmd.AppVersion=$GIT_TAG'" | ||
upload_file() { | ||
NAME=$1 | ||
|
||
GIT_TAG=$(git tag | tail -1); GOOS=linux GOARCH=amd64 go build -o amd64-linux-sb -a -ldflags="-X 'sb/cmd.AppVersion=$GIT_TAG'" | ||
zip "${NAME}.zip" "${NAME}" | ||
curl -H "Accept: application/vnd.github.v3+json" \ | ||
-H "Authorization: Bearer ${GITHUB_TOKEN}" \ | ||
-H "Content-Type: application/zip" \ | ||
--data-binary "@${NAME}.zip" \ | ||
"${UPLOAD_URL}?name=${NAME}.zip" | ||
} | ||
|
||
zip arm64-macos-sb.zip arm64-macos-sb | ||
for PLATFORM in ${RELEASES}; do | ||
GOOS=$(echo "${PLATFORM}" | cut -d - -f 2) \ | ||
GOARCH=$(echo "${PLATFORM}" | cut -d - -f 1) \ | ||
go build -o "${PLATFORM}" -a -ldflags="-X 'sb/cmd.AppVersion=${GIT_TAG}'" | ||
|
||
zip amd64-macos-sb.zip amd64-macos-sb | ||
|
||
zip amd64-linux-sb.zip amd64-linux-sb | ||
|
||
rm *-sb | ||
if [ "${UPLOAD_URL}" != null ]; then | ||
upload_file "${PLATFORM}" | ||
fi | ||
done |