Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: fix release action #33

Merged
merged 4 commits into from
Feb 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/go-checks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ jobs:
uses: actions/cache@v3
with:
path: |
bin/gomodcache
bin/gocache
.go/gomodcache
.go/gocache
key: ${{ runner.os }}-gobuildcontainer-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-gobuildcontainer-
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/release-binary.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ jobs:
uses: actions/cache@v3
with:
path: |
bin/gomodcache
bin/gocache
.go/gomodcache
.go/gocache
key: ${{ runner.os }}-gobuildcontainer-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-gobuildcontainer-
Expand All @@ -46,7 +46,7 @@ jobs:
echo ::set-output name=VERSION::${VERSION}

- name: Build Binaries for All Platforms
run: make trigger-all-build
run: make trigger-all-package

- name: Attach Binaries to Release
uses: softprops/action-gh-release@v1
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/release-image.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ jobs:
uses: actions/cache@v3
with:
path: |
bin/gomodcache
bin/gocache
.go/gomodcache
.go/gocache
key: ${{ runner.os }}-gobuildcontainer-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-gobuildcontainer-
Expand Down Expand Up @@ -69,8 +69,8 @@ jobs:
uses: actions/cache@v3
with:
path: |
bin/gomodcache
bin/gocache
.go/gomodcache
.go/gocache
key: ${{ runner.os }}-gobuildcontainer-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-gobuildcontainer-
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/upload-test-binary.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ jobs:
uses: actions/cache@v3
with:
path: |
bin/gomodcache
bin/gocache
.go/gomodcache
.go/gocache
key: ${{ runner.os }}-gobuildcontainer-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-gobuildcontainer-
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ cscope.*

# Build output
bin
.go

# etcd
default.etcd
Expand Down
9 changes: 6 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ $(foreach p,$(SUBPROJS),$(eval \
$(p)-%: mk-%.$(p); \
))

# Common targets for subprojects
# Common targets for subprojects, will be executed on all subprojects
TARGETS := build \
all-build \
package \
Expand All @@ -42,18 +42,21 @@ TARGETS := build \
container-push \
all-container-build-push \
clean \
cleanall \
all-clean \
version \
imageversion \
binaryname \
variables \
help

# Targets to run on all subprojects
# Run common targets on all subprojects
$(foreach t,$(TARGETS),$(eval \
$(t): $(addprefix mk-$(t).,$(SUBPROJS)); \
))

# `shell' only needs to be executed once, not on every subproject
shell: $(addprefix mk-shell.,$(word 1,$(SUBPROJS)));

mk-%:
$(MAKE) -f $(lastword $(subst ., ,$*)).mk $(firstword $(subst ., ,$*))

Expand Down
4 changes: 3 additions & 1 deletion makefiles/consts.mk
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,10 @@ ifeq ($(OS), windows)
PKG_FULLNAME := $(subst .exe,,$(if $(FULL_NAME),$(BIN_VERBOSE_BASE),$(BIN_BASENAME))).zip
endif

# This holds build output, cache, and helper tools
# This holds build output and helper tools
DIST := bin
# This holds build cache
GOCACHE := .go
BIN_VERBOSE_DIR := $(DIST)/$(BIN)-$(VERSION)
# Full output path
OUTPUT := $(if $(FULL_NAME),$(BIN_VERBOSE_DIR)/$(BIN_FULLNAME),$(DIST)/$(BIN_FULLNAME))
104 changes: 64 additions & 40 deletions makefiles/targets.mk
Original file line number Diff line number Diff line change
Expand Up @@ -14,34 +14,34 @@

all: build

# Build cache of the build container
BUILDCACHE ?= $$(pwd)/$(DIST)

# ===== BUILD =====

build-dirs:
mkdir -p "$(GOCACHE)/gocache" \
"$(GOCACHE)/gomodcache" \
"$(DIST)"

build: # @HELP build binary for current platform
build: gen-dockerignore
mkdir -p "$(BUILDCACHE)/gocache" "$(BUILDCACHE)/gomodcache" && \
docker run \
-i \
--rm \
-u $$(id -u):$$(id -g) \
-v $$(pwd):/src \
-w /src \
-v $(BUILDCACHE)/gocache:/gocache \
-v $(BUILDCACHE)/gomodcache:/gomodcache \
--env GOCACHE="/gocache" \
--env GOMODCACHE="/gomodcache" \
--env ARCH="$(ARCH)" \
--env OS="$(OS)" \
--env VERSION="$(VERSION)" \
--env DEBUG="$(DEBUG)" \
--env OUTPUT="$(OUTPUT)" \
--env GOFLAGS="$(GOFLAGS)" \
--env GOPROXY="$(GOPROXY)" \
--env HTTP_PROXY="$(HTTP_PROXY)" \
--env HTTPS_PROXY="$(HTTPS_PROXY)" \
$(BUILD_IMAGE) \
build: gen-dockerignore build-dirs
docker run \
-i \
--rm \
-u $$(id -u):$$(id -g) \
-v $$(pwd):/src \
-w /src \
-v $$(pwd)/$(GOCACHE):/cache \
--env GOCACHE="/cache/gocache" \
--env GOMODCACHE="/cache/gomodcache" \
--env ARCH="$(ARCH)" \
--env OS="$(OS)" \
--env VERSION="$(VERSION)" \
--env DEBUG="$(DEBUG)" \
--env OUTPUT="$(OUTPUT)" \
--env GOFLAGS="$(GOFLAGS)" \
--env GOPROXY="$(GOPROXY)" \
--env HTTP_PROXY="$(HTTP_PROXY)" \
--env HTTPS_PROXY="$(HTTPS_PROXY)" \
$(BUILD_IMAGE) \
./build/build.sh $(ENTRY)

# INTERNAL: build-<os>_<arch> to build for a specific platform
Expand Down Expand Up @@ -92,27 +92,22 @@ all-package: $(addprefix package-, $(subst /,_, $(BIN_PLATFORMS)))
# ===== CONTAINERS =====

container-build: # @HELP build container image for current platform
container-build: build-$(OS)_$(ARCH)
printf "# CONTAINER repotags: %s\ttarget: %s/%s\tbinaryversion: %s\n" "$(IMAGE_REPO_TAGS)" "$(OS)" "$(ARCH)" "$(VERSION)"
container-build: build-linux_$(ARCH)
printf "# CONTAINER repotags: %s\ttarget: %s/%s\tbinaryversion: %s\n" "$(IMAGE_REPO_TAGS)" "linux" "$(ARCH)" "$(VERSION)"
if [ "$(OS)" != "linux" ]; then \
echo "# CONTAINER warning: you have set target os to $(OS), but container target os will always be linux"; \
fi; \
TMPFILE=Dockerfile && \
sed 's/$${BIN}/$(BIN)/g' Dockerfile.in > $${TMPFILE} && \
DOCKER_BUILDKIT=1 \
docker build \
-f $${TMPFILE} \
--build-arg "ARCH=$(ARCH)" \
--build-arg "OS=$(OS)" \
--build-arg "OS=linux" \
--build-arg "VERSION=$(VERSION)" \
--build-arg "BASE_IMAGE=$(BASE_IMAGE)" \
$(addprefix -t ,$(IMAGE_REPO_TAGS)) .

# INTERNAL: container-build-<os>_<arch> to build container image for a specific platform
container-build-%:
$(MAKE) -f $(firstword $(MAKEFILE_LIST)) \
docker-build \
--no-print-directory \
GOOS=$(firstword $(subst _, ,$*)) \
GOARCH=$(lastword $(subst _, ,$*))

container-push: # @HELP push built container image to all repos
container-push: $(addprefix container-push-, $(subst :,=, $(subst /,_, $(IMAGE_REPO_TAGS))))

Expand All @@ -138,6 +133,34 @@ all-container-build-push: $(addprefix build-, $(subst /,_, $(IMAGE_PLATFORMS)))

# ===== MISC =====

# Optional variable to pass arguments to sh
# Example: make shell CMD="-c 'date'"
CMD ?=

shell: # @HELP launches a shell in the containerized build environment
shell: build-dirs
echo "# launching a shell in the containerized build environment"
docker run \
-it \
--rm \
-u $$(id -u):$$(id -g) \
-v $$(pwd):/src \
-w /src \
-v $$(pwd)/$(GOCACHE):/cache \
--env GOCACHE="/cache/gocache" \
--env GOMODCACHE="/cache/gomodcache" \
--env ARCH="$(ARCH)" \
--env OS="$(OS)" \
--env VERSION="$(VERSION)" \
--env DEBUG="$(DEBUG)" \
--env OUTPUT="$(OUTPUT)" \
--env GOFLAGS="$(GOFLAGS)" \
--env GOPROXY="$(GOPROXY)" \
--env HTTP_PROXY="$(HTTP_PROXY)" \
--env HTTPS_PROXY="$(HTTPS_PROXY)" \
$(BUILD_IMAGE) \
/bin/sh $(CMD)

# Generate a dockerignore file to ignore everything except
# current build output directory. This is useful because
# when building a container, we only need the final binary.
Expand All @@ -150,9 +173,10 @@ clean: # @HELP clean built binaries
clean:
rm -rf $(DIST)/$(BIN)*

cleanall: # @HELP clean built binaries, build cache, and helper tools
cleanall: clean
rm -rf $(DIST)
all-clean: # @HELP clean built binaries, build cache, and helper tools
all-clean: clean
test -d $(GOCACHE) && chmod -R u+w $(GOCACHE) || true
rm -rf $(GOCACHE) $(DIST)

version: # @HELP output the version string
version:
Expand Down Expand Up @@ -186,7 +210,7 @@ help: # @HELP print this message
help: variables
echo "TARGETS:"
grep -E '^.*: *# *@HELP' $(MAKEFILE_LIST) \
| sed --expression='s_.*.mk:__g' \
| sed -E 's_.*.mk:__g' \
| awk ' \
BEGIN {FS = ": *# *@HELP"}; \
{ printf " %-25s %s\n", $$1, $$2 }; \
Expand Down