Skip to content

Commit

Permalink
Maintenance (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
devfacet authored Dec 30, 2022
1 parent 6b925d8 commit 71e5ff3
Show file tree
Hide file tree
Showing 7 changed files with 117 additions and 110 deletions.
95 changes: 61 additions & 34 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
40 changes: 18 additions & 22 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,45 +2,41 @@ name: Test

on:
push:
branches: [ '*' ]
tags-ignore: [ '*' ]
branches: ["*"]
tags-ignore: ["*"]
pull_request:
branches: [ '*' ]
branches: ["*"]

workflow_dispatch:
inputs:
logLevel:
description: 'Log level'
default: 'info'
description: Log Level
default: info
type: choice
options:
- debug
- error
- fatal
- info
- panic
- warning
- debug
- error
- fatal
- info
- panic
- warning
environment:
description: Environment
default: test

jobs:

test:
runs-on: ubuntu-latest
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
with:
# https://github.com/actions/checkout/issues/100
fetch-depth: 0

- name: Install test tools
run: |
make test-tools
uses: actions/checkout@v3

- name: Run Tests
run: |
make init-tools
make test
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.DS_Store
.vscode
.vs
.vscode
Thumbs.db

*.exe
Expand All @@ -11,7 +11,7 @@ Thumbs.db

logs/
node_modules/
reports/
releases/
reports/
tmp/
vendor/
2 changes: 1 addition & 1 deletion LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2022 Fatih Cetinkaya (https://github.com/devfacet/streamy)
Copyright (c) 2022 Fatih Cetinkaya - https://github.com/devfacet/streamy

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
67 changes: 31 additions & 36 deletions Makefile
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
Expand All @@ -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'"; \
Expand All @@ -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
17 changes: 3 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,16 @@ See [streamy_test.go](streamy_test.go), [reader_test.go](reader_test.go), [progr
## Test

```shell
# Test everything:
# Run tests
make test

# For BDD development:
# It will open a new browser window. Make sure:
# 1. There is no errors on the terminal window.
# 2. There is no other open GoConvey page.
# Continuous testing
make test-ui

# Benchmarks
make test-benchmarks
```

## Release

```shell
# Update and commit CHANGELOG.md first (i.e. git add CHANGELOG.md && git commit -m "v1.0.0").
# Set GIT_TAG using semver (i.e. GIT_TAG=v1.0.0)
make release GIT_TAG=
```

## Contributing

See [CONTRIBUTING.md](CONTRIBUTING.md)
Expand All @@ -48,4 +37,4 @@ For the full copyright and license information, please view the LICENSE.txt file
[release-image]: https://img.shields.io/github/release/devfacet/streamy.svg?style=flat-square

[build-url]: https://github.com/devfacet/streamy/actions/workflows/test.yaml
[build-image]: https://github.com/devfacet/streamy/workflows/Test/badge.svg
[build-image]: https://github.com/devfacet/streamy/workflows/test.yaml/badge.svg
2 changes: 1 addition & 1 deletion go.mod
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

0 comments on commit 71e5ff3

Please sign in to comment.