forked from tohjustin/kube-lineage
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Justin Toh <[email protected]>
- Loading branch information
Showing
7 changed files
with
304 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
# This workflow is triggered on push or pull request for the master branch. | ||
# It runs tests and various checks to validate that the proposed changes | ||
# will not introduce any regression after merging the code to the master branch. | ||
name: Build | ||
on: | ||
push: | ||
branches: | ||
- master | ||
paths-ignore: | ||
- '*.md' | ||
pull_request: | ||
branches: | ||
- master | ||
paths-ignore: | ||
- '*.md' | ||
env: | ||
GO_VERSION: "1.16" | ||
jobs: | ||
lint: | ||
name: Run linter | ||
runs-on: ubuntu-18.04 | ||
steps: | ||
- name: Setup Go | ||
uses: actions/setup-go@v2 | ||
with: | ||
go-version: ${{ env.GO_VERSION }} | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
with: | ||
fetch-depth: 0 | ||
- uses: actions/cache@v2 | ||
with: | ||
path: ~/go/pkg/mod | ||
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} | ||
restore-keys: | | ||
${{ runner.os }}-go- | ||
- name: Run linter | ||
run: make lint | ||
test: | ||
name: Run tests | ||
runs-on: ubuntu-18.04 | ||
steps: | ||
- name: Setup Go | ||
uses: actions/setup-go@v2 | ||
with: | ||
go-version: ${{ env.GO_VERSION }} | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
with: | ||
fetch-depth: 0 | ||
- uses: actions/cache@v2 | ||
with: | ||
path: ~/go/pkg/mod | ||
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} | ||
restore-keys: | | ||
${{ runner.os }}-go- | ||
- name: Run tests | ||
run: make test | ||
release-snapshot: | ||
name: Release unversioned snapshot | ||
needs: | ||
- lint | ||
- test | ||
runs-on: ubuntu-18.04 | ||
permissions: | ||
contents: read | ||
steps: | ||
- name: Setup Go | ||
uses: actions/setup-go@v2 | ||
with: | ||
go-version: ${{ env.GO_VERSION }} | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
with: | ||
fetch-depth: 0 | ||
- uses: actions/cache@v2 | ||
with: | ||
path: ~/go/pkg/mod | ||
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} | ||
restore-keys: | | ||
${{ runner.os }}-go- | ||
- name: Release | ||
run: make release-snapshot |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
# This workflow is triggered on new tags. | ||
# It runs tests to validate that the code is working before publishing a new | ||
# version for plugin "lineage" in krew-index. | ||
name: Release | ||
on: | ||
push: | ||
tags: | ||
- 'v*.*.*' | ||
env: | ||
GO_VERSION: "1.16" | ||
jobs: | ||
lint: | ||
name: Run linter | ||
runs-on: ubuntu-18.04 | ||
steps: | ||
- name: Setup Go | ||
uses: actions/setup-go@v2 | ||
with: | ||
go-version: ${{ env.GO_VERSION }} | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
with: | ||
fetch-depth: 0 | ||
- uses: actions/cache@v2 | ||
with: | ||
path: ~/go/pkg/mod | ||
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} | ||
restore-keys: | | ||
${{ runner.os }}-go- | ||
- name: Run linter | ||
run: make lint | ||
test: | ||
name: Run tests | ||
runs-on: ubuntu-18.04 | ||
steps: | ||
- name: Setup Go | ||
uses: actions/setup-go@v2 | ||
with: | ||
go-version: ${{ env.GO_VERSION }} | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
with: | ||
fetch-depth: 0 | ||
- uses: actions/cache@v2 | ||
with: | ||
path: ~/go/pkg/mod | ||
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} | ||
restore-keys: | | ||
${{ runner.os }}-go- | ||
- name: Run tests | ||
run: make test | ||
release: | ||
name: Release | ||
runs-on: ubuntu-18.04 | ||
permissions: | ||
contents: write | ||
steps: | ||
- name: Setup Go | ||
uses: actions/setup-go@v2 | ||
with: | ||
go-version: ${{ env.GO_VERSION }} | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
with: | ||
fetch-depth: 0 | ||
- uses: actions/cache@v2 | ||
with: | ||
path: ~/go/pkg/mod | ||
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} | ||
restore-keys: | | ||
${{ runner.os }}-go- | ||
- name: Release | ||
run: make release | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
run: | ||
deadline: 1m | ||
deadline: 5m | ||
linters: | ||
enable-all: true | ||
disable: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
project_name: kubectl-lineage | ||
before: | ||
hooks: | ||
- go mod tidy | ||
builds: | ||
- binary: kubectl-lineage | ||
main: ./cmd/kubectl-lineage | ||
goos: | ||
- darwin | ||
- linux | ||
- windows | ||
goarch: | ||
- amd64 | ||
- arm64 | ||
ignore: | ||
- goos: windows | ||
goarch: arm64 | ||
env: | ||
- CGO_ENABLED=0 | ||
ldflags: | ||
- -s -w | ||
- -X github.com/tohjustin/kubectl-lineage/internal/version.gitMajor={{ .Env.GIT_VERSION_MAJOR }} | ||
- -X github.com/tohjustin/kubectl-lineage/internal/version.gitMinor={{ .Env.GIT_VERSION_MINOR }} | ||
- -X github.com/tohjustin/kubectl-lineage/internal/version.gitVersion={{ .Env.GIT_VERSION }} | ||
- -X github.com/tohjustin/kubectl-lineage/internal/version.gitCommit={{ .Env.GIT_COMMIT }} | ||
- -X github.com/tohjustin/kubectl-lineage/internal/version.gitTreeState={{ .Env.GIT_TREE_STATE }} | ||
- -X github.com/tohjustin/kubectl-lineage/internal/version.buildDate={{ .Env.BUILD_DATE }} | ||
archives: | ||
- files: | ||
- LICENSE.md | ||
- README.md | ||
format_overrides: | ||
- goos: windows | ||
format: zip | ||
name_template: "{{ .ProjectName }}_{{ .Os }}_{{ .Arch }}" | ||
wrap_in_directory: false | ||
checksum: | ||
name_template: "checksums.txt" | ||
snapshot: | ||
name_template: "{{ .Tag }}-next" | ||
changelog: | ||
sort: asc | ||
filters: | ||
exclude: | ||
- "^chore:" | ||
- "^docs:" | ||
- "^refactor:" | ||
- "^test:" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
SHELL:=/bin/bash | ||
|
||
GO_VERSION = "1.16" | ||
GOLANGCI_LINT_VERSION = "1.41.1" | ||
GORELEASER_VERSION = "0.179.0" | ||
|
||
export BUILD_DATE = $(shell date -u +"%Y-%m-%dT%H:%M:%SZ") | ||
export GIT_COMMIT = $(shell git rev-parse HEAD) | ||
export GIT_TREE_STATE = $(shell if [ -z "`git status --porcelain`" ]; then echo "clean" ; else echo "dirty"; fi) | ||
export GIT_VERSION = $(shell git describe --tags --always | grep -E '^v\d+\.\d+\.\d+(-.*)?') | ||
export GIT_VERSION_MAJOR = $(shell if [[ "${GIT_VERSION}" ]]; then echo ${GIT_VERSION} | cut -d 'v' -f 2 | cut -d "." -f 1 ; fi) | ||
export GIT_VERSION_MINOR = $(shell if [[ "${GIT_VERSION}" ]]; then echo ${GIT_VERSION} | cut -d 'v' -f 2 | cut -d "." -f 2 ; fi) | ||
export CGO_ENABLED = 1 | ||
|
||
REPO = $(shell go list -m) | ||
GO_BUILD_ARGS = \ | ||
-gcflags "all=-trimpath=$(shell dirname $(shell pwd))" \ | ||
-asmflags "all=-trimpath=$(shell dirname $(shell pwd))" \ | ||
-ldflags " \ | ||
-s \ | ||
-w \ | ||
-X '$(REPO)/internal/version.buildDate=$(BUILD_DATE)' \ | ||
-X '$(REPO)/internal/version.gitCommit=$(GIT_COMMIT)' \ | ||
-X '$(REPO)/internal/version.gitTreeState=$(GIT_TREE_STATE)' \ | ||
-X '$(REPO)/internal/version.gitVersion=$(GIT_VERSION)' \ | ||
-X '$(REPO)/internal/version.gitVersionMajor=$(GIT_VERSION_MAJOR)' \ | ||
-X '$(REPO)/internal/version.gitVersionMinor=$(GIT_VERSION_MINOR)' \ | ||
" \ | ||
|
||
.PHONY: all | ||
all: install | ||
|
||
.PHONY: clean | ||
clean: | ||
rm -rf bin dist | ||
|
||
.PHONY: lint | ||
lint: | ||
source ./scripts/fetch.sh; fetch golangci-lint $(GOLANGCI_LINT_VERSION) && ./bin/golangci-lint run | ||
|
||
.PHONY: test | ||
test: | ||
go test ./... | ||
|
||
.PHONY: build | ||
build: | ||
go build $(GO_BUILD_ARGS) -o bin/kubectl-lineage ./cmd/kubectl-lineage | ||
|
||
.PHONY: install | ||
install: build | ||
install bin/kubectl-lineage $(shell go env GOPATH)/bin | ||
|
||
.PHONY: release | ||
RELEASE_ARGS?=release --rm-dist | ||
release: | ||
source ./scripts/fetch.sh; fetch goreleaser $(GORELEASER_VERSION) && ./bin/goreleaser $(RELEASE_ARGS) | ||
|
||
.PHONY: release-snapshot | ||
RELEASE_SNAPSHOT_ARGS?=release --rm-dist --skip-publish --snapshot | ||
release-snapshot: | ||
source ./scripts/fetch.sh; fetch goreleaser $(GORELEASER_VERSION) && ./bin/goreleaser $(RELEASE_SNAPSHOT_ARGS) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#!/usr/bin/env bash | ||
|
||
ROOT=$(git rev-parse --show-toplevel) | ||
|
||
fetch() { | ||
local tool=$1; shift | ||
local ver=$1; shift | ||
|
||
local ver_cmd="" | ||
local tool_fetch_cmd="" | ||
case "$tool" in | ||
"golangci-lint") | ||
ver_cmd="${ROOT}/bin/golangci-lint --version 2>/dev/null | cut -d\" \" -f4" | ||
fetch_cmd="curl -sSfL \"https://raw.githubusercontent.com/golangci/golangci-lint/v${ver}/install.sh\" | sh -s -- -b \"${ROOT}/bin\" \"v${ver}\"" | ||
;; | ||
"goreleaser") | ||
ver_cmd="${ROOT}/bin/goreleaser --version 2>/dev/null | grep 'goreleaser version' | cut -d' ' -f3" | ||
fetch_cmd="curl -sSfL https://install.goreleaser.com/github.com/goreleaser/goreleaser.sh | sh -s -- -b \"${ROOT}/bin\" -d \"v${ver}\"" | ||
;; | ||
*) | ||
echo "unknown tool $tool" | ||
return 1 | ||
;; | ||
esac | ||
|
||
if [[ "${ver}" != "$(eval ${ver_cmd})" ]]; then | ||
echo "${tool} missing or not version '${ver}', downloading..." | ||
eval ${fetch_cmd} | ||
fi | ||
} |