Skip to content

Commit

Permalink
Windows releases (#6)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
gitworkflows authored Sep 23, 2024
1 parent 1dce744 commit f3d1abd
Show file tree
Hide file tree
Showing 4 changed files with 125 additions and 57 deletions.
30 changes: 28 additions & 2 deletions .github/workflows/pipeline.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand All @@ -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:
Expand Down
110 changes: 61 additions & 49 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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'
Expand All @@ -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)
Expand All @@ -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 \
Expand All @@ -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
1 change: 1 addition & 0 deletions golicenses.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
41 changes: 35 additions & 6 deletions goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit f3d1abd

Please sign in to comment.