Skip to content
This repository has been archived by the owner on Nov 11, 2020. It is now read-only.

Commit

Permalink
fix: update to the build pack
Browse files Browse the repository at this point in the history
reuse the build pack for pipeline + makefile
  • Loading branch information
jstrachan committed Feb 26, 2020
1 parent 618c6ee commit bed8ff2
Show file tree
Hide file tree
Showing 9 changed files with 161 additions and 75 deletions.
123 changes: 123 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
env:
- GO111MODULE=on
- CGO_ENABLED=0
before:
hooks:
- go mod download

builds:
- id: tp-linux
# Path to main.go file or main package.
# Default is `.`.
main: ./cmd/main.go

# Binary name.
# Can be a path (e.g. `bin/app`) to wrap the binary in a directory.
# Default is the name of the project directory.
binary: tp

# Custom ldflags templates.
# Default is `-s -w -X main.version={{.Version}} -X main.commit={{.ShortCommit}} -X main.date={{.Date}} -X main.builtBy=goreleaser`.
ldflags:
- -X "{{.Env.ROOTPACKAGE}}/pkg/version.Version={{.Env.VERSION}}" -X "{{.Env.ROOTPACKAGE}}/pkg/version.Revision={{.Env.REV}}" -X "{{.Env.ROOTPACKAGE}}/pkg/version.Branch={{.Env.BRANCH}}" -X "{{.Env.ROOTPACKAGE}}/pkg/version.BuildDate={{.Env.BUILDDATE}}" -X "{{.Env.ROOTPACKAGE}}/pkg/version.GoVersion={{.Env.GOVERSION}}"

# GOOS list to build for.
# For more info refer to: https://golang.org/doc/install/source#environment
# Defaults are darwin and linux.
goos:
- linux

# GOARCH to build for.
# For more info refer to: https://golang.org/doc/install/source#environment
# Defaults are 386 and amd64.
goarch:
- amd64

- id: tp-amd64
# Path to main.go file or main package.
# Default is `.`.
main: ./cmd/main.go

# Binary name.
# Can be a path (e.g. `bin/app`) to wrap the binary in a directory.
# Default is the name of the project directory.
binary: tp

# Custom ldflags templates.
# Default is `-s -w -X main.version={{.Version}} -X main.commit={{.ShortCommit}} -X main.date={{.Date}} -X main.builtBy=goreleaser`.
ldflags:
- -X "{{.Env.ROOTPACKAGE}}/pkg/version.Version={{.Env.VERSION}}" -X "{{.Env.ROOTPACKAGE}}/pkg/version.Revision={{.Env.REV}}" -X "{{.Env.ROOTPACKAGE}}/pkg/version.Branch={{.Env.BRANCH}}" -X "{{.Env.ROOTPACKAGE}}/pkg/version.BuildDate={{.Env.BUILDDATE}}" -X "{{.Env.ROOTPACKAGE}}/pkg/version.GoVersion={{.Env.GOVERSION}}"

# GOOS list to build for.
# For more info refer to: https://golang.org/doc/install/source#environment
# Defaults are darwin and linux.
goos:
- darwin

# GOARCH to build for.
# For more info refer to: https://golang.org/doc/install/source#environment
# Defaults are 386 and amd64.
goarch:
- amd64

- id: tp-windows-amd64
# Path to main.go file or main package.
# Default is `.`.
main: ./cmd/main.go

# Binary name.
# Can be a path (e.g. `bin/app`) to wrap the binary in a directory.
# Default is the name of the project directory.
binary: tp

# Custom ldflags templates.
# Default is `-s -w -X main.version={{.Version}} -X main.commit={{.ShortCommit}} -X main.date={{.Date}} -X main.builtBy=goreleaser`.
ldflags:
- -X "{{.Env.ROOTPACKAGE}}/pkg/version.Version={{.Env.VERSION}}" -X "{{.Env.ROOTPACKAGE}}/pkg/version.Revision={{.Env.REV}}" -X "{{.Env.ROOTPACKAGE}}/pkg/version.Branch={{.Env.BRANCH}}" -X "{{.Env.ROOTPACKAGE}}/pkg/version.BuildDate={{.Env.BUILDDATE}}" -X "{{.Env.ROOTPACKAGE}}/pkg/version.GoVersion={{.Env.GOVERSION}}"

# GOOS list to build for.
# For more info refer to: https://golang.org/doc/install/source#environment
# Defaults are darwin and linux.
goos:
- windows

# GOARCH to build for.
# For more info refer to: https://golang.org/doc/install/source#environment
# Defaults are 386 and amd64.
goarch:
- amd64

archives:
- name_template: "{{ .ProjectName }}-{{ .Os }}-{{ .Arch }}"
format_overrides:
- goos: windows
format: zip

checksum:
# You can change the name of the checksums file.
# Default is `{{ .ProjectName }}_{{ .Version }}_checksums.txt`.
name_template: "{{ .ProjectName }}-checksums.txt"

# Algorithm to be used.
# Accepted options are sha256, sha512, sha1, crc32, md5, sha224 and sha384.
# Default is sha256.
algorithm: sha256

changelog:
# set it to true if you wish to skip the changelog generation
skip: true

release:
# If set to true, will not auto-publish the release.
# Default is false.
draft: false

# If set to auto, will mark the release as not ready for production
# in case there is an indicator for this in the tag e.g. v1.0.0-rc1
# If set to true, will mark the release as not ready for production.
# Default is false.
prerelease: false

# You can change the name of the GitHub release.
# Default is `{{.Tag}}`
name_template: "{{.Env.VERSION}}"
85 changes: 11 additions & 74 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@
rwildcard=$(wildcard $1$2) $(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2))

SHELL := /bin/bash
NAME := tp
NAME := helmboot
BUILD_TARGET = build
MAIN_SRC_FILE=cmd/tp/tp.go
MAIN_SRC_FILE=cmd/main.go
GO := GO111MODULE=on go
GO_NOMOD :=GO111MODULE=off go
REV := $(shell git rev-parse --short HEAD 2> /dev/null || echo 'unknown')
ORG := jenkins-x
ORG := jenkins-x-labs
ORG_REPO := $(ORG)/$(NAME)
RELEASE_ORG_REPO := $(ORG_REPO)
ROOT_PACKAGE := github.com/$(ORG_REPO)
GO_VERSION := $(shell $(GO) version | sed -e 's/^[^0-9.]*\([0-9.]*\).*/\1/')
GO_DEPENDENCIES := $(call rwildcard,pkg/,*.go) $(call rwildcard,cmd/tp/,*.go)
GO_DEPENDENCIES := $(call rwildcard,pkg/,*.go) $(call rwildcard,cmd/j,*.go)

BRANCH := $(shell git rev-parse --abbrev-ref HEAD 2> /dev/null || echo 'unknown')
BUILD_DATE := $(shell date +%Y%m%d-%H:%M:%S)
Expand All @@ -22,12 +22,6 @@ CGO_ENABLED = 0
REPORTS_DIR=$(BUILD_TARGET)/reports

GOTEST := $(GO) test
# If available, use gotestsum which provides more comprehensive output
# This is used in the CI builds
ifneq (, $(shell which gotestsum 2> /dev/null))
GOTESTSUM_FORMAT ?= standard-quiet
GOTEST := GO111MODULE=on gotestsum --junitfile $(REPORTS_DIR)/integration.junit.xml --format $(GOTESTSUM_FORMAT) --
endif

# set dev version unless VERSION is explicitly set via environment
VERSION ?= $(shell echo "$$(git for-each-ref refs/tags/ --count=1 --sort=-version:refname --format='%(refname:short)' 2>/dev/null)-dev+$(REV)" | sed 's/^v//')
Expand Down Expand Up @@ -76,7 +70,6 @@ list: ## List all make targets
help:
@grep -h -E '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'

all: build ## Build the binary
full: check ## Build and run the tests
check: build test ## Build and run the tests
get-test-deps: ## Install test dependencies
Expand All @@ -86,7 +79,7 @@ get-test-deps: ## Install test dependencies
print-version: ## Print version
@echo $(VERSION)

build: $(GO_DEPENDENCIES) ## Build tp binary for current OS
build: $(GO_DEPENDENCIES) clean ## Build jx-labs binary for current OS
CGO_ENABLED=$(CGO_ENABLED) $(GO) $(BUILD_TARGET) $(BUILDFLAGS) -o build/$(NAME) $(MAIN_SRC_FILE)

build-all: $(GO_DEPENDENCIES) build make-reports-dir ## Build all files - runtime, all tests etc.
Expand All @@ -101,7 +94,7 @@ tidy-deps: ## Cleans up dependencies
make-reports-dir:
mkdir -p $(REPORTS_DIR)

test: make-reports-dir ## Run tests with the "unit" build tag
test: ## Run tests with the "unit" build tag
KUBECONFIG=/cluster/connections/not/allowed CGO_ENABLED=$(CGO_ENABLED) $(GOTEST) --tags=unit -failfast -short ./... $(TEST_BUILDFLAGS)

test-coverage : make-reports-dir ## Run tests and coverage for all tests with the "unit" build tag
Expand All @@ -113,42 +106,6 @@ test-report: make-reports-dir get-test-deps test-coverage ## Create the test rep
test-report-html: make-reports-dir get-test-deps test-coverage ## Create the test report in HTML format
@gocov convert $(COVER_OUT) | gocov-html > $(REPORTS_DIR)/cover.html && open $(REPORTS_DIR)/cover.html

test-verbose: make-reports-dir ## Run the unit tests in verbose mode
CGO_ENABLED=$(CGO_ENABLED) $(GOTEST) -v $(COVERFLAGS) --tags=unit -failfast ./... $(TEST_BUILDFLAGS)

test-integration: get-test-deps ## Run the integration tests
@CGO_ENABLED=$(CGO_ENABLED) $(GOTEST) -tags=integration -short ./... $(TEST_BUILDFLAGS)

test-integration1: make-reports-dir
@CGO_ENABLED=$(CGO_ENABLED) $(GOTEST) -tags=integration $(COVERFLAGS) -short ./... $(TEST_BUILDFLAGS) -test.v -run $(TEST)

test-integration1-pkg: make-reports-dir
@CGO_ENABLED=$(CGO_ENABLED) $(GOTEST) -tags=integration $(COVERFLAGS) -short $(PKG) -test.v -run $(TEST)

test-rich-integration1: make-reports-dir
@CGO_ENABLED=$(CGO_ENABLED) richgo test -tags=integration $(COVERFLAGS) -short -test.v $(TEST_PACKAGE) $(TEST_BUILDFLAGS) -run $(TEST)

test-integration-report: make-reports-dir get-test-deps test-integration ## Create the integration tests report
@gocov convert $(COVER_OUT) | gocov report

test-integration-report-html: make-reports-dir get-test-deps test-integration
@gocov convert $(COVER_OUT) | gocov-html > $(REPORTS_DIR)/cover.html && open $(REPORTS_DIR)/cover.html

test-slow-integration: make-reports-dir ## Run the any tests without a build tag as well as those that have the "integration" build tag. This target is run during CI.
@CGO_ENABLED=$(CGO_ENABLED) $(GOTEST) -tags=integration $(COVERFLAGS) ./... $(TEST_BUILDFLAGS)

test-slow-integration-report: make-reports-dir get-test-deps test-slow-integration
@gocov convert $(COVER_OUT) | gocov report

test-slow-integration-report-html: make-reports-dir get-test-deps test-slow-integration
@gocov convert $(COVER_OUT) | gocov-html > $(REPORTS_DIR)/cover.html && open $(REPORTS_DIR)/cover.html

test1: get-test-deps make-reports-dir ## Runs single test specified by test name and optional package, eg 'make test1 TEST_PACKAGE=./pkg/gits TEST=TestGitCLI'
CGO_ENABLED=$(CGO_ENABLED) $(GOTEST) $(TEST_BUILDFLAGS) -tags="unit integration" $(TEST_PACKAGE) -run $(TEST)

testbin: get-test-deps make-reports-dir
CGO_ENABLED=$(CGO_ENABLED) $(GOTEST) -c github.com/jenkins-x/tp/pkg/cmd -o build/tp-test $(TEST_BUILDFLAGS)

install: $(GO_DEPENDENCIES) ## Install the binary
GOBIN=${GOPATH}/bin $(GO) install $(BUILDFLAGS) $(MAIN_SRC_FILE)

Expand All @@ -167,25 +124,11 @@ darwin: ## Build for OSX
CGO_ENABLED=$(CGO_ENABLED) GOOS=darwin GOARCH=amd64 $(GO) $(BUILD_TARGET) $(BUILDFLAGS) -o build/darwin/$(NAME) $(MAIN_SRC_FILE)
chmod +x build/darwin/$(NAME)

.PHONY: test-release
test-release: clean build
git fetch --tags
REV=$(REV) BRANCH=$(BRANCH) BUILDDATE=$(BUILD_DATE) GOVERSION=$(GO_VERSION) ROOTPACKAGE=$(ROOT_PACKAGE) VERSION=$(VERSION) goreleaser --config=./.goreleaser.yml --snapshot --skip-publish --rm-dist --skip-validate --debug

.PHONY: release
release: clean build test-slow-integration linux # Release the binary
git fetch origin refs/tags/v$(VERSION)
# Don't create a changelog for the distro
@if [[ -z "${DISTRO}" ]]; then \
./build/linux/tp step changelog --verbose --header-file=docs/dev/changelog-header.md --version=$(VERSION) --rev=$(PULL_BASE_SHA) --output-markdown=changelog.md --update-release=false; \
GITHUB_TOKEN=$(GITHUB_ACCESS_TOKEN) REV=$(REV) BRANCH=$(BRANCH) BUILDDATE=$(BUILD_DATE) GOVERSION=$(GO_VERSION) ROOTPACKAGE=$(ROOT_PACKAGE) VERSION=$(VERSION) goreleaser release --config=.goreleaser.yml --rm-dist --release-notes=./changelog.md --skip-validate; \
else \
GITHUB_TOKEN=$(GITHUB_ACCESS_TOKEN) REV=$(REV) BRANCH=$(BRANCH) BUILDDATE=$(BUILD_DATE) GOVERSION=$(GO_VERSION) ROOTPACKAGE=$(ROOT_PACKAGE) VERSION=$(VERSION) goreleaser release --config=.goreleaser.yml --rm-dist; \
fi

.PHONY: release-distro
release-distro:
@$(MAKE) DISTRO=true release
release: clean build test linux win darwin
#git fetch origin refs/tags/v$(VERSION)
jx step changelog --verbose --header-file=hack/changelog-header.md --version=$(VERSION) --rev=$(PULL_BASE_SHA) --output-markdown=changelog.md --update-release=false
jxl goreleaser --organisation=$(ORG) --revision=$(REV) --branch=$(BRANCH) --build-date=$(BUILD_DATE) --go-version=$(GO_VERSION) --root-package=$(ROOT_PACKAGE) --version=$(VERSION)

.PHONY: clean
clean: ## Clean the generated artifacts
Expand Down Expand Up @@ -216,10 +159,4 @@ lint: ## Lint the code
./hack/generate.sh

.PHONY: all
all: fmt build lint test

.PHONY: gcp
gcp: linux ## Creates a GCP image the code
./build.sh

include Makefile.docker
all: fmt build lint test
6 changes: 6 additions & 0 deletions OWNERS_ALIASES
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
aliases:
- rawlingsj
best-approvers:
- rawlingsj
best-reviewers:
- rawlingsj
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

[![Documentation](https://godoc.org/github.com/jenkins-x-labs/trigger-pipeline?status.svg)](https://pkg.go.dev/mod/github.com/jenkins-x-labs/trigger-pipeline)
[![Go Report Card](https://goreportcard.com/badge/github.com/jenkins-x-labs/trigger-pipeline)](https://goreportcard.com/report/github.com/jenkins-x-labs/trigger-pipeline)
[![Releases](https://img.shields.io/github/release-pre/jenkins-x-labs/trigger-pipeline.svg)](https://github.com/jenkins-x-labs/trigger-pipeline/releases)
[![LICENSE](https://img.shields.io/github/license/jenkins-x-labs/trigger-pipeline.svg)](https://github.com/jenkins-x-labs/trigger-pipeline/blob/master/LICENSE)
[![Slack Status](https://img.shields.io/badge/slack-join_chat-white.svg?logo=slack&style=social)](https://slack.k8s.io/)

This project creates a small stand alone binary and container image for triggering pipelines in remove [Jenkins](https://jenkins.io/) servers.

Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion cmd/tp/tp.go → cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package main
import (
"os"

"github.com/jenkins-x-labs/trigger-pipeline/cmd/tp/app"
"github.com/jenkins-x-labs/trigger-pipeline/cmd/app"
)

// Entrypoint for the command
Expand Down
10 changes: 10 additions & 0 deletions jenkins-x.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
buildPack: go-cli
pipelineConfig:
pipelines:
release:
promote:
steps:
- command: ./promote.sh
dir: /workspace/source
name: promote-release
image: gcr.io/jenkinsxio/builder-go
7 changes: 7 additions & 0 deletions promote.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

echo "promoting the new version ${VERSION} to downstream repositories"

jx step create pr go --name github.com/jenkins-x-labs/trigger-pipeline --version ${VERSION} --build "make build" --repo https://github.com/jenkins-x-labs/jx-labs.git

jx step create pr regex --regex "^(?m)\s+name: tp\s+version: \"(.*)\"$" --version ${VERSION} --files alpha/plugins.yml --repo https://github.com/jenkins-x-labs/jx-labs.git

0 comments on commit bed8ff2

Please sign in to comment.