Skip to content

Commit

Permalink
Github action to create release with assets
Browse files Browse the repository at this point in the history
  • Loading branch information
Ajnasz committed Dec 16, 2020
1 parent 849273c commit 20f7ae6
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 58 deletions.
22 changes: 16 additions & 6 deletions .github/workflows/build.yml → .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
name: Build
name: Release

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
tags:
- 'v*'

jobs:
build:
Expand All @@ -31,6 +30,17 @@ jobs:
dep ensure
fi
- name: Build
- name: Test
run: |
./build.sh -o linux -a amd64 -s postgres
./build.sh build
- run: |
set -x
assets=()
for asset in build/*; do
assets+=("-a" "$asset")
done
tag_name="${GITHUB_REF##*/}"
hub release create "${assets[@]}" -m "$tag_name" "$tag_name"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
53 changes: 11 additions & 42 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,45 +1,17 @@
name: Test

on: push
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:

container-job:
name: Test
build:
name: Build
runs-on: ubuntu-latest

# Service containers to run with `container-job`
services:
# Label used to access the service container
redis:
# Docker Hub image
image: redis
# Set health checks to wait until redis has started
options: >-
--health-cmd "redis-cli ping"
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 6379:6379
postgres:
# Docker Hub image
image: postgres
# Provide the password for postgres
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: password
POSTGRES_DB: sekret_link_test
# Set health checks to wait until postgres has started
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432

steps:

- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
Expand All @@ -59,9 +31,6 @@ jobs:
dep ensure
fi
- name: Test
env:
POSTGRES_URL: "postgres://postgres:password@localhost:5432/sekret_link_test?sslmode=disable"
REDIS_URL: "redis://localhost:6379/0"
run: go test -tags test -v .

- name: Build
run: |
./build.sh test
38 changes: 28 additions & 10 deletions build.sh
Original file line number Diff line number Diff line change
@@ -1,49 +1,64 @@
#!/bin/sh

set -eu

build() {
VERSION=$(git describe --tags)
BUILD=$(date +%FT%T%z)
ARCHLIST="$1"
OSLIST="$2"
STORAGE="$3"
echo $VERSION
echo $BUILD
BUILD_DIR="$4"

echo "$VERSION"
echo "$BUILD"

mkdir -p $BUILD_DIR

for os in $OSLIST
do
for arch in $ARCHLIST
do
for storage in $STORAGELIST
do
echo "building $os.$arch.$storage"
GOOS=$os GOARCH=$arch go build -tags $storage -ldflags "-w -s -X main.version=${VERSION} -X main.build=${BUILD}" -o "sekret.link.$os.$arch.$storage"
GOOS="$os" GOARCH="$arch" go build -tags "$storage" -ldflags "-w -s -X main.version=${VERSION} -X main.build=${BUILD}" -o "$BUILD_DIR/sekret.link.$os.$arch.$storage"
done
done
done
}

remove() {
BUILD_DIR="$1"
for os in $OSLIST
do
for arch in $ARCHLIST
do
for storage in $STORAGELIST
do
if [ -f "sekret.link.$os.$arch.$storage" ]
if [ -f "$BUILD_DIR/sekret.link.$os.$arch.$storage" ]
then
echo "removing $os.$arch.$storage"
rm "sekret.link.$os.$arch.$storage"
rm "$BUILD_DIR/sekret.link.$os.$arch.$storage"
fi
done
done
done
}

REMOVE=0
OSLIST="linux darwin freebsd"
OSLIST="linux"
ARCHLIST="amd64 386"
STORAGELIST="postgres redis sqlite"
BUILD_DIR="./build"
STORAGE=""
BUILD=0

if [ $# -lt 1 ];then
echo "Command required, available commands are \"test\" and \"build\"" >&2
exit 1
fi

subcommand="$1"
shift
case "$subcommand" in
Expand All @@ -55,12 +70,12 @@ case "$subcommand" in
BUILD=1;
;;
*)
echo "Invalid command, available commands are \"test\" and \"build\""
echo "Invalid command, available commands are \"test\" and \"build\"" >&2
exit 1
;;
esac

while getopts "tra:o:s:" opt
while getopts "ra:o:s:b:" opt
do
case "$opt" in
"r")
Expand All @@ -75,14 +90,17 @@ do
"s")
STORAGELIST="$OPTARG"
;;
"b")
BUILD_DIR="$OPTARG"
;;
[?])
exit 1
;;
esac
done

if [ $REMOVE -eq 1 ];then
remove
remove "$BUILD_DIR"
else
build "$ARCHLIST" "$OSLIST" "$STORAGE"
build "$ARCHLIST" "$OSLIST" "$STORAGE" "$BUILD_DIR"
fi

0 comments on commit 20f7ae6

Please sign in to comment.