diff --git a/.github/workflows/validate_goreleaser.yml b/.github/workflows/validate_goreleaser.yml new file mode 100644 index 00000000..d5b52425 --- /dev/null +++ b/.github/workflows/validate_goreleaser.yml @@ -0,0 +1,33 @@ +# Validate the goReleaser configuration + +name: validate_goreleaser + +on: + push: + branches: + - master + pull_request: + branches: + - master + +jobs: + validate_goreleaser: + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v2.3.3 + with: + fetch-depth: 0 + + - name: Set up Go + uses: actions/setup-go@v2.1.3 + with: + go-version: 1.15.2 + + - name: Download GoReleaser + run: | + curl -sSLf https://github.com/goreleaser/goreleaser/releases/latest/download/goreleaser_Linux_x86_64.tar.gz -o - | tar --extract --gunzip --directory /usr/local/bin goreleaser + - name: Check goreleaser validity + run: | + goreleaser check diff --git a/.gitignore b/.gitignore index 2458929c..2838deeb 100644 --- a/.gitignore +++ b/.gitignore @@ -22,3 +22,7 @@ bin/ # MacOS .DS_Store + +# goReleaser +dist/ +bin/ diff --git a/.goreleaser.yml b/.goreleaser.yml new file mode 100644 index 00000000..78f105de --- /dev/null +++ b/.goreleaser.yml @@ -0,0 +1,48 @@ +# This is an example .goreleaser.yml file with some sane defaults. +# Make sure to check the documentation at http://goreleaser.com +env_files: + github_token: ~/.config/goreleaser/token + +before: + hooks: + # You may remove this if you don't use go modules. + - go mod tidy + # you may remove this if you don't need go generate + # - go generate ./... + +builds: + - env: + - CGO_ENABLED=0 + goos: + - linux + - darwin + goarch: + - amd64 + ldflags: + - -s -w -X 'github.com/openshift/osdctl/cmd.GitCommit={{.ShortCommit}}' + +archives: + - replacements: + darwin: Darwin + linux: Linux + amd64: x86_64 + +checksum: + name_template: 'sha256sum.txt' + algorithm: sha256 + +snapshot: + name_template: "{{ .Tag }}-next" + +changelog: + sort: asc + filters: + exclude: + - '^docs:' + - '^test:' + +release: + github: + owner: "openshift" + name: "osdctl" + prerelease: auto diff --git a/Dockerfile b/Dockerfile index ee7428ee..0bd01128 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,12 +2,12 @@ FROM registry.svc.ci.openshift.org/openshift/release:golang-1.14 WORKDIR /src COPY . . -RUN make build +RUN make ci-build FROM registry.access.redhat.com/ubi8/ubi-minimal:latest LABEL io.openshift.managed.name="osdctl" \ io.openshift.managed.description="OSD related command line utilities" -COPY --from=0 /src/bin/osdctl /bin/osdctl +COPY --from=0 /src/dist/osdctl_linux_amd64/osdctl /bin/osdctl ENTRYPOINT ["bin/osdctl"] diff --git a/Makefile b/Makefile index bcdb1e7b..27a61aa7 100644 --- a/Makefile +++ b/Makefile @@ -1,21 +1,33 @@ -REPOSITORY = $(shell go list -m) -GIT_COMMIT = $(shell git rev-parse --short HEAD) - BUILDFLAGS ?= -LDFLAGS = -ldflags="-X '${REPOSITORY}/cmd.GitCommit=${GIT_COMMIT}'" +GORELEASER_BUILD_ARGS = "--rm-dist" unexport GOFLAGS all: format mod build test -format: vet fmt mockgen docs +format: vet fmt mockgen ci-build docs fmt: @echo "gofmt" @gofmt -w -s . @git diff --exit-code . +.PHONY: download-goreleaser +download-goreleaser: + mkdir -p ./bin && curl -sSLf https://github.com/goreleaser/goreleaser/releases/latest/download/goreleaser_Linux_x86_64.tar.gz -o - | tar --extract --gunzip --directory ./bin goreleaser + +# Need to use --snapshot here because the goReleaser +# requires more git info that is provided in Prow's clone. +# Snapshot allows the build without validation of the +# repository itself +.PHONY: ci-build +ci-build: download-goreleaser + ./bin/goreleaser build $(GORELEASER_BUILD_ARGS) --snapshot + build: - go build ${BUILDFLAGS} ${LDFLAGS} -o ./bin/osdctl main.go + goreleaser build $(GORELEASER_BUILD_ARGS) + +release: + goreleaser release --rm-dist vet: go vet ${BUILDFLAGS} ./... @@ -24,8 +36,8 @@ mod: go mod tidy @git diff --exit-code -- go.mod -docs: build - ./bin/osdctl docs ./docs/command +docs: + ./dist/osdctl_$(shell uname | tr [:upper:] [:lower:])_amd64/osdctl ./docs/command @git diff --exit-code -- ./docs/command/ mockgen: ensure-mockgen