Skip to content

Commit

Permalink
Merge pull request #86 from clcollins/release_pipeline
Browse files Browse the repository at this point in the history
Adds goReleaser for release creation and binary builds
  • Loading branch information
openshift-merge-robot authored May 13, 2021
2 parents cccf0e5 + e31bbea commit 639bd1d
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 10 deletions.
33 changes: 33 additions & 0 deletions .github/workflows/validate_goreleaser.yml
Original file line number Diff line number Diff line change
@@ -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/[email protected]
with:
fetch-depth: 0

- name: Set up Go
uses: actions/[email protected]
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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,7 @@ bin/

# MacOS
.DS_Store

# goReleaser
dist/
bin/
48 changes: 48 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
28 changes: 20 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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} ./...
Expand All @@ -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
Expand Down

0 comments on commit 639bd1d

Please sign in to comment.