Skip to content

Commit

Permalink
完善ci (#8)
Browse files Browse the repository at this point in the history
* 完善ci

* 添加license
  • Loading branch information
hookokoko authored Oct 25, 2023
1 parent 56fbe58 commit c92c5b1
Show file tree
Hide file tree
Showing 38 changed files with 685 additions and 88 deletions.
23 changes: 23 additions & 0 deletions .github/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/sh
# Copyright 2021 ecodeclub
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# To use, store as .git/hooks/pre-commit inside your repository and make sure
# it has execute permissions.
#
# This script does not handle file names that contain spaces.

# Pre-commit configuration

exit 0
50 changes: 50 additions & 0 deletions .github/pre-push
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/bin/sh
# Copyright 2021 ecodeclub
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# git test pre-push hook
#
# To use, store as .git/hooks/pre-push inside your repository and make sure
# it has execute permissions.
#
# This script does not handle file names that contain spaces.

# Pre-push configuration
remote=$1
url=$2
echo >&2 "Try pushing $2 to $1"

TEST="go test ./... -race -cover -failfast"
LINTER="golangci-lint run -c .golangci.yml"

# Run test and return if failed
printf "Running go test..."
$TEST
RESULT=$?
if [ $RESULT -ne 0 ]; then
echo >&2 "$TEST"
echo >&2 "Check code to pass test."
exit 1
fi

# Run linter and return if failed
printf "Running go linter..."
$LINTER
RESULT=$?
if [ $RESULT -ne 0 ]; then
echo >&2 "$LINTER"
echo >&2 "Check code to pass linter."
exit 1
fi

exit 0
44 changes: 44 additions & 0 deletions .github/workflows/go-fmt.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Copyright 2021 ecodeclub
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

name: Format Go code

on:
push:
branches: [ main,dev ]
pull_request:
branches: [ main,dev ]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: ">=1.20.0"

- name: Install goimports
run: |
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest && \
go install golang.org/x/tools/cmd/goimports@latest
- name: Check
run: |
make check
if [ -n "$(git status --porcelain)" ]; then
echo >&2 "错误: 请在本地运行命令'make check'后再提交."
exit 1
fi
40 changes: 40 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Copyright 2021 ecodeclub
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

name: Go

on:
push:
branches: [ dev ]
pull_request:
branches: [ dev ]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: ">=1.21.0"

- name: Build
run: go build -v ./...

- name: Test
run: go test -race -coverprofile=cover.out -v ./...

- name: Post Coverage
uses: codecov/codecov-action@v3
57 changes: 57 additions & 0 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Copyright 2021 ecodeclub
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

name: golangci-lint
on:
push:
branches: [dev, main]
pull_request:
branches: [dev, main]
permissions:
contents: read
# Optional: allow read access to pull request. Use with `only-new-issues` option.
pull-requests: read
jobs:
golangci:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v3
with:
go-version: ">=1.20.0"
- uses: actions/checkout@v4
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
# Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
version: latest

# Optional: working directory, useful for monorepos
# working-directory: somedir

# Optional: golangci-lint command line arguments.
# args: -c .golangci.yml

# Optional: show only new issues if it's a pull request. The default value is `false`.
only-new-issues: true

# Optional: if set to true then the all caching functionality will be complete disabled,
# takes precedence over all other caching options.
# skip-cache: true

# Optional: if set to true then the action don't cache or restore ~/go/pkg.
# skip-pkg-cache: true

# Optional: if set to true then the action don't cache or restore ~/.cache/go-build.
# skip-build-cache: true
28 changes: 28 additions & 0 deletions .github/workflows/license.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Copyright 2021 ecodeclub
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

name: Check License Lines
on:
pull_request:
types: [opened, synchronize, reopened, labeled, unlabeled]
branches:
- main
- dev
jobs:
check-license-lines:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: Check License Lines
uses: kt3k/[email protected]
28 changes: 0 additions & 28 deletions .github/workflows/notify-go.yml

This file was deleted.

18 changes: 18 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Copyright 2021 ecodeclub
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

run:
go: '1.21'
skip-dirs:
- .idea
5 changes: 5 additions & 0 deletions .licenserc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"**/*.go": "// Copyright 2021 ecodeclub",
"**/*.{yml}": "# Copyright 2021 ecodeclub",
"**/*.sh": "# Copyright 2021 ecodeclub"
}
29 changes: 29 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
.PHONY: bench
bench:
@go test -bench=. -benchmem ./...

.PHONY: ut
ut:
@go test -race ./... -failfast

.PHONY: setup
setup:
@sh ./script/setup.sh

.PHONY: fmt
fmt:
@goimports -l -w $$(find . -type f -name '*.go' -not -path "./.idea/*")

.PHONY: lint
lint:
@golangci-lint run -c .golangci.yml

.PHONY: tidy
tidy:
@go mod tidy -v

.PHONY: check
check:
@$(MAKE) fmt
@$(MAKE) tidy
@$(MAKE) lint
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[![Go](https://github.com/hookokoko/notify-go_dev/actions/workflows/notify-go.yml/badge.svg?branch=dev)](https://github.com/hookokoko/notify-go_dev/actions/workflows/notify-go.yml)
[![Go](https://github.com/hookokoko/notify-go_dev/actions/workflows/go.yml/badge.svg?branch=dev)](https://github.com/hookokoko/notify-go_dev/actions/workflows/notify-go.yml)
[![codecov](https://codecov.io/github/hookokoko/notify-go_dev/graph/badge.svg?token=H9D9S5Y2VM)](https://codecov.io/github/hookokoko/notify-go_dev)
# notify-go

Expand Down
14 changes: 14 additions & 0 deletions channel/channel.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// Copyright 2021 ecodeclub
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package channel

import (
Expand Down
14 changes: 14 additions & 0 deletions channel/email/email.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// Copyright 2021 ecodeclub
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package email

import (
Expand Down
Loading

0 comments on commit c92c5b1

Please sign in to comment.