Skip to content

Commit

Permalink
Merge branch 'master' into leecalcote/ci/build-release
Browse files Browse the repository at this point in the history
Signed-off-by: Lee Calcote <lee.calcote@layer5.io>
  • Loading branch information
leecalcote committed Nov 5, 2024
2 parents c02e5e7 + 1cdd3cc commit 960d3bc
Show file tree
Hide file tree
Showing 18 changed files with 302 additions and 133 deletions.
48 changes: 21 additions & 27 deletions .github/.goreleaser.yml
Original file line number Diff line number Diff line change
@@ -1,56 +1,50 @@
project_name: kanvas-snapshot
project_name: helm-kanvas-snapshot
version: 2
before:
hooks:
- go mod tidy

builds:
- main: cmd/kanvas-snapshot/main.go

env:
- env:
- CGO_ENABLED=0

ldflags:
- -s -w
- -X main.providerToken={{.Env.PROVIDER_TOKEN}}
- -X main.providerToken={{.Env.PROVIDER_TOKEN}}
- -X main.MesheryCloudApiBaseUrl="https://meshery.layer5.io"
- -X main.MesheryApiBaseUrl="https://playground.meshery.io"

goos:
- darwin
- linux
- darwin
- freebsd
- windows

goarch:
- 386
- amd64
- '386'
- arm
- arm64

ignore:
- goos: windows
goarch: arm
- goos: windows
goarch: arm64
binary: '{{ .ProjectName }}'

archives:
- id: stable
- format: tar.gz
wrap_in_directory: true
name_template: >-
{{ .ProjectName }}_{{.Version}}_
{{- title .Os }}_
{{- .ProjectName }}_
{{- .Version }}_
{{- .Os }}_
{{- if eq .Arch "amd64" }}x86_64
{{- else if eq .Arch "386" }}i386
{{- else }}{{ .Arch }}{{ end }}
format: tar.gz
# format_overrides:
# - goos: windows
# format: zip

checksum:
name_template: 'checksums.txt'
files:
- plugin.yaml
- LICENSE
- install-binary.sh

snapshot:
version_template: "{{ .Tag }}-next"
name_template: "{{ .ProjectName }}_{{ .Version }}_{{ .Runtime.Goos }}_{{ .Runtime.Goarch }}"

checksum:
name_template: '{{ .ProjectName }}_{{ .Version }}_SHA256SUMS'
algorithm: sha256

changelog:
sort: asc
Expand Down
2 changes: 1 addition & 1 deletion .github/release-drafter.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name-template: 'Meshery v$NEXT_PATCH_VERSION'
name-template: 'Helm Kanvas Snapshot v$NEXT_PATCH_VERSION'
tag-template: 'v$NEXT_PATCH_VERSION'
categories:
- title: '🚀 Features'
Expand Down
22 changes: 11 additions & 11 deletions .github/workflows/build-and-release-snapshot-plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ on:
types: [published]

workflow_dispatch:
inputs:
branch:
description: "Branch to deploy in the staging environment. If not provided, master branch of the repository will be used."
default: "master"
type: string

pull_request: # Add this to trigger on PR events
branches:
- install-script-enhancement

jobs:
release:
if: github.repository == 'meshery/helm-kanvas-snapshot' && startsWith(github.ref, 'refs/tags/v') && !contains(github.ref, 'patch') && !contains(github.ref, 'alpha') && !contains(github.ref, 'beta') && !contains(github.ref, 'rc')
Expand All @@ -26,21 +26,21 @@ jobs:
uses: actions/setup-go@v5
with:
go-version: "1.21"
- name: golangci-lint

- name: Run golangci-lint
uses: golangci/golangci-lint-action@v6
with:
version: v1.59
working-directory: ./cmd/kanvas-snapshot
working-directory: .
args: --timeout 10m --verbose
skip-cache: true

- name: Run GoReleaser with tag
uses: goreleaser/goreleaser-action@v6
with:
version: latest # Use latest GoReleaser action version
args: release --clean --skip-validate -f goreleaser.yml # Corrected filename to root
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
RELEASE_CHANNEL: "stable"
PROVIDER_TOKEN: ${{ secrets.PROVIDER_TOKEN }}
with:
version: 2
args: release --clean --skip validate -f .github/.goreleaser.yml
5 changes: 2 additions & 3 deletions .github/workflows/error-codes-updater.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,12 @@ jobs:
- name: Run Utility For Plugin
run: |
cd ./cmd
~/errorutil update -d . -i ./helpers -o ./helpers
output=$(~/errorutil -d . analyze -i ./helpers -o ./helpers | wc -c)
if [ "$output" -ne 0 ]; then
exit 1
fi
echo '{ "errors_export": "" }' | jq --slurpfile export ../server/helpers/errorutil_errors_export.json '.errors_export = $export[0]' > ../docs/_data/errorref/mesheryctl_errors_export.json
echo '{ "errors_export": "" }' | jq --slurpfile export ./helpers/errorutil_errors_export.json '.errors_export = $export[0]' > ./helpers/errorutil_errors_export.json
- name: Pull changes from remote
run: git pull origin master
Expand All @@ -54,7 +53,7 @@ jobs:
if: ${{ github.event_name != 'pull_request' }} # Skip for pull requests
uses: stefanzweifel/git-auto-commit-action@v5
with:
file_pattern: mesheryctl/helpers server/helpers/ **.go docs/
file_pattern: helpers
commit_user_name: l5io
commit_user_email: ci@layer5.io
commit_author: ${{ github.actor }} <${{ github.actor }}@users.noreply.github.com>
Expand Down
117 changes: 67 additions & 50 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
# See the License for the specific language governing permissions and
# limitations under the License.

include build/Makefile.core.mk
# include build/Makefile.core.mk


.PHONY: all
all: dep-check build
## Lint check
## Lint check
golangci: error dep-check
golangci-lint run --exclude-use-default

Expand All @@ -29,11 +29,9 @@ error: dep-check
error-util:
go run github.com/layer5io/meshkit/cmd/errorutil -d . update -i ./build -o ./build



#-----------------------------------------------------------------------------
# Dependencies
#-----------------------------------------------------------------------------
# #-----------------------------------------------------------------------------
# # Dependencies
# #-----------------------------------------------------------------------------
.PHONY: dep-check
#.SILENT: dep-check

Expand All @@ -48,47 +46,66 @@ ifeq (,$(findstring $(GOVERSION), $(INSTALLED_GO_VERSION)))
@echo "INSTALLED_GO_VERSION: " $(INSTALLED_GO_VERSION)
endif

GOFMT_FILES?=$(shell find . -type f -name '*.go' -not -path "./vendor/*")
APP_NAME?=helm-kanvas-snapshot
APP_DIR?=$(shell git rev-parse --show-toplevel)
DEV?=${DEVBOX_TRUE}
SRC_PACKAGES=$(shell go list ./... | grep -v "mocks")
BUILD_ENVIRONMENT?=${ENVIRONMENT}
VERSION?=0.1.0
REVISION?=$(shell git rev-parse --verify HEAD)
DATE?=$(shell date)
PLATFORM?=$(shell go env GOOS)
ARCHITECTURE?=$(shell go env GOARCH)
GOVERSION?=$(shell go version | awk '{printf $$3}')
BUILD_WITH_FLAGS="-s -w -X 'github.com/meshery/helm-kanvas-snapshot/version.Version=${VERSION}' -X 'github.com/meshery/helm-kanvas-snapshot/version.Env=${BUILD_ENVIRONMENT}' -X 'github.com/meshery/helm-kanvas-snapshot/version.BuildDate=${DATE}' -X 'github.com/meshery/helm-kanvas-snapshot/version.Revision=${REVISION}' -X 'github.com/meshery/helm-kanvas-snapshot/version.Platform=${PLATFORM}/${ARCHITECTURE}' -X 'github.com/meshery/helm-kanvas-snapshot/version.GoVersion=${GOVERSION}' -X 'main.providerToken=$(PROVIDER_TOKEN)' -X 'main.MesheryCloudApiBaseUrl=$(MESHERY_CLOUD_API_BASE_URL)' -X 'main.MesheryApiBaseUrl=$(MESHERY_API_BASE_URL)'"

# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
ifeq (,$(shell go env GOBIN))
GOBIN=$(shell go env GOPATH)/bin
else
GOBIN=$(shell go env GOBIN)
endif

.PHONY: help
help: ## Prints help (only for targets with comments)
@grep -E '^[a-zA-Z0-9._-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'

local.fmt: ## Lints all the Go code in the application.
@gofmt -w $(GOFMT_FILES)
$(GOBIN)/goimports -w $(GOFMT_FILES)
$(GOBIN)/gofumpt -l -w $(GOFMT_FILES)
$(GOBIN)/gci write $(GOFMT_FILES) --skip-generated

local.check: local.fmt ## Loads all dependencies
@go mod tidy

local.build: local.check ## Generates the artifact with 'go build'
@go build -o $(APP_NAME) -ldflags="-s -w"

local.snapshot: local.check ## Generates the artifact with 'go build'
GOVERSION=${GOVERSION} BUILD_ENVIRONMENT=${BUILD_ENVIRONMENT} goreleaser build --snapshot --clean

local.push: local.build ## Pushes built artifact to specified location

local.run: local.build ## Builds the artifact and starts the service
./${APP_NAME}

print_home:
@echo ${ENVIRONMENT}


local.deploy: local.build ## Deploys locally built Helm plugin
@rm -rf ${HOME}/Library/helm/plugins/helm-kanvas-snapshot/bin/helm-kanvas-snapshot
@cp helm-images ${HOME}/Library/helm/plugins/helm-kanvas-snapshot/bin/helm-kanvas-snapshot


publish: local.check ## Builds and publishes the app
GOVERSION=${GOVERSION} BUILD_ENVIRONMENT=${BUILD_ENVIRONMENT} PLUGIN_PATH=${APP_DIR} goreleaser release --snapshot --clean

mock.publish: local.check ## Builds and mocks app release
GOVERSION=${GOVERSION} BUILD_ENVIRONMENT=${BUILD_ENVIRONMENT} PLUGIN_PATH=${APP_DIR} goreleaser release --skip=publish --clean


OUTDIR := ./cmd/kanvas-snapshot/bin
ARCH := amd64

BINNAME_DARWIN ?= kanvas-snapshot-darwin-$(ARCH)
BINNAME_LINUX ?= kanvas-snapshot-linux-$(ARCH)
BINNAME_WINDOWS ?= kanvas-snapshot-windows-$(ARCH).exe


LDFLAGS := "\
-X 'main.providerToken=$(PROVIDER_TOKEN)' \
-X 'main.MesheryCloudApiBaseUrl=$(MESHERY_CLOUD_API_BASE_URL)' \
-X 'main.MesheryApiBaseUrl=$(MESHERY_API_BASE_URL)'"

.PHONY: build
build:
@echo "Building for all platforms..."
@$(MAKE) $(BINNAME_DARWIN)
@$(MAKE) $(BINNAME_LINUX)
@$(MAKE) $(BINNAME_WINDOWS)

# Build Helm plugin for Darwin (macOS)
.PHONY: $(BINNAME_DARWIN)
$(BINNAME_DARWIN):
@echo "Building for Darwin..."
CGO_ENABLED=0 GOARCH=$(ARCH) GOOS=darwin go build -ldflags=$(LDFLAGS) -o $(OUTDIR)/$(BINNAME_DARWIN) ./cmd/kanvas-snapshot/main.go

# Build Helm plugin for Linux
.PHONY: $(BINNAME_LINUX)
$(BINNAME_LINUX):
@echo "Building for Linux..."
CGO_ENABLED=0 GOARCH=$(ARCH) GOOS=linux go build -ldflags=$(LDFLAGS) -o $(OUTDIR)/$(BINNAME_LINUX) ./cmd/kanvas-snapshot/main.go

# Build Helm plugin for Windows
.PHONY: $(BINNAME_WINDOWS)
$(BINNAME_WINDOWS):
@echo "Building for Windows..."
CGO_ENABLED=0 GOARCH=$(ARCH) GOOS=windows go build -ldflags=$(LDFLAGS) -o $(OUTDIR)/$(BINNAME_WINDOWS) ./cmd/kanvas-snapshot/main.go

# Clean up binaries
.PHONY: clean
clean:
@echo "Cleaning up..."
rm -rf $(OUTDIR)
install.hooks: ## Installs pre-push hooks for the repository
${APP_DIR}/scripts/hook.sh ${APP_DIR}
19 changes: 19 additions & 0 deletions artifacthub-repo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Artifact Hub repository metadata file
#
# Some settings like the verified publisher flag or the ignored packages won't
# be applied until the next time the repository is processed. Please keep in
# mind that the repository won't be processed if it has not changed since the
# last time it was processed. Depending on the repository kind, this is checked
# in a different way. For Helm http based repositories, we consider it has
# changed if the `index.yaml` file changes. For git based repositories, it does
# when the hash of the last commit in the branch you set up changes. This does
# NOT apply to ownership claim operations, which are processed immediately.
#
repositoryID: 1b4e2e51-4979-43c4-a164-c26426c196b2
owners: # (optional, used to claim repository ownership)
- name: meshery
email: maintainers@meshery.io
#ignore: # (optional, packages that should not be indexed by Artifact Hub)
# - name: package1
# - name: package2 # Exact match
# version: beta # Regular expression (when omitted, all versions are ignored)
6 changes: 3 additions & 3 deletions build/component_info.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "kanvas-snapshot",
"name": "helm-kanvas-snapshot",
"type": "component",
"next_error_code": 1006
}
"next_error_code": 1000
}
Loading

0 comments on commit 960d3bc

Please sign in to comment.