From bed8ff26e1642686f10b597f913f29e70abd3c10 Mon Sep 17 00:00:00 2001 From: James Strachan Date: Wed, 26 Feb 2020 14:29:32 +0000 Subject: [PATCH] fix: update to the build pack reuse the build pack for pipeline + makefile --- .goreleaser.yml | 123 ++++++++++++++++++++++ Makefile | 85 ++------------- OWNERS_ALIASES | 6 ++ README.md | 3 + cmd/{tp/app/tp-win.go => app/main-win.go} | 0 cmd/{tp/app/tp.go => app/main.go} | 0 cmd/{tp/tp.go => main.go} | 2 +- jenkins-x.yml | 10 ++ promote.sh | 7 ++ 9 files changed, 161 insertions(+), 75 deletions(-) create mode 100644 .goreleaser.yml create mode 100644 OWNERS_ALIASES rename cmd/{tp/app/tp-win.go => app/main-win.go} (100%) rename cmd/{tp/app/tp.go => app/main.go} (100%) rename cmd/{tp/tp.go => main.go} (71%) create mode 100755 jenkins-x.yml create mode 100755 promote.sh diff --git a/.goreleaser.yml b/.goreleaser.yml new file mode 100644 index 0000000..30185b4 --- /dev/null +++ b/.goreleaser.yml @@ -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}}" \ No newline at end of file diff --git a/Makefile b/Makefile index bef995c..8dd5d7c 100644 --- a/Makefile +++ b/Makefile @@ -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) @@ -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//') @@ -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 @@ -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. @@ -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 @@ -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) @@ -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 @@ -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 \ No newline at end of file diff --git a/OWNERS_ALIASES b/OWNERS_ALIASES new file mode 100644 index 0000000..99b7a9e --- /dev/null +++ b/OWNERS_ALIASES @@ -0,0 +1,6 @@ +aliases: +- rawlingsj +best-approvers: +- rawlingsj +best-reviewers: +- rawlingsj diff --git a/README.md b/README.md index 2b51b99..a463df7 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/cmd/tp/app/tp-win.go b/cmd/app/main-win.go similarity index 100% rename from cmd/tp/app/tp-win.go rename to cmd/app/main-win.go diff --git a/cmd/tp/app/tp.go b/cmd/app/main.go similarity index 100% rename from cmd/tp/app/tp.go rename to cmd/app/main.go diff --git a/cmd/tp/tp.go b/cmd/main.go similarity index 71% rename from cmd/tp/tp.go rename to cmd/main.go index f181424..74b7e2e 100644 --- a/cmd/tp/tp.go +++ b/cmd/main.go @@ -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 diff --git a/jenkins-x.yml b/jenkins-x.yml new file mode 100755 index 0000000..12665cc --- /dev/null +++ b/jenkins-x.yml @@ -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 \ No newline at end of file diff --git a/promote.sh b/promote.sh new file mode 100755 index 0000000..051fc5e --- /dev/null +++ b/promote.sh @@ -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