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

Use krew-plugin-release instead of krew-release-bot #48

Merged
merged 1 commit into from
May 8, 2021
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
5 changes: 5 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,8 @@ jobs:
- run: make lint
- run: make test
- run: make dist
- uses: superbrothers/actions/krew-plugin-test@master
with:
manifest: ./dist/sort-manifests.yaml
archive: ./dist/ksort-linux-amd64.zip
command: kubectl sort-manifests --help
19 changes: 15 additions & 4 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,20 @@ jobs:
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Release
run: make release
- run: make dist
- uses: softprops/action-gh-release@v1
with:
files: dist/!(config.yaml)
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Update new version in krew-index
uses: rajatjindal/[email protected]
- uses: superbrothers/actions/krew-plugin-test@master
with:
manifest: ./dist/sort-manifests.yaml
command: kubectl sort-manifests --help
- uses: superbrothers/actions/krew-plugin-release@master
with:
token: ${{ secrets.PAT }}
plugin_name: sort-manifests
manifest_path: dist/sort-manifests.yaml
git_author_name: Kazuki Suda
git_author_email: [email protected]
12 changes: 7 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
GO ?= GO111MODULE=on go
DIST_DIR := dist
GIT_VERSION ?= $(shell ./hack/git-version.sh)

.PHONY: build
build:
Expand All @@ -11,13 +12,17 @@ GORELEASER_BIN := bin/goreleaser
GORELEASER := $(TOOLS_DIR)/$(GORELEASER_BIN)
GOLANGCI_LINT_BIN := bin/golangci-lint
GOLANGCI_LINT := $(TOOLS_DIR)/$(GOLANGCI_LINT_BIN)
GOMPLATE_BIN := bin/gomplate
GOMPLATE := $(TOOLS_DIR)/$(GOMPLATE_BIN)

$(GORELEASER): $(TOOLS_DIR)/go.mod
cd $(TOOLS_DIR) && $(GO) build -o $(GORELEASER_BIN) github.com/goreleaser/goreleaser

$(GOLANGCI_LINT): $(TOOLS_DIR)/go.mod
cd $(TOOLS_DIR) && $(GO) build -o $(GOLANGCI_LINT_BIN) github.com/golangci/golangci-lint/cmd/golangci-lint

$(GOMPLATE): $(TOOLS_DIR)/go.mod
cd $(TOOLS_DIR) && $(GO) build -o $(GOMPLATE_BIN) github.com/hairyhenderson/gomplate/v3/cmd/gomplate

.PHONY: build-cross
build-cross: $(GORELEASER)
Expand All @@ -40,12 +45,9 @@ test:
$(GO) test -v ./...

.PHONY: dist
dist: $(GORELEASER)
dist: $(GORELEASER) $(GOMPLATE)
$(GORELEASER) release --rm-dist --skip-publish --snapshot

.PHONY: release
release: $(GORELEASER)
$(GORELEASER) release --rm-dist
GIT_VERSION=$(GIT_VERSION) $(GOMPLATE) -f ./hack/sort-manifests.yaml.tmpl > $(DIST_DIR)/sort-manifests.yaml

.PHONY: clean
clean:
Expand Down
24 changes: 24 additions & 0 deletions hack/git-version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/env bash

set -e -o pipefail; [[ -n "$DEBUG" ]] && set -x

# parse the current git commit hash
commit="$(git rev-parse HEAD)"

# check if the current commit has a matching tag
tag="$(git describe --exact-match --abbrev=0 --tags "${commit}" 2> /dev/null ||:)"

# use the matching tag as the version, if available
if [[ -z "$tag" ]]; then
version="v0.0.0-${commit}"
else
version="$tag"
fi

# check for changed files
if [[ -n "$(git diff --shortstat 2> /dev/null | tail -n1)" ]]; then
version="${version}-dirty"
fi

echo "$version"
# vim: ai ts=2 sw=2 et sts=2 ft=sh
11 changes: 7 additions & 4 deletions .krew.yaml → hack/sort-manifests.yaml.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ kind: Plugin
metadata:
name: sort-manifests
spec:
version: {{ .TagName }}
version: {{ .Env.GIT_VERSION }}
shortDescription: Sort manifest files in a proper order by Kind
description: |
When installing manifests, they should be sorted in a proper order by Kind.
Expand All @@ -14,7 +14,8 @@ spec:
using tiller.SortByKind() in Kubernetes Helm.
homepage: https://github.com/superbrothers/ksort
platforms:
- {{addURIAndSha "https://github.com/superbrothers/ksort/releases/download/{{ .TagName }}/ksort-darwin-amd64.zip" .TagName }}
- uri: https://github.com/superbrothers/ksort/releases/download/{{ .Env.GIT_VERSION }}/ksort-darwin-amd64.zip
sha256: {{ file.Read "./dist/ksort-darwin-amd64.zip" | crypto.SHA256 }}
bin: ksort
files:
- from: ksort
Expand All @@ -25,7 +26,8 @@ spec:
matchLabels:
os: darwin
arch: amd64
- {{addURIAndSha "https://github.com/superbrothers/ksort/releases/download/{{ .TagName }}/ksort-linux-amd64.zip" .TagName }}
- uri: https://github.com/superbrothers/ksort/releases/download/{{ .Env.GIT_VERSION }}/ksort-linux-amd64.zip
sha256: {{ file.Read "./dist/ksort-linux-amd64.zip" | crypto.SHA256 }}
bin: ksort
files:
- from: ksort
Expand All @@ -36,7 +38,8 @@ spec:
matchLabels:
os: linux
arch: amd64
- {{addURIAndSha "https://github.com/superbrothers/ksort/releases/download/{{ .TagName }}/ksort-windows-amd64.zip" .TagName }}
- uri: https://github.com/superbrothers/ksort/releases/download/{{ .Env.GIT_VERSION }}/ksort-windows-amd64.zip
sha256: {{ file.Read "./dist/ksort-windows-amd64.zip" | crypto.SHA256 }}
bin: ksort.exe
files:
- from: ksort.exe
Expand Down
7 changes: 4 additions & 3 deletions hack/tools/go.mod
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
module github.com/superbrothers/kubectl-open-svc-plugin/hack/tools

go 1.15
go 1.16

require (
github.com/goreleaser/goreleaser v0.145.0
github.com/golangci/golangci-lint v1.32.0
github.com/golangci/golangci-lint v1.36.0
github.com/goreleaser/goreleaser v0.157.0
github.com/hairyhenderson/gomplate/v3 v3.9.0
)
Loading