Skip to content
This repository was archived by the owner on Jun 30, 2023. It is now read-only.

Commit

Permalink
scripts: add a script for generating pre-compiled artifacts
Browse files Browse the repository at this point in the history
  • Loading branch information
ericchiang committed Dec 29, 2021
1 parent 4346c64 commit edf4af1
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 0 deletions.
14 changes: 14 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,17 @@ jobs:
run: go build ./...
- name: Test
run: go test ./...
release:
strategy:
matrix:
go-version: [1.17.x]
runs-on: ubuntu-latest
steps:
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go-version }}
- name: Checkout code
uses: actions/checkout@v2
- name: Build Release
run: ./scripts/build-release.sh v0.0.0+test
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bin/
56 changes: 56 additions & 0 deletions scripts/build-release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/bin/bash -e

# A script for building binary releases for various platforms.

if [[ "$0" != "./scripts/build-release.sh" ]]; then
1>&2 echo "Script must be run at root of filesystem"
exit 1
fi

VERSION="$1"

if [[ "$VERSION" != v* ]]; then
1>&2 echo "No version specified as argument"
exit 1
fi

mkdir -p bin
rm -f bin/*.zip
rm -f bin/*.tar.gz

function build {
TEMP_DIR="$( mktemp -d )"
GOOS="$1"
GOARCH="$2"

export CGO_ENABLED=0

BIN_NAME="log4jscanner"
if [[ "$1" == "windows" ]]; then
BIN_NAME="log4jscanner.exe"
fi

GOOS="$GOOS" GOARCH="$GOARCH" go build -o "${TEMP_DIR}/log4jscanner/${BIN_NAME}"

if [[ "$1" == "windows" ]]; then
TARGET="${PWD}/bin/log4jscanner-${VERSION}-${GOOS}-${GOARCH}.zip"
cd "$TEMP_DIR"
zip -r "$TARGET" ./
cd -
else
tar \
--group=root \
--owner=root \
-czvf \
"${PWD}/bin/log4jscanner-${VERSION}-${GOOS}-${GOARCH}.tar.gz" \
-C "$TEMP_DIR" \
"./"
fi
rm -rf "$TEMP_DIR"
}

build darwin amd64
build darwin arm64
build linux amd64
build linux arm64
build windows amd64

0 comments on commit edf4af1

Please sign in to comment.