From f3d1abdad6455115783470b622a52d66323680bb Mon Sep 17 00:00:00 2001 From: gitworkflows <118260833+gitworkflows@users.noreply.github.com> Date: Mon, 23 Sep 2024 13:20:38 +0600 Subject: [PATCH] Windows releases (#6) * Update pipeline.yaml Signed-off-by: gitworkflows <118260833+gitworkflows@users.noreply.github.com> * Update Makefile Signed-off-by: gitworkflows <118260833+gitworkflows@users.noreply.github.com> * Update golicenses.sh Signed-off-by: gitworkflows <118260833+gitworkflows@users.noreply.github.com> * Update goreleaser.yaml Signed-off-by: gitworkflows <118260833+gitworkflows@users.noreply.github.com> * Update pipeline.yaml Signed-off-by: gitworkflows <118260833+gitworkflows@users.noreply.github.com> * Update Makefile Signed-off-by: gitworkflows <118260833+gitworkflows@users.noreply.github.com> * Update pipeline.yaml Signed-off-by: gitworkflows <118260833+gitworkflows@users.noreply.github.com> --------- Signed-off-by: gitworkflows <118260833+gitworkflows@users.noreply.github.com> --- .github/workflows/pipeline.yaml | 30 ++++++++- Makefile | 110 ++++++++++++++++++-------------- golicenses.sh | 1 + goreleaser.yaml | 41 ++++++++++-- 4 files changed, 125 insertions(+), 57 deletions(-) diff --git a/.github/workflows/pipeline.yaml b/.github/workflows/pipeline.yaml index 67bf8e8..2d7b87f 100644 --- a/.github/workflows/pipeline.yaml +++ b/.github/workflows/pipeline.yaml @@ -83,6 +83,11 @@ jobs: - name: Checkout code uses: actions/checkout@v2 + - name: Set up Go + uses: actions/setup-go@v2 + with: + go-version: '1.18.x' + - name: Download artifacts uses: actions/download-artifact@v3 with: @@ -105,7 +110,7 @@ jobs: - name: Set up Go uses: actions/setup-go@v2 with: - go-version: '1.20' # Specify the Go version you need + go-version: '1.18.x' - name: Download artifacts uses: actions/download-artifact@v3 @@ -116,8 +121,29 @@ jobs: - name: Test Darwin run run: make ci-test-mac-run + test-windows-artifacts: + needs: build-artifacts + runs-on: windows-latest + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Set up Go + uses: actions/setup-go@v2 + with: + go-version: '1.18.x' + + - name: Download artifacts + uses: actions/download-artifact@v3 + with: + name: artifacts + path: dist + + - name: Test Windows run + run: make ci-test-windows-run + release: - needs: [test, build-artifacts, test-linux-artifacts, test-mac-artifacts] + needs: [test, build-artifacts, test-linux-artifacts, test-mac-artifacts, test-windows-artifacts] runs-on: ubuntu-latest if: startsWith(github.ref, 'refs/tags/v') steps: diff --git a/Makefile b/Makefile index 902b4bf..59bf4d5 100644 --- a/Makefile +++ b/Makefile @@ -7,15 +7,26 @@ COVER_REPORT = $(RESULTS)/cover.report COVER_TOTAL = $(RESULTS)/cover.total LINTCMD = $(BIN)/golangci-lint run --tests=false --config .golangci.yaml -BOLD := $(shell tput -T linux bold) -PURPLE := $(shell tput -T linux setaf 5) -GREEN := $(shell tput -T linux setaf 2) -CYAN := $(shell tput -T linux setaf 6) -RED := $(shell tput -T linux setaf 1) -RESET := $(shell tput -T linux sgr0) +# Color definitions with checks for OS +ifeq ($(OS),Windows_NT) + BOLD := "" + PURPLE := "" + GREEN := "" + CYAN := "" + RED := "" + RESET := "" +else + BOLD := $(shell tput -T linux bold) + PURPLE := $(shell tput -T linux setaf 5) + GREEN := $(shell tput -T linux setaf 2) + CYAN := $(shell tput -T linux setaf 6) + RED := $(shell tput -T linux setaf 1) + RESET := $(shell tput -T linux sgr0) +endif + TITLE := $(BOLD)$(PURPLE) SUCCESS := $(BOLD)$(GREEN) -COVERAGE_THRESHOLD := 34 +COVERAGE_THRESHOLD := 55 RELEASE_CMD=$(BIN)/goreleaser --rm-dist @@ -31,7 +42,7 @@ define title @printf '$(TITLE)$(1)$(RESET)\n' endef -.PHONY: all bootstrap lint lint-fix unit coverage help test clean ci-build-snapshot-packages ci-plugs-out-test ci-test-linux-run ci-test-linux-arm-run ci-test-mac-run ci-test-mac-arm-run ci-release +.PHONY: all bootstrap lint lint-fix unit coverage help test clean all: lint test ## Run all checks (linting, unit tests, and integration tests) @printf '$(SUCCESS)All checks pass!$(RESET)\n' @@ -43,40 +54,33 @@ help: bootstrap: ## Download and install all project dependencies (+ prep tooling in the ./.tmp dir) $(call title,Downloading dependencies) - @mkdir -p $(TMP) $(RESULTS) $(BIN) || exit 1 - go mod download || exit 1 - cat tools.go | grep _ | awk -F'"' '{print $$2}' | xargs -tI % env GOBIN=$(BIN) go install % || exit 1 - curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(BIN) v1.50.1 || exit 1 + mkdir -p $(TMP) $(RESULTS) $(BIN) # Create necessary directories + go mod download + cat tools.go | grep _ | awk -F'"' '{print $$2}' | xargs -tI % env GOBIN=$(BIN) go install % + curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(BIN) v1.47.2 cd $(TMP) && curl -sLO https://github.com/markbates/pkger/releases/download/v0.17.0/pkger_0.17.0_$(shell uname)_x86_64.tar.gz && \ tar -xzvf pkger_0.17.0_$(shell uname)_x86_64.tar.gz pkger && \ - mv pkger $(BIN) || exit 1 - GOBIN=$(BIN) go install github.com/goreleaser/goreleaser@v1.3.1 || exit 1 + mv pkger $(BIN) + GOBIN=$(BIN) go install github.com/goreleaser/goreleaser@v1.3.1 $(DBASSET): $(call title,Building assets) - @mkdir -p $(ASSETS) || exit 1 - $(BIN)/license_serializer -output $(ASSETS) || exit 1 + mkdir -p $(ASSETS) + $(BIN)/license_serializer -output $(ASSETS) pkged.go: $(DBASSET) - $(BIN)/pkger || exit 1 + $(BIN)/pkger -lint: ## Run gofmt + golangci-lint checks +lint: ## Run gofmt + golangci lint checks $(call title,Running linters) - @FILES_WITH_ISSUES="$(shell gofmt -l -s .)"; \ - if [ -n "$$FILES_WITH_ISSUES" ]; then \ - echo "The following files have gofmt issues:"; \ - echo "$$FILES_WITH_ISSUES"; \ - exit 1; \ - fi - @printf "Running golangci-lint...\n" - $(LINTCMD) || exit 1 + @printf "files with gofmt issues: [$(shell gofmt -l -s .)]\n" + @test -z "$(shell gofmt -l -s .)" + $(LINTCMD) -lint-fix: ## Auto-format all source code + run golangci-lint fixers +lint-fix: ## Auto-format all source code + run golangci lint fixers $(call title,Running lint fixers) - @echo "Running gofmt to auto-format code..." - @gofmt -w -s . || exit 1 - @echo "Running golangci-lint with --fix..." - $(LINTCMD) --fix || exit 1 + gofmt -w -s . + $(LINTCMD) --fix unit: ## Run unit tests (with coverage) $(call title,Running unit tests) @@ -88,7 +92,9 @@ unit: ## Run unit tests (with coverage) fi ci-build-snapshot-packages: pkged.go - $(RELEASE_CMD) --snapshot --skip-publish + $(RELEASE_CMD) \ + --snapshot \ + --skip-publish ci-plugs-out-test: docker run \ @@ -97,33 +103,39 @@ ci-plugs-out-test: -w //src \ golang:latest \ /bin/bash -x -c "\ - ./dist/go-licenses_linux_amd64/golicenses version && \ - ./dist/go-licenses_linux_amd64/golicenses list github.com/khulnasoft/go-licenses && \ - ./dist/go-licenses_linux_amd64/golicenses check github.com/khulnasoft/go-licenses \ + ./dist/linux-build_linux_amd64/golicenses version && \ + ./dist/linux-build_linux_amd64/golicenses list github.com/khulnasoft/go-licenses && \ + ./dist/linux-build_linux_amd64/golicenses check github.com/khulnasoft/go-licenses \ " ci-test-linux-run: - chmod 755 ./dist/go-licenses_linux_amd64/golicenses && \ - ./dist/go-licenses_linux_amd64/golicenses version && \ - ./dist/go-licenses_linux_amd64/golicenses list github.com/khulnasoft/go-licenses + chmod 755 ./dist/linux-build_linux_amd64/golicenses && \ + ./dist/linux-build_linux_amd64/golicenses version && \ + ./dist/linux-build_linux_amd64/golicenses list github.com/khulnasoft/go-licenses ci-test-linux-arm-run: - chmod 755 ./dist/go-licenses_linux_arm64/golicenses && \ - ./dist/go-licenses_linux_arm64/golicenses version && \ - ./dist/go-licenses_linux_arm64/golicenses list github.com/khulnasoft/go-licenses + chmod 755 ./dist/linux-build_linux_arm64/golicenses && \ + ./dist/linux-build_linux_arm64/golicenses version && \ + ./dist/linux-build_linux_arm64/golicenses list github.com/khulnasoft/go-licenses ci-test-mac-run: - chmod 755 ./dist/go-licenses_darwin_amd64/golicenses && \ - ./dist/go-licenses_darwin_amd64/golicenses version && \ - ./dist/go-licenses_darwin_amd64/golicenses list github.com/khulnasoft/go-licenses + chmod 755 ./dist/darwin-build_darwin_amd64/golicenses && \ + ./dist/darwin-build_darwin_amd64/golicenses version && \ + ./dist/darwin-build_darwin_amd64/golicenses list github.com/khulnasoft/go-licenses ci-test-mac-arm-run: - chmod 755 ./dist/go-licenses_darwin_arm64/golicenses && \ - ./dist/go-licenses_darwin_arm64/golicenses version && \ - ./dist/go-licenses_darwin_arm64/golicenses list github.com/khulnasoft/go-licenses + chmod 755 ./dist/darwin-build_darwin_arm64/golicenses && \ + ./dist/darwin-build_darwin_arm64/golicenses version && \ + ./dist/darwin-build_darwin_arm64/golicenses list github.com/khulnasoft/go-licenses + +ci-test-windows-run: + @echo "Running Windows tests..." + @powershell -Command "Start-Process -NoNewWindow -File ./dist/windows-build_windows_amd64/golicenses.exe -ArgumentList 'version' -Wait" + @powershell -Command "Start-Process -NoNewWindow -File ./dist/windows-build_windows_amd64/golicenses.exe -ArgumentList 'list github.com/khulnasoft/go-licenses' -Wait" ci-release: pkged.go $(BIN)/goreleaser --rm-dist -clean: ## Clean build artifacts - rm -rf dist .tmp $(RESULTS) +clean: + rm -rf dist + rm -rf .tmp diff --git a/golicenses.sh b/golicenses.sh index 94213cf..9b1d788 100755 --- a/golicenses.sh +++ b/golicenses.sh @@ -66,6 +66,7 @@ get_binaries() { linux/amd64) BINARIES="golicenses" ;; darwin/arm64) BINARIES="golicenses" ;; linux/arm64) BINARIES="golicenses" ;; + windows/amd64) BINARIES="golicenses.exe" ;; *) log_crit "platform $PLATFORM is not supported. Make sure this script is up-to-date and file request at https://github.com/${PREFIX}/issues/new" exit 1 diff --git a/goreleaser.yaml b/goreleaser.yaml index 7644696..635afb7 100644 --- a/goreleaser.yaml +++ b/goreleaser.yaml @@ -1,17 +1,46 @@ release: prerelease: auto +env: + - CGO_ENABLED=0 + builds: - - binary: golicenses - env: - - CGO_ENABLED=0 + - id: linux-build + binary: golicenses goos: - - darwin - linux goarch: - amd64 - arm64 - ldflags: -s -w -X main.version={{.Version}} -X main.commit={{.Commit}} -X main.buildTime={{.Date}}`. + ldflags: &build-ldflags -s -w -X main.version={{.Version}} -X main.commit={{.Commit}} -X main.buildTime={{.Date}}`. + + - id: darwin-build + binary: golicenses + goos: + - darwin + goarch: + - amd64 + - arm64 + ldflags: *build-ldflags + + - id: windows-build + binary: golicenses + goos: + - windows + goarch: + - amd64 + ldflags: *build-ldflags archives: - - format: tar.gz + - id: linux-archives + builds: + - linux-build + + - id: darwin-archives + builds: + - darwin-build + + - id: windows-archives + format: zip + builds: + - windows-build