forked from lunny/changelog
CI and Linter (#27)
Add S3 for master/releases Signed-off-by: jolheiser <john.olheiser@gmail.com> Move to arm64 for more RAM Signed-off-by: jolheiser <john.olheiser@gmail.com> Add lint to CI Signed-off-by: jolheiser <john.olheiser@gmail.com> Rename default to compliance and un-test releases Signed-off-by: jolheiser <john.olheiser@gmail.com> Test Signed-off-by: jolheiser <john.olheiser@gmail.com> Initial work Signed-off-by: jolheiser <john.olheiser@gmail.com> Co-authored-by: jolheiser <john.olheiser@gmail.com> Reviewed-on: https://gitea.com/gitea/changelog/pulls/27 Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com> Reviewed-by: 6543 <6543@noreply.gitea.io>
This commit is contained in:
parent
747f3cb162
commit
b707352bf9
102
.drone.yml
102
.drone.yml
@ -1,20 +1,32 @@
|
||||
---
|
||||
kind: pipeline
|
||||
name: default
|
||||
name: compliance
|
||||
|
||||
platform:
|
||||
os: linux
|
||||
arch: amd64
|
||||
arch: arm64
|
||||
|
||||
trigger:
|
||||
event:
|
||||
- pull_request
|
||||
|
||||
steps:
|
||||
|
||||
- name: build
|
||||
pull: always
|
||||
image: golang:1.13
|
||||
environment:
|
||||
GOPROXY: https://goproxy.cn,direct
|
||||
commands:
|
||||
- go test -race
|
||||
- go test -race ./...
|
||||
- go build
|
||||
|
||||
- name: check
|
||||
pull: always
|
||||
image: golang:1.13
|
||||
environment:
|
||||
GOPROXY: https://goproxy.cn,direct
|
||||
commands:
|
||||
- make lint
|
||||
|
||||
- name: discord
|
||||
pull: always
|
||||
@ -32,6 +44,86 @@ steps:
|
||||
- changed
|
||||
- failure
|
||||
|
||||
---
|
||||
kind: pipeline
|
||||
name: release
|
||||
|
||||
platform:
|
||||
os: linux
|
||||
arch: amd64
|
||||
|
||||
trigger:
|
||||
branch:
|
||||
- master
|
||||
- master
|
||||
event:
|
||||
- push
|
||||
- tag
|
||||
|
||||
steps:
|
||||
- name: fetch-tags
|
||||
pull: always
|
||||
image: docker:git
|
||||
commands:
|
||||
- git fetch --tags --force
|
||||
|
||||
- name: release
|
||||
pull: always
|
||||
image: techknowlogick/xgo:latest
|
||||
environment:
|
||||
GOPROXY: https://goproxy.cn,direct
|
||||
commands:
|
||||
- export PATH=$PATH:$GOPATH/bin
|
||||
- make release
|
||||
|
||||
- name: bucket-master
|
||||
pull: always
|
||||
image: plugins/s3:1
|
||||
settings:
|
||||
acl: public-read
|
||||
bucket: releases
|
||||
endpoint: https://storage.gitea.io
|
||||
path_style: true
|
||||
source: "dist/*"
|
||||
strip_prefix: dist/
|
||||
target: /changelog-tool/master
|
||||
environment:
|
||||
AWS_ACCESS_KEY_ID:
|
||||
from_secret: aws_access_key_id
|
||||
AWS_SECRET_ACCESS_KEY:
|
||||
from_secret: aws_secret_access_key
|
||||
when:
|
||||
event:
|
||||
- push
|
||||
|
||||
- name: bucket-tag
|
||||
pull: always
|
||||
image: plugins/s3:1
|
||||
settings:
|
||||
acl: public-read
|
||||
bucket: releases
|
||||
endpoint: https://storage.gitea.io
|
||||
path_style: true
|
||||
source: "dist/*"
|
||||
strip_prefix: dist/
|
||||
target: "/changelog-tool/${DRONE_TAG##v}"
|
||||
environment:
|
||||
AWS_ACCESS_KEY_ID:
|
||||
from_secret: aws_access_key_id
|
||||
AWS_SECRET_ACCESS_KEY:
|
||||
from_secret: aws_secret_access_key
|
||||
when:
|
||||
event:
|
||||
- tag
|
||||
|
||||
- name: gitea
|
||||
pull: always
|
||||
image: plugins/gitea-release:1
|
||||
settings:
|
||||
api_key:
|
||||
from_secret: gitea_token
|
||||
base_url: https://gitea.com
|
||||
files:
|
||||
- "dist/*"
|
||||
when:
|
||||
event:
|
||||
- tag
|
24
.golangci.yml
Normal file
24
.golangci.yml
Normal file
@ -0,0 +1,24 @@
|
||||
linters:
|
||||
enable:
|
||||
- deadcode
|
||||
- dogsled
|
||||
- dupl
|
||||
- errcheck
|
||||
- funlen
|
||||
- gocognit
|
||||
- goconst
|
||||
- gocritic
|
||||
- gocyclo
|
||||
- gofmt
|
||||
- golint
|
||||
- gosimple
|
||||
- govet
|
||||
- maligned
|
||||
- misspell
|
||||
- prealloc
|
||||
- staticcheck
|
||||
- structcheck
|
||||
- typecheck
|
||||
- unparam
|
||||
- unused
|
||||
- varcheck
|
68
Makefile
Normal file
68
Makefile
Normal file
@ -0,0 +1,68 @@
|
||||
DIST := dist
|
||||
GO ?= go
|
||||
|
||||
ifneq ($(DRONE_TAG),)
|
||||
SHORT_VERSION ?= $(subst v,,$(DRONE_TAG))
|
||||
LONG_VERSION ?= $(SHORT_VERSION)
|
||||
else
|
||||
SHORT_VERSION ?= $(shell git describe --tags --always --abbrev=0 | sed 's/-/+/' | sed 's/^v//')
|
||||
LONG_VERSION ?= $(shell git describe --tags --always | sed 's/-/+/' | sed 's/^v//')
|
||||
endif
|
||||
|
||||
LDFLAGS := $(LDFLAGS) -X "main.Version=$(LONG_VERSION)"
|
||||
|
||||
.PHONY: build
|
||||
build: generate
|
||||
$(GO) build -ldflags '-s -w $(LDFLAGS)'
|
||||
|
||||
.PHONY: generate
|
||||
generate:
|
||||
$(GO) generate ./...
|
||||
|
||||
.PHONY: lint
|
||||
lint:
|
||||
@hash golangci-lint > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
|
||||
export BINARY="golangci-lint"; \
|
||||
curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(go env GOPATH)/bin v1.23.1; \
|
||||
fi
|
||||
golangci-lint run --timeout 5m
|
||||
|
||||
.PHONY: fmt
|
||||
fmt:
|
||||
go fmt ./...
|
||||
|
||||
.PHONY: release
|
||||
release: release-dirs check-xgo release-windows release-linux release-darwin release-compress release-check
|
||||
|
||||
.PHONY: release-dirs
|
||||
release-dirs:
|
||||
mkdir -p $(DIST)/
|
||||
|
||||
.PHONY: check-xgo
|
||||
check-xgo:
|
||||
@hash xgo > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
|
||||
$(GO) get -u src.techknowlogick.com/xgo; \
|
||||
fi
|
||||
|
||||
.PHONY: release-linux
|
||||
release-linux:
|
||||
xgo -dest $(DIST)/ -targets 'linux/amd64,linux/386,linux/arm-5,linux/arm-6,linux/arm64,linux/mips64le,linux/mips,linux/mipsle' -out changelog-$(SHORT_VERSION) .
|
||||
|
||||
.PHONY: release-windows
|
||||
release-windows:
|
||||
xgo -dest $(DIST)/ -targets 'windows/*' -out changelog-$(SHORT_VERSION) .
|
||||
|
||||
.PHONY: release-darwin
|
||||
release-darwin:
|
||||
xgo -dest $(DIST)/ -targets 'darwin/*' -out changelog-$(SHORT_VERSION) .
|
||||
|
||||
.PHONY: release-check
|
||||
release-check:
|
||||
cd $(DIST)/; for file in `find . -type f -name "*"`; do echo "checksumming $${file}" && $(SHASUM) `echo $${file} | sed 's/^..//'` > $${file}.sha256; done;
|
||||
|
||||
.PHONY: release-compress
|
||||
release-compress:
|
||||
@hash gxz > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
|
||||
go get -u github.com/ulikunitz/xz/cmd/gxz; \
|
||||
fi
|
||||
cd $(DIST)/; for file in `find . -type f -name "*"`; do echo "compressing $${file}" && gxz -k -9 $${file}; done;
|
@ -6,6 +6,7 @@ package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"regexp"
|
||||
|
||||
"code.gitea.io/changelog/config"
|
||||
"code.gitea.io/changelog/service"
|
||||
@ -13,11 +14,16 @@ import (
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
var Generate = &cli.Command{
|
||||
Name: "generate",
|
||||
Usage: "Generates a changelog",
|
||||
Action: runGenerate,
|
||||
}
|
||||
var (
|
||||
Generate = &cli.Command{
|
||||
Name: "generate",
|
||||
Usage: "Generates a changelog",
|
||||
Action: runGenerate,
|
||||
}
|
||||
labels = make(map[string]string)
|
||||
entries = make(map[string][]service.PullRequest)
|
||||
defaultGroup string
|
||||
)
|
||||
|
||||
func runGenerate(cmd *cli.Context) error {
|
||||
cfg, err := config.New(ConfigPathFlag)
|
||||
@ -25,22 +31,7 @@ func runGenerate(cmd *cli.Context) error {
|
||||
return err
|
||||
}
|
||||
|
||||
labels := make(map[string]string)
|
||||
entries := make(map[string][]service.PullRequest)
|
||||
var defaultGroup string
|
||||
for _, g := range cfg.Groups {
|
||||
entries[g.Name] = []service.PullRequest{}
|
||||
for _, l := range g.Labels {
|
||||
labels[l] = g.Name
|
||||
}
|
||||
if g.Default {
|
||||
defaultGroup = g.Name
|
||||
}
|
||||
}
|
||||
|
||||
if defaultGroup == "" {
|
||||
defaultGroup = cfg.Groups[len(cfg.Groups)-1].Name
|
||||
}
|
||||
processGroups(cfg.Groups)
|
||||
|
||||
s, err := service.New(cfg.Service, cfg.Repo, cfg.BaseURL, MilestoneFlag, TokenFlag)
|
||||
if err != nil {
|
||||
@ -52,29 +43,7 @@ func runGenerate(cmd *cli.Context) error {
|
||||
return err
|
||||
}
|
||||
|
||||
PRLoop: // labels in Go, let's get old school
|
||||
for _, pr := range prs {
|
||||
if pr.Index < AfterFlag {
|
||||
continue
|
||||
}
|
||||
|
||||
var label string
|
||||
for _, lb := range pr.Labels {
|
||||
if cfg.SkipRegex != nil && cfg.SkipRegex.MatchString(lb.Name) {
|
||||
continue PRLoop
|
||||
}
|
||||
|
||||
if g, ok := labels[lb.Name]; ok && len(label) == 0 {
|
||||
label = g
|
||||
}
|
||||
}
|
||||
|
||||
if len(label) > 0 {
|
||||
entries[label] = append(entries[label], pr)
|
||||
} else {
|
||||
entries[defaultGroup] = append(entries[defaultGroup], pr)
|
||||
}
|
||||
}
|
||||
processPRs(prs, cfg.SkipRegex)
|
||||
|
||||
fmt.Println(title)
|
||||
for _, g := range cfg.Groups {
|
||||
@ -99,3 +68,45 @@ PRLoop: // labels in Go, let's get old school
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func processGroups(groups []config.Group) {
|
||||
for _, g := range groups {
|
||||
entries[g.Name] = []service.PullRequest{}
|
||||
for _, l := range g.Labels {
|
||||
labels[l] = g.Name
|
||||
}
|
||||
if g.Default {
|
||||
defaultGroup = g.Name
|
||||
}
|
||||
}
|
||||
|
||||
if defaultGroup == "" {
|
||||
defaultGroup = groups[len(groups)-1].Name
|
||||
}
|
||||
}
|
||||
|
||||
func processPRs(prs []service.PullRequest, skip *regexp.Regexp) {
|
||||
PRLoop: // labels in Go, let's get old school
|
||||
for _, pr := range prs {
|
||||
if pr.Index < AfterFlag {
|
||||
continue
|
||||
}
|
||||
|
||||
var label string
|
||||
for _, lb := range pr.Labels {
|
||||
if skip != nil && skip.MatchString(lb.Name) {
|
||||
continue PRLoop
|
||||
}
|
||||
|
||||
if g, ok := labels[lb.Name]; ok && len(label) == 0 {
|
||||
label = g
|
||||
}
|
||||
}
|
||||
|
||||
if len(label) > 0 {
|
||||
entries[label] = append(entries[label], pr)
|
||||
} else {
|
||||
entries[defaultGroup] = append(entries[defaultGroup], pr)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
4
main.go
4
main.go
@ -15,9 +15,9 @@ import (
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
const (
|
||||
var (
|
||||
// Version of changelog
|
||||
Version = "0.2"
|
||||
Version = "development"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
@ -112,7 +112,7 @@ func (ge *Gitea) Contributors() (ContributorList, error) {
|
||||
}
|
||||
|
||||
contributors := make(ContributorList, 0, len(contributorsMap))
|
||||
for contributor, _ := range contributorsMap {
|
||||
for contributor := range contributorsMap {
|
||||
contributors = append(contributors, Contributor{
|
||||
Name: contributor,
|
||||
Profile: fmt.Sprintf("%s/%s", ge.BaseURL, contributor),
|
||||
|
@ -101,7 +101,7 @@ func (gh *GitHub) Contributors() (ContributorList, error) {
|
||||
}
|
||||
|
||||
contributors := make(ContributorList, 0, len(contributorsMap))
|
||||
for contributor, _ := range contributorsMap {
|
||||
for contributor := range contributorsMap {
|
||||
contributors = append(contributors, Contributor{
|
||||
Name: contributor,
|
||||
Profile: fmt.Sprintf("https://github.com/%s", contributor),
|
||||
|
Loading…
Reference in New Issue
Block a user