Skip to content

Commit

Permalink
Chore: better cross building infra
Browse files Browse the repository at this point in the history
  • Loading branch information
charlie0129 committed Aug 21, 2022
1 parent 1959ea9 commit f9a7b7f
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 37 deletions.
38 changes: 15 additions & 23 deletions .github/workflows/go-build-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@ jobs:
- name: Checkout Code
uses: actions/checkout@v3

- name: Run Go Generate
run: make generate

- name: Check boilerplate
run: make checklicense

Expand All @@ -45,9 +42,18 @@ jobs:
with:
version: ${{ env.GOLANGCI_VERSION }}

- name: Run Go Generate
run: make generate

- name: Show Make Variables
run: ./make-kt variables

- name: Get Version
id: get_version
run: |
export VERSION=$(./make-kt version)
echo ::set-output name=VERSION::${VERSION}
- name: Build Binaries for All Platforms
env:
DIRTY_BUILD: true
Expand All @@ -56,34 +62,20 @@ jobs:
- name: Upload Artifacts (linux-amd64)
uses: actions/upload-artifact@v3
with:
name: kube-trigger-${{ github.sha }}-linux-amd64
name: kube-trigger-${{ steps.get_version.outputs.VERSION }}-linux-amd64
retention-days: 7
path: bin/kube-trigger-*-linux-amd64

- name: Upload Artifacts (linux-arm64)
uses: actions/upload-artifact@v3
with:
name: kube-trigger-${{ github.sha }}-linux-arm64
retention-days: 7
path: bin/kube-trigger-*-linux-arm64
path: bin/kube-trigger-${{ steps.get_version.outputs.VERSION }}/kube-trigger-*-linux-amd64

- name: Upload Artifacts (darwin-amd64)
uses: actions/upload-artifact@v3
with:
name: kube-trigger-${{ github.sha }}-darwin-amd64
name: kube-trigger-${{ steps.get_version.outputs.VERSION }}-darwin-amd64
retention-days: 7
path: bin/kube-trigger-*-darwin-amd64
path: bin/kube-trigger-${{ steps.get_version.outputs.VERSION }}/kube-trigger-*-darwin-amd64

- name: Upload Artifacts (darwin-arm64)
uses: actions/upload-artifact@v3
with:
name: kube-trigger-${{ github.sha }}-darwin-arm64
retention-days: 7
path: bin/kube-trigger-*-darwin-arm64

- name: Upload Artifacts (windows-amd64)
uses: actions/upload-artifact@v3
with:
name: kube-trigger-${{ github.sha }}-windows-amd64
name: kube-trigger-${{ steps.get_version.outputs.VERSION }}-darwin-arm64
retention-days: 7
path: bin/kube-trigger-*-windows-amd64.exe
path: bin/kube-trigger-${{ steps.get_version.outputs.VERSION }}/kube-trigger-*-darwin-arm64
6 changes: 3 additions & 3 deletions .github/workflows/release-binary.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@ jobs:
fail_on_unmatched_files: true
prerelease: ${{ contains(steps.get_version.outputs.VERSION, 'alpha') || contains(steps.get_version.outputs.VERSION, 'beta') }}
files: |
bin/kube-trigger-*.zip
bin/kube-trigger-*.tar.gz
bin/*-checksums.txt
bin/kube-trigger-${{ steps.get_version.outputs.VERSION }}/kube-trigger-*.zip
bin/kube-trigger-${{ steps.get_version.outputs.VERSION }}/kube-trigger-*.tar.gz
bin/kube-trigger-${{ steps.get_version.outputs.VERSION }}/*-checksums.txt
26 changes: 15 additions & 11 deletions makefiles/common-targets.mk
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,21 @@
# limitations under the License.

# Binary basename
_OUT := $(BIN)$(BIN_EXTENSION)
BIN_BASENAME := $(BIN)$(BIN_EXTENSION)
# Binary basename with version and target
_VER_OUT := $(BIN)-$(VERSION)-$(OS)-$(ARCH)$(BIN_EXTENSION)
BIN_VERBOSE_BASE := $(BIN)-$(VERSION)-$(OS)-$(ARCH)$(BIN_EXTENSION)
# If the user set FULL_NAME, we will use the basename with version and target.
# e.g. kube-trigger-v0.0.1-linux-amd64
BIN_FULLNAME := $(if $(FULL_NAME),$(_VER_OUT),$(_OUT))
PKG_FULLNAME := $(if $(FULL_NAME),$(_VER_OUT),$(_OUT)).tar.gz
BIN_FULLNAME := $(if $(FULL_NAME),$(BIN_VERBOSE_BASE),$(BIN_BASENAME))
PKG_FULLNAME := $(if $(FULL_NAME),$(BIN_VERBOSE_BASE),$(BIN_BASENAME)).tar.gz
ifeq ($(OS), windows)
PKG_FULLNAME := $(subst .exe,,$(if $(FULL_NAME),$(_VER_OUT),$(_OUT))).zip
PKG_FULLNAME := $(subst .exe,,$(if $(FULL_NAME),$(BIN_VERBOSE_BASE),$(BIN_BASENAME))).zip
endif

BIN_VERBOSE_DIR := bin/$(BIN)-$(VERSION)
# Full output relative path
OUTPUT := bin/$(BIN_FULLNAME)
OUTPUT := $(if $(FULL_NAME),$(BIN_VERBOSE_DIR)/$(BIN_FULLNAME),bin/$(BIN_FULLNAME))


all: build

Expand All @@ -38,7 +41,7 @@ build-%:

all-build: # @HELP build and package binaries for all platforms
all-build: $(addprefix build-, $(subst /,_, $(BIN_PLATFORMS)))
cd bin && sha256sum *{.tar.gz,.zip} > "$(BIN)-$(VERSION)-checksums.txt"
cd "$(BIN_VERBOSE_DIR)" && sha256sum *{.tar.gz,.zip} > "$(BIN)-$(VERSION)-checksums.txt"

build: # @HELP build binary locally
build:
Expand All @@ -52,11 +55,12 @@ build:

package: build
echo "# Compressing $(BIN_FULLNAME) to $(PKG_FULLNAME)"
cp LICENSE bin/LICENSE
cd bin && if [ "$(OS)" == "windows" ]; then \
zip "$(PKG_FULLNAME)" "$(BIN_FULLNAME)" LICENSE; \
cp LICENSE "$(BIN_VERBOSE_DIR)/LICENSE"
cp "$(OUTPUT)" "$(BIN_VERBOSE_DIR)/$(BIN_BASENAME)"
cd $(BIN_VERBOSE_DIR) && if [ "$(OS)" == "windows" ]; then \
zip "$(PKG_FULLNAME)" "$(BIN_BASENAME)" LICENSE; \
else \
tar czf "$(PKG_FULLNAME)" "$(BIN_FULLNAME)" LICENSE; \
tar czf "$(PKG_FULLNAME)" "$(BIN_BASENAME)" LICENSE; \
fi

dirty-build: # @HELP same as build, but using build cache is allowed
Expand Down

0 comments on commit f9a7b7f

Please sign in to comment.