Signed-off-by: Chris Crone <christopher.crone@docker.com>
This commit is contained in:
Chris Crone 2020-10-22 11:24:49 +02:00 коммит произвёл Djordje Lukic
Родитель cf8adb1716
Коммит 5ddd6d567e
4 изменённых файлов: 73 добавлений и 43 удалений

50
.github/workflows/release-weekly-build.yml поставляемый
Просмотреть файл

@ -36,7 +36,35 @@ jobs:
./golangci-lint run
build:
name: Cross compile
runs-on: ubuntu-latest
env:
GO111MODULE: "on"
steps:
- name: Set up Go 1.15
uses: actions/setup-go@v1
with:
go-version: 1.15
id: go
- name: Checkout code into the Go module directory
uses: actions/checkout@v2
- name: Unit test
run: make test-unit
- name: Cross compile
run: make TAG_NAME=${{ github.event.inputs.tag }} package-cross
- name: Upload binary artifact
uses: actions/upload-artifact@v2
with:
name: hub-tool-packages
path: ./dist/*
test:
runs-on: ${{ matrix.os }}
needs: [build]
strategy:
matrix:
os: [windows-latest, macos-latest, ubuntu-latest]
@ -59,25 +87,23 @@ jobs:
with:
ref: ${{ github.event.inputs.branch }}
- name: Download binaries
run: make -f builder.Makefile download
- name: Download artifacts
uses: actions/download-artifact@v2
with:
path: dist
- name: Build binary, package and run tests
- name: Extract platform binary
run: mv dist/hub-tool-packages/* dist/ && make -f builder.Makefile ci-extract
- name: Run e2e tests
env:
E2E_HUB_USERNAME: ${{ secrets.E2E_HUB_USERNAME }}
E2E_HUB_TOKEN: ${{ secrets.E2E_HUB_TOKEN }}
run: make TAG_NAME=${{ github.event.inputs.tag }} -f builder.Makefile build test-unit e2e package
- name: Upload binary artifact
if: ${{ github.event.inputs.tag != '' }} # don't push artifacts if no tag is specified
uses: actions/upload-artifact@v2
with:
name: hub-tool-${{ matrix.os }}
path: ./dist/
run: make TAG_NAME=${{ github.event.inputs.tag }} -f builder.Makefile e2e
release:
runs-on: ubuntu-latest
needs: [lint, build]
needs: [lint, build, test]
if: ${{ github.event.inputs.tag != '' }} # don't release if no tag is specified
steps:
- name: Download artifacts

Просмотреть файл

@ -14,17 +14,17 @@
include vars.mk
export DOCKER_BUILDKIT=1
BUILD_ARGS:=--build-arg GO_VERSION=$(GO_VERSION)\
--build-arg ALPINE_VERSION=$(ALPINE_VERSION)\
--build-arg GOLANGCI_LINT_VERSION=$(GOLANGCI_LINT_VERSION) \
--build-arg TAG_NAME=$(GIT_TAG_NAME) \
--build-arg GOTESTSUM_VERSION=$(GOTESTSUM_VERSION) \
--build-arg BINARY_NAME=$(BINARY_NAME) \
--build-arg BINARY=$(BINARY)
BUILD_ARGS:=--build-arg GO_VERSION=$(GO_VERSION) \
--build-arg ALPINE_VERSION=$(ALPINE_VERSION) \
--build-arg GOLANGCI_LINT_VERSION=$(GOLANGCI_LINT_VERSION) \
--build-arg TAG_NAME=$(TAG_NAME) \
--build-arg GOTESTSUM_VERSION=$(GOTESTSUM_VERSION) \
--build-arg BINARY_NAME=$(BINARY_NAME) \
--build-arg BINARY=$(BINARY)
E2E_ENV:=--env E2E_HUB_USERNAME \
--env E2E_HUB_TOKEN \
--env E2E_TEST_NAME
--env E2E_HUB_TOKEN \
--env E2E_TEST_NAME
TMPDIR_WIN_PKG:=$(shell mktemp -d)
@ -34,18 +34,19 @@ all: lint validate build test
.PHONY: build
build: ## Build the tool in a container
docker build $(BUILD_ARGS) . \
--output type=local,dest=./bin \
--platform local \
--target hub
--output type=local,dest=./bin \
--platform local \
--target hub
.PHONY: cross
cross: ## Cross compile the tool binaries in a container
docker build $(BUILD_ARGS) . \
--output type=local,dest=./bin \
--target cross
--output type=local,dest=./bin \
--target cross
.PHONY: package-cross
package-cross: cross ## Package the cross compiled binaries in tarballs for *nix and a zip for Windows
mkdir -p dist
docker build $(BUILD_ARGS) . \
--platform linux/amd64 \
--output type=tar,dest=- \
@ -98,8 +99,8 @@ lint: ## Run the go linter
.PHONY: validate-headers
validate-headers: ## Validate files license header
docker run --rm -v $(CURDIR):/work -w /work \
golang:${GO_VERSION} \
bash -c 'go get -u github.com/kunalkushwaha/ltag && ./scripts/validate/fileheader'
golang:${GO_VERSION} \
bash -c 'go get -u github.com/kunalkushwaha/ltag && ./scripts/validate/fileheader'
.PHONY: validate-go-mod
validate-go-mod: ## Validate go.mod and go.sum are up-to-date

Просмотреть файл

@ -1,31 +1,30 @@
include vars.mk
NULL := /dev/null
NULL:=/dev/null
ifeq ($(COMMIT),)
COMMIT := $(shell git rev-parse --short HEAD 2> $(NULL))
COMMIT:=$(shell git rev-parse HEAD 2> $(NULL))
endif
ifeq ($(TAG_NAME),)
TAG_NAME := $(shell git describe --always --dirty --abbrev=10 2> $(NULL))
TAG_NAME:=$(shell git describe --tags --match "v[0-9]*" 2> $(NULL))
endif
PKG_NAME:=github.com/docker/hub-tool
STATIC_FLAGS:=CGO_ENABLED=0
LDFLAGS:="-s -w \
-X $(PKG_NAME)/internal.GitCommit=$(COMMIT) \
-X $(PKG_NAME)/internal.Version=$(TAG_NAME)"
-X $(PKG_NAME)/internal.GitCommit=$(COMMIT) \
-X $(PKG_NAME)/internal.Version=$(TAG_NAME)"
GO_BUILD:=go build -trimpath -ldflags=$(LDFLAGS)
VARS:=BINARY_NAME=${BINARY_NAME} \
BINARY=${BINARY}
BINARY=${BINARY}
ifneq ($(strip $(E2E_TEST_NAME)),)
RUN_TEST=-test.run $(E2E_TEST_NAME)
RUN_TEST=-test.run $(E2E_TEST_NAME)
endif
TAR_TRANSFORM:=--transform s/packaging/${BINARY_NAME}/ --transform s/bin/${BINARY_NAME}/ --transform s/${PLATFORM_BINARY}/${BINARY_NAME}/
ifneq ($(findstring bsd,$(shell tar --version)),)
TAR_TRANSFORM=-s /packaging/${BINARY_NAME}/ -s /bin/${BINARY_NAME}/ -s /${PLATFORM_BINARY}/${BINARY_NAME}/
TAR_TRANSFORM=-s /packaging/${BINARY_NAME}/ -s /bin/${BINARY_NAME}/ -s /${PLATFORM_BINARY}/${BINARY_NAME}/
endif
TMPDIR_WIN_PKG:=$(shell mktemp -d)
@ -40,7 +39,7 @@ e2e:
.PHONY: test-unit
test-unit:
gotestsum $(shell go list ./... | grep -vE '/e2e')
$(STATIC_FLAGS) gotestsum $(shell go list ./... | grep -vE '/e2e')
cross:
GOOS=linux GOARCH=amd64 $(STATIC_FLAGS) $(GO_BUILD) -o bin/$(BINARY_NAME)_linux_amd64 ./cmd/$(BINARY_NAME)
@ -68,7 +67,11 @@ else
tar -czf dist/$(BINARY_NAME)-$(GOOS)-$(GOARCH).tar.gz $(TAR_TRANSFORM) packaging/LICENSE bin/$(PLATFORM_BINARY)
endif
# For multi-platform (windows,macos,linux) github actions
.PHONY: download
download:
GO111MODULE=on go get gotest.tools/gotestsum@v${GOTESTSUM_VERSION}
.PHONY: ci-extract
ci-extract:
mkdir -p bin
ifeq ($(GOOS),windows)
7z e -obin/ dist/$(BINARY_NAME)-windows-amd64.zip $(BINARY_NAME).exe
else
tar xzf dist/$(BINARY_NAME)-$(GOOS)-$(GOARCH).tar.gz --strip-components 1 --directory bin/ $(BINARY_NAME)/$(BINARY_NAME)
endif

Просмотреть файл

@ -8,7 +8,7 @@ GOOS?=$(shell go env GOOS)
GOARCH?=$(shell go env GOARCH)
BINARY_EXT=
ifeq ($(GOOS),windows)
BINARY_EXT=.exe
BINARY_EXT=.exe
endif
BINARY_NAME=hub-tool
PLATFORM_BINARY:=$(BINARY_NAME)_$(GOOS)_$(GOARCH)$(BINARY_EXT)