Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CI: enforce changelog #965

Merged
merged 15 commits into from
Jul 13, 2020
6 changes: 5 additions & 1 deletion .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ steps:
- wget -qO- https://github.com/fossas/fossa-cli/releases/download/v1.0.11/fossa-cli_1.0.11_linux_amd64.tar.gz | tar xvz -C /go/bin/
- /go/bin/fossa analyze


- name: build
image: golang:1.13
commands:
Expand Down Expand Up @@ -123,6 +122,11 @@ steps:
commands:
- golangci-lint run --timeout 2m0s

- name: changelog
image: golang:1.13
commands:
- make check-changelog-drone

- name: license-check
image: golang:1.13
failure: ignore
Expand Down
13 changes: 13 additions & 0 deletions .github/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Configuration for update-docs - https://github.com/behaviorbot/update-docs

# Comment to be posted to on PRs that don't update documentation
updateDocsComment: >
Thanks for opening this pull request! The maintainers of this repository would appreciate it if you would create a [changelog](https://github.com/cs3org/reva/blob/master/changelog/README.md) item based on your changes.

updateDocsWhiteList:
- Tests-only
- tests-only
- Tests-Only

updateDocsTargetFiles:
- changelog/unreleased/
10 changes: 8 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ GIT_DIRTY=`git diff-index --quiet HEAD -- || echo "dirty-"`
VERSION=`git describe --always`
GO_VERSION=`go version | awk '{print $$3}'`

default: build test lint gen-doc
release: deps build test lint gen-doc
default: build test lint gen-doc check-changelog
release: deps build test lint gen-doc check-changelog

off:
GOPROXY=off
Expand Down Expand Up @@ -60,6 +60,12 @@ lint-ci:
gen-doc:
go run tools/generate-documentation/main.go

check-changelog:
go run tools/check-changelog/main.go

check-changelog-drone:
go run tools/check-changelog/main.go -repo origin

# to be run in CI platform
ci: build-ci test lint-ci

Expand Down
6 changes: 6 additions & 0 deletions changelog/unreleased/enforce-changelog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Enhancement: Enforce adding changelog in make and CI

When adding a feature or fixing a bug, a changelog needs to be specified,
failing which the build wouldn't pass.

https://github.com/cs3org/reva/pull/965
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,3 @@ trying to unmarshal the empty file.

https://github.com/cs3org/reva/issues/941
https://github.com/cs3org/reva/pull/940

57 changes: 57 additions & 0 deletions tools/check-changelog/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// Copyright 2018-2020 CERN
//
// 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.
//
// In applying this license, CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.

package main

import (
"errors"
"flag"
"log"
"os/exec"
"strings"
)

func main() {
repo := flag.String("repo", "", "the remote repo against which diff-index is to be derived")
flag.Parse()

branch := "master"
if *repo != "" {
branch = *repo + "/master"
}
cmd := exec.Command("git", "diff-index", branch, "--", "changelog/unreleased")
out, err := cmd.Output()
if err != nil {
log.Fatal(err)
}

var changelog bool
mods := strings.Split(string(out), "\n")

for _, m := range mods {
params := strings.Split(m, " ")
// The fifth param in the output of diff-index is always the status followed by optional score number
if len(params) >= 5 && params[4][0] == 'A' {
changelog = true
}
}

if !changelog {
log.Fatal(errors.New("No changelog added. Please create a changelog item based on your changes"))
}
}