Switch to goreleaser-xx (#291)

Co-authored-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
CrazyMax
2021-03-07 01:19:09 +01:00
committed by GitHub
parent ad7964fd26
commit 456b1f5e5c
3 changed files with 15 additions and 178 deletions

1
.gitignore vendored
View File

@@ -5,5 +5,4 @@
/bin
/dist
/site
/.goreleaser.yml
/coverage.txt

View File

@@ -1,35 +1,34 @@
# syntax=docker/dockerfile:1.2
ARG GO_VERSION=1.15
ARG GORELEASER_VERSION=0.157.0
FROM --platform=$BUILDPLATFORM crazymax/goreleaser-xx:latest AS goreleaser-xx
FROM --platform=$BUILDPLATFORM golang:${GO_VERSION}-alpine AS base
ARG GORELEASER_VERSION
RUN apk add --no-cache ca-certificates curl gcc file git linux-headers musl-dev tar
RUN wget -qO- https://github.com/goreleaser/goreleaser/releases/download/v${GORELEASER_VERSION}/goreleaser_Linux_x86_64.tar.gz | tar -zxvf - goreleaser \
&& mv goreleaser /usr/local/bin/goreleaser
COPY --from=goreleaser-xx / /
RUN apk add --no-cache ca-certificates gcc file git linux-headers musl-dev tar
WORKDIR /src
FROM base AS gomod
RUN --mount=type=bind,target=.,rw \
--mount=type=cache,target=/go/pkg/mod \
go mod tidy && go mod download
FROM gomod AS build
FROM base AS build
ARG TARGETPLATFORM
ARG TARGETOS
ARG TARGETARCH
ARG TARGETVARIANT
ARG GIT_REF
RUN --mount=type=bind,target=/src,rw \
--mount=type=cache,target=/root/.cache/go-build \
--mount=target=/go/pkg/mod,type=cache \
./hack/goreleaser.sh "diun" "/out"
goreleaser-xx --debug \
--name "diun" \
--dist "/out" \
--hooks="go mod tidy" \
--hooks="go mod download" \
--main="./cmd/main.go" \
--ldflags="-s -w -X 'main.version={{.Version}}'" \
--files="CHANGELOG.md" \
--files="LICENSE" \
--files="README.md"
FROM scratch AS artifacts
COPY --from=build /out/*.tar.gz /
COPY --from=build /out/*.zip /
FROM --platform=$TARGETPLATFORM alpine
FROM alpine
LABEL maintainer="CrazyMax"
RUN apk --update --no-cache add \

View File

@@ -1,161 +0,0 @@
#!/usr/bin/env sh
APPNAME=$1
DISTPATH=$2
: ${TARGETPLATFORM=}
: ${TARGETOS=}
: ${TARGETARCH=}
: ${TARGETVARIANT=}
: ${CGO_ENABLED=}
: ${GOARCH=}
: ${GOOS=}
: ${GOARM=}
: ${GOMIPS=}
: ${GOBIN=}
: ${GIT_REF=}
set -eu
usage() {
echo "usage: $0 <appname> <distpath>"
exit 1
}
if [ -z "$APPNAME" ] || [ -z "$DISTPATH" ]; then
usage
fi
if [ -n "$TARGETPLATFORM" ]; then
os="$(echo $TARGETPLATFORM | cut -d"/" -f1)"
arch="$(echo $TARGETPLATFORM | cut -d"/" -f2)"
if [ -n "$os" ] && [ -n "$arch" ]; then
export GOOS="$os"
export GOARCH="$arch"
if [ "$arch" = "arm" ]; then
case "$(echo $TARGETPLATFORM | cut -d"/" -f3)" in
"v5")
export GOARM="5"
;;
"v6")
export GOARM="6"
;;
*)
export GOARM="7"
;;
esac
fi
fi
fi
if [ -n "$TARGETOS" ]; then
export GOOS="$TARGETOS"
fi
if [ -n "$TARGETARCH" ]; then
export GOARCH="$TARGETARCH"
fi
if [ "$TARGETARCH" = "arm" ]; then
if [ -n "$TARGETVARIANT" ]; then
case "$TARGETVARIANT" in
"v5")
export GOARM="5"
;;
"v6")
export GOARM="6"
;;
*)
export GOARM="7"
;;
esac
else
export GOARM="7"
fi
fi
if case $TARGETARCH in "mips"*) true;; *) false;; esac; then
if [ -n "$TARGETVARIANT" ]; then
export GOMIPS="$TARGETVARIANT"
else
export GOMIPS="hardfloat"
fi
fi
if [ "$GOOS" = "wasi" ]; then
export GOOS="js"
fi
if [ -z "$GOBIN" ] && [ -n "$GOPATH" ] && [ -n "$GOARCH" ] && [ -n "$GOOS" ]; then
export PATH=${GOPATH}/bin/${GOOS}_${GOARCH}:${PATH}
fi
cat > ./.goreleaser.yml <<EOL
project_name: ${APPNAME}
dist: ${DISTPATH}
builds:
-
main: ./cmd/main.go
ldflags:
- -s -w -X "main.version={{ .Version }}"
env:
- CGO_ENABLED=0
goos:
- ${GOOS}
goarch:
- ${GOARCH}
goarm:
- ${GOARM}
gomips:
- ${GOMIPS}
hooks:
post:
- cp "{{ .Path }}" /usr/local/bin/${APPNAME}
archives:
-
replacements:
386: i386
amd64: x86_64
format_overrides:
- goos: windows
format: zip
files:
- CHANGELOG.md
- LICENSE
- README.md
release:
disable: true
EOL
gitTag=""
case "$GIT_REF" in
refs/tags/v*)
gitTag="${GIT_REF#refs/tags/}"
export GORELEASER_CURRENT_TAG=$gitTag
;;
*)
if gitTag=$(git tag --points-at HEAD --sort -version:creatordate | head -n 1); then
if [ -z "$gitTag" ]; then
gitTag=$(git describe --tags --abbrev=0)
fi
fi
;;
esac
echo "git tag found: ${gitTag}"
gitDirty="true"
if git describe --exact-match --tags --match "$gitTag" >/dev/null 2>&1; then
gitDirty="false"
fi
echo "git dirty: ${gitDirty}"
flags=""
if [ "$gitDirty" = "true" ]; then
flags="--snapshot"
fi
set -x
/usr/local/bin/goreleaser release $flags