Giter VIP home page Giter VIP logo

go-changelog's Introduction

go-changelog

go-changelog is a library and a set of binaries for working with changelog generation, written in Go.

The underlying strategy is to have a directory committed as part of the git repo you're generating a changelog for--by convention, .changelog is used, but the tool doesn't care what it's called or where it is. Inside that directory, each unit of change--almost always a pull request--has a file named after the unit of change. For example, a PR would include a .changelog/PR#.txt file, where PR# is the unique ID for the PR.

Because each PR or unit of change has its own file, you should never encounter merge conflicts for changelog entries.

The tool then takes two commits for the repository--specified by any valid git reference--and compiles a list of the files present in the later commit that aren't present in the earlier commit. These are assumed to accurately reflect the changes that have been added between the two commits.

Installation

Binaries

To run the command line binaries, use Go to build the commands. For example:

$ go install github.com/hashicorp/go-changelog/cmd/changelog-pr-body-check@latest

Docker

A Dockerfile is provided that will build an image containing the binaries. You can either run this container directly, or you can build an image sourced from it that specifies the environment variables and entrypoint. In the future, when go-changelog has config files, this will be how you can add your config files.

FROM hashicorpdev/go-changelog

ENV GITHUB_REPO=myrepo
ENV GITHUB_OWNER=myorg

# Maybe leave this one out and specify it with -e
ENV GITHUB_TOKEN=foo123abc

ENTRYPOINT ["/go-changelog/changelog-pr-body-check"]

Usage

For using the go-changelog library, please see go.dev. For using the specific binaries, please see the README files in their directories.

Change File Formatting

The files in your directory describe the changes that will be used to generate the changelog. Their contents should have the following formatting:

```release-note:TYPE
ENTRY
```

Where TYPE is the type of release note entry this is. This is usually "bug", "enhancement", etc. The tool does not prescribe a list of types to choose from; whatever you enter will be available to you when generating the changelog.

ENTRY is the body of the changelog entry, and should describe the changes that were made. This is used as free-text input and will be returned to you as it is entered when generating the changelog.

Sometimes PRs have multiple changelog entries associated with them. In this case, use multiple blocks.

```release-note:deprecation
Deprecated the `foo` interface, please use the `bar` interface instead.
```

```release-note:enhancement
Added the `bar` interface.
```

Best Practices

Keep changelog entries with code change commits

This system works under the assumption that changelog entries will always be kept with the code they're describing changes to. So it works best if the code and its changelog entry appear in the same commit. This means cherry-picks that move the code around will make sure to bring the changelog entries with it and will keep the changelog correct.

Using squash merges makes this easier.

Lean on automation

A sample changelog-check binary is included in the cmd directory to show how a GitHub PR can be checked to ensure that a changelog entry is attached to the PR. Lean on automation to guard against forgetting changelog entries when submitting PRs.

You can also have bots generate these files from PR bodies--when a PR body is updated, have a bot push a commit updating the changelog entry as well. The markdown code blocks can be easily parsed out of the PR body using the NotesFromEntry function in the changelog package, and re-formatted into a file for the commit. This means users don't need to mess with git to update changelog entries.

Shortcomings

Immutable changelog entries

Once a changelog entry is merged, it's hard to mutate it and make sure the commit updating it stays with the code. It's not impossible--you just need to remember to always cherrypick both commits--but it is harder. It is recommended that you use automation and PR review to make sure you're happy with the changelog entry before merging, as much as possible, to keep these situations limited.

Silent failure when no changelog entry is set

If a change forgets to include a changelog entry at all, the tool will ignore it completely. PR-based tools can shout loudly that a PR did not include a change, but this system does not have that capability without expecting every commit to have a changelog entry associated with it, which seems unreasonable.

It is recommended to use automation to prevent changes without changelog entries before they're merged, to ensure every change gets an entry.

Why

Changelogs are an important interface for helping users be aware of development efforts and behavioral changes in software. Writing good changelogs is tricky.

  • Writing changelogs by hand inevitably leads to people forgetting to include things in the changelog.
  • Basing changelog entries on commit messages conflates two audiences; commit messages are for developers and maintainers and should be directed towards them, changelog entries are directed towards users and should be written in the terminology they understand and use.
  • Writing changelogs in PR bodies is quick, easy, and allows them to be part of the PR review process, but PR bodies aren't stored in the repository itself (meaning they can't be easily backed up, etc.) and makes it harder to keep changelogs with the code they describe as that code is cherry-picked, backported, and merged across branches.

go-changelog prioritises making it easy to generate correct changelogs no matter what shenanigans you engaged in to build the branch you're releasing from. It also prioritises flexibility around workflows and changelog formatting.

Prior Art

This package is based on a bunch of experiments with the Google Cloud Platform Terraform provider and the lessons learned while generating it. It is also based on prior art in the community:

go-changelog's People

Contributors

bflad avatar chapmanc avatar dadgar avatar dependabot[bot] avatar dhiaayachi avatar eculver avatar hanshasselberg avatar hashicorp-copywrite[bot] avatar jar-b avatar maxb avatar mikemorris avatar nathancoleman avatar paddycarver avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

go-changelog's Issues

cmd/changelog-pr-body-check: Go 1.16 Errors

Submitting a fix for this shortly as it is a valid issue, although the underlying behavior should be the same using %s:

$ go version
go version go1.16.3 darwin/amd64
$ go test ./cmd/changelog-pr-body-check
# github.com/hashicorp/go-changelog/cmd/changelog-pr-body-check
cmd/changelog-pr-body-check/main.go:22:3: Fatalf call has error-wrapping directive %w
cmd/changelog-pr-body-check/main.go:48:3: Fatalf call has error-wrapping directive %w
cmd/changelog-pr-body-check/main.go:69:4: Fatalf call has error-wrapping directive %w
cmd/changelog-pr-body-check/main.go:111:4: Fatalf call has error-wrapping directive %w

Support for Github HTTPS compatibility

Spent a lot of time trying to figure out why changelog entry was not working. Took my teammate time to figure it out mainly from looking through the code base to see that a git url would work and not an HTTPS url. Support should probably be made for both or at least be mentioned somewhere in the documentation.

QUICK FIX: git remote set-url origin [email protected]:hashicorp/terraform-provider-helm.git will most likely solve many peoples issues

Support for Managing Existing Changelog File

Description

Currently, changelog-build covers the case of building a CHANGELOG section for a current release. It would be great if there was the ability to manage an existing CHANGELOG file to add that section.

For example, the Terraform AWS Provider uses a script to build an updated CHANGELOG:

  • Leave top header ("Unreleased"/"Next")
  • changelog-build contents
  • Append the previous release CHANGELOG contents

If this functionality would be acceptable for changelog-build, it would only need two additional pieces of optional information:

  • CHANGELOG file name to manage
  • Enable leaving a top header (e.g. skip line 1, skip line 1 if matching string, or add this line 1)

References

https://github.com/hashicorp/terraform-provider-aws/blob/ad8293cc2ec8556783e4896eed33ae97e56f5919/scripts/generate-changelog.sh#L1-L54

Entries without a link

We are starting to use go-changelog for Consul and there is an edgecase that I would like to solve. For changes in Consul Enterprise we don't have a PR or issue that we could link to because this repository is private. Now I am trying to find a way to generate changelog entries without a link to a PR or issue.

Our current note template:

{{- define "note" -}}
{{.Body}} [[GH-{{- .Issue -}}](https://github.com/hashicorp/consul/issues/{{- .Issue -}})]
{{- end -}}

I would like it to look like this:

{{- define "note" -}}
{{.Body}}{{if .Link}} [[GH-{{- .Issue -}}](https://github.com/hashicorp/consul/issues/{{- .Issue -}})]{{end}}
{{- end -}}

Displaying links should be the default, you would want to opt out manually, maybe like this:

```release-note:enhancement:no-link
Added the `bar` interface.
```

What do you think about that?

Investigate Configurable Entry Type and Regular Expression Entry Checks

Description

Consumers of go-changelog may wish to use changelog-pr-body-check in pull request workflows with slightly more configurable entry type checking and other functionality such as expected entry prefixes/regular expressions for certain types. While the goal would not be to create too complex of a configuration for the tooling, there could be some broadly beneficial updates that could potentially be made.

References

Support for updating changelogs on merge

It would be really nice if we could regenerate the unreleased changelog on every PR merge, updating the CHANGELOG.md to reflect the latest, unreleased changes in an easy-to-access format. In theory, this should be relatively achievable with GitHub actions, perhaps in combination with #5.

Hello :-)

Hi @paddycarver how are you? I was giving a look on your project and I have a need related to this, do you have anywhere plans for this project? Do you have plans to work towards https://keepachangelog.com/en/1.0.0/ also?

I would like to learn go, maybe I can help try with simple features from the backlog.

Thx.

Investigate Required Changelog File/Entry Workflow

Description

Certain projects may want an easy GitHub Actions workflow to require changelog entries for pull requests that are managed by go-changelog. Currently, this can be done, but requires some glue scripting, such as what is done by Consul.

It would be great if projects could quickly configure a workflow to enable this behavior. This could be potentially done along with other changelog checks as shown below:

- uses: hashicorp/go-changelog-check
  with:
    pull-request-number: {{ github.event.pull_request.number }}
    required: true
    required-ignore-labels: ["pr/no-changelog"]

References

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.