Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 9 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/go.yml
@@ -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
31 changes: 22 additions & 9 deletions build.sh
@@ -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

0 comments on commit f9d2a0b

Please sign in to comment.