-
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.
- Loading branch information
Showing
7 changed files
with
117 additions
and
110 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 |
---|---|---|
|
@@ -5,62 +5,89 @@ permissions: | |
|
||
on: | ||
push: | ||
tags: [ 'v*.*.*' ] | ||
tags: ["v*.*.*"] | ||
|
||
workflow_dispatch: | ||
inputs: | ||
releaseTag: | ||
description: 'Existing git tag to be released (i.e. v1.0.0)' | ||
description: Existing git tag (i.e. v0.1.0) | ||
required: true | ||
dryRun: | ||
description: Dryrun | ||
default: "true" | ||
type: choice | ||
options: | ||
- "true" | ||
- "false" | ||
|
||
jobs: | ||
check: | ||
runs-on: ubuntu-latest | ||
if: (github.event_name == 'workflow_dispatch' || (github.event_name == 'push' && github.ref_type == 'tag')) | ||
outputs: | ||
RELEASE_TAG: ${{ steps.check-tag.outputs.RELEASE_TAG }} | ||
REPO_NAME: ${{ steps.check-tag.outputs.REPO_NAME }} | ||
steps: | ||
- name: Check release tag | ||
id: check-tag | ||
uses: actions/github-script@v6 | ||
with: | ||
script: | | ||
console.log('github.event_name', '${{ github.event_name }}') | ||
console.log('github.ref_type', '${{ github.ref_type }}') | ||
let releaseTag | ||
if('${{ github.event_name }}' == 'workflow_dispatch') { | ||
releaseTag = '${{ github.event.inputs.releaseTag }}' | ||
} else if('${{ github.event_name }}' == 'push' && '${{ github.ref_type }}' == 'tag') { | ||
releaseTag = '${{ github.ref }}'.replace(/^refs\/tags\//, ''); | ||
} else { | ||
console.log('no semver tag found') | ||
return | ||
} | ||
console.log('RELEASE_TAG', releaseTag) | ||
core.setOutput('RELEASE_TAG', releaseTag) | ||
console.log('REPO_NAME', context.repo.repo) | ||
core.setOutput('REPO_NAME', context.repo.repo) | ||
- name: Check tag semver | ||
id: check-tag-semver | ||
uses: madhead/semver-utils@cd1ddc05fca0b1514b697c2ca9fe88d4df4000ae # latest as of 2022-11-11 | ||
if: ${{ steps.check-tag.outputs.RELEASE_TAG != '' }} | ||
with: | ||
version: ${{ steps.check-tag.outputs.RELEASE_TAG }} | ||
lenient: false # fail on error | ||
|
||
test: | ||
runs-on: ubuntu-latest | ||
needs: check | ||
if: ${{ needs.check.outputs.RELEASE_TAG != '' }} | ||
outputs: | ||
RELEASE_TAG: ${{ needs.check.outputs.RELEASE_TAG }} | ||
steps: | ||
- name: Setup Go environment | ||
uses: actions/setup-go@v2 | ||
uses: actions/setup-go@v3 | ||
with: | ||
go-version: '1.17' | ||
go-version: "1.19" | ||
|
||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
uses: actions/checkout@v3 | ||
if: ${{ needs.check.outputs.RELEASE_TAG != '' }} | ||
with: | ||
# https://github.com/actions/checkout/issues/100 | ||
fetch-depth: 0 | ||
ref: ${{ needs.check.outputs.RELEASE_TAG }} | ||
fetch-depth: 0 # Ref: https://github.com/actions/checkout/issues/100 | ||
|
||
- name: Install test tools | ||
run: | | ||
make test-tools | ||
- name: Run Tests | ||
- name: Run tests | ||
run: | | ||
make init-tools | ||
make test | ||
release: | ||
runs-on: ubuntu-latest | ||
needs: test | ||
outputs: | ||
RELEASE_TAG: ${{ steps.env.outputs.RELEASE_TAG }} | ||
if: ${{ needs.test.outputs.RELEASE_TAG != '' }} | ||
steps: | ||
- name: Setup ENV | ||
id: env | ||
run: | | ||
if [[ "${GITHUB_EVENT_NAME}" == "workflow_dispatch" ]]; then | ||
RELEASE_TAG=${{ github.event.inputs.releaseTag }} | ||
elif [[ "${GITHUB_REF}" == refs/tags/v*.*.* ]]; then | ||
RELEASE_TAG=${GITHUB_REF/refs\/tags\//} | ||
fi | ||
if [[ "${RELEASE_TAG}" != v*.*.* ]]; then | ||
echo "invalid release tag (${RELEASE_TAG} - ${GITHUB_REF}), only semver is allowed (i.e v*.*.*)" | ||
exit 1 | ||
fi | ||
echo "::set-output name=RELEASE_TAG::${RELEASE_TAG}" | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
|
||
- name: Release | ||
uses: softprops/[email protected] | ||
- name: Make a release | ||
uses: softprops/action-gh-release@de2c0eb89ae2a093876385947365aca7b0e5f844 # v0.1.15 | ||
if: github.event.inputs.dryRun != 'true' | ||
with: | ||
tag_name: ${{ steps.env.outputs.RELEASE_TAG }} | ||
tag_name: ${{ needs.test.outputs.RELEASE_TAG }} |
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
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,6 +1,7 @@ | ||
# Init vars. | ||
# Init vars | ||
MAKEFILE := $(lastword $(MAKEFILE_LIST)) | ||
BASENAME := $(shell basename "$(PWD)") | ||
SHELL := /bin/bash | ||
|
||
.PHONY: help | ||
all: help | ||
|
@@ -11,20 +12,16 @@ help: Makefile | |
@sed -n 's/^##//p' $< | sed -e 's/^/ /' | sort | ||
@echo | ||
|
||
## test Run gofmt, golint, staticcheck, go vet and go test. | ||
## test Run tests, formatting, etc. | ||
test: | ||
@$(MAKE) -f $(MAKEFILE) check-tools | ||
|
||
$(eval FMT=$(shell find . -type f -name '*.go' | grep -v -E '^./vendor|^./third_party' | xargs -L1 dirname | sort | uniq | xargs gofmt -l | wc -l | tr -d ' ')) | ||
@if [ "$(FMT)" != "0" ]; then \ | ||
echo "some files are not formatted, run 'make fmt'"; \ | ||
exit 1; \ | ||
fi | ||
|
||
$(eval LINT=$(shell find . -type f -name '*.go' | grep -v -E '^./vendor|^./third_party' | xargs -L1 dirname | sort | uniq | xargs golint | wc -l | tr -d ' ')) | ||
@if [ "$(LINT)" != "0" ]; then \ | ||
echo "some files have linting errors, run 'make lint'"; \ | ||
exit 1; \ | ||
fi | ||
|
||
$(eval STATICCHECK=$(shell find . -type f -name '*.go' | grep -v -E '^./vendor|^./third_party' | xargs -L1 dirname | sort | uniq | xargs staticcheck | wc -l | tr -d ' ')) | ||
@if [ "$(STATICCHECK)" != "0" ]; then \ | ||
echo "some files have staticcheck errors, run 'make staticcheck'"; \ | ||
|
@@ -39,60 +36,58 @@ test: | |
|
||
@$(MAKE) -f $(MAKEFILE) test-go | ||
|
||
## test-go Run go test | ||
## test-go Run go test | ||
test-go: | ||
@find . -type f -name '*.go' | grep -v -E '^./vendor|^./third_party' | xargs -L1 dirname | sort | uniq | xargs go test -v -race | ||
@find . -type f -name '*.go' | grep -v -E '^./vendor|^./third_party|^./_examples' | xargs -L1 dirname | sort | uniq | xargs go test -v -race | ||
|
||
## test-benchmarks Run go benchmarks | ||
## test-benchmarks Run go benchmarks | ||
test-benchmarks: | ||
@find . -type f -name '*.go' | grep -v -E '^./vendor|^./third_party' | xargs -L1 dirname | sort | uniq | xargs go test -benchmem -bench | ||
@find . -type f -name '*.go' | grep -v -E '^./vendor|^./third_party|^./_examples' | xargs -L1 dirname | sort | uniq | xargs go test -benchmem -bench | ||
|
||
## test-ui Launch test UI | ||
## test-ui Launch test UI | ||
test-ui: | ||
$(eval GOCONVEY_PATH=$(shell which goconvey)) | ||
@if [ -z "$(GOCONVEY_PATH)" ]; then \ | ||
GO111MODULE=off go get github.com/smartystreets/goconvey; \ | ||
fi | ||
goconvey -port 8088 -excludedDirs vendor,node_modules,assets | ||
goconvey -port 8088 -excludedDirs vendor,node_modules,assets,_examples | ||
|
||
## test-clean Clean test cache | ||
## test-clean Clean test cache | ||
test-clean: | ||
@go clean -testcache | ||
|
||
## test-tools Install test tools | ||
test-tools: | ||
@# golint is deprecated and frozen. | ||
$(eval GOLINT_PATH=$(shell which golint)) | ||
@if [ -z "$(GOLINT_PATH)" ]; then \ | ||
GO111MODULE=off go get golang.org/x/lint/golint; \ | ||
fi | ||
|
||
$(eval STATICCHECK_PATH=$(shell which staticcheck)) | ||
@if [ -z "$(STATICCHECK_PATH)" ]; then \ | ||
go install honnef.co/go/tools/cmd/[email protected]; \ | ||
fi | ||
|
||
## fmt Run formating | ||
## fmt Run formating | ||
fmt: | ||
@find . -type f -name '*.go' | grep -v -E '^./vendor|^./third_party' | xargs -L1 dirname | sort | uniq | xargs gofmt -l | ||
|
||
## lint Run linting | ||
lint: | ||
@find . -type f -name '*.go' | grep -v -E '^./vendor|^./third_party' | xargs -L1 dirname | sort | uniq | xargs golint | ||
|
||
## staticcheck Run staticcheck | ||
## staticcheck Run staticcheck | ||
staticcheck: | ||
@find . -type f -name '*.go' | grep -v -E '^./vendor|^./third_party' | xargs -L1 dirname | sort | uniq | xargs staticcheck | ||
|
||
## vet Run vetting | ||
## vet Run vetting | ||
vet: | ||
@find . -type f -name '*.go' | grep -v -E '^./vendor' | xargs -L1 dirname | sort | uniq | xargs go vet 2>&1 | ||
|
||
## release Release a version | ||
## release Release a version | ||
release: | ||
@if [ "$(shell echo \$${GIT_TAG:0:1})" != "v" ]; then \ | ||
echo "invalid GIT_TAG (${GIT_TAG}). Try something like 'make release GIT_TAG=v1.0.0'"; \ | ||
exit 1; \ | ||
fi | ||
git tag -a $(GIT_TAG) -m "$(GIT_TAG)" | ||
git push --follow-tags | ||
|
||
## init-tools Initialize tools | ||
init-tools: | ||
$(eval STATICCHECK_PATH=$(shell which staticcheck)) | ||
@if [ -z "$(STATICCHECK_PATH)" ]; then \ | ||
go install honnef.co/go/tools/cmd/staticcheck@latest; \ | ||
fi | ||
|
||
## check-tools Check tools | ||
check-tools: | ||
$(eval STATICCHECK_PATH=$(shell which staticcheck)) | ||
@if [ -z "$(STATICCHECK_PATH)" ]; then \ | ||
echo "docker binary not found"; \ | ||
exit 1; \ | ||
fi |
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,3 +1,3 @@ | ||
module github.com/devfacet/streamy | ||
|
||
go 1.17 | ||
go 1.19 |