diff --git a/.github/workflows/build.yml b/.github/workflows/release.yml similarity index 60% rename from .github/workflows/build.yml rename to .github/workflows/release.yml index e5e0032..14f64c5 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/release.yml @@ -1,10 +1,9 @@ -name: Build +name: Release on: push: - branches: [ master ] - pull_request: - branches: [ master ] + tags: + - 'v*' jobs: build: @@ -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 }} diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 340284b..8260e37 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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: @@ -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 diff --git a/build.sh b/build.sh index 62cc9fd..e89c4a8 100755 --- a/build.sh +++ b/build.sh @@ -1,13 +1,20 @@ #!/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 @@ -15,23 +22,24 @@ build() { 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 @@ -39,11 +47,18 @@ remove() { } 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 @@ -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") @@ -75,6 +90,9 @@ do "s") STORAGELIST="$OPTARG" ;; + "b") + BUILD_DIR="$OPTARG" + ;; [?]) exit 1 ;; @@ -82,7 +100,7 @@ do done if [ $REMOVE -eq 1 ];then - remove + remove "$BUILD_DIR" else - build "$ARCHLIST" "$OSLIST" "$STORAGE" + build "$ARCHLIST" "$OSLIST" "$STORAGE" "$BUILD_DIR" fi