Skip to content

Add a latest command that shows the latest released version #77

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

Open
wants to merge 40 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
62c5a0f
Ignore .idea folder
aslakhellesoy Sep 22, 2021
bca39a4
Make Changelog JSONable
aslakhellesoy Sep 22, 2021
70aaee7
Add --json flag to show command
aslakhellesoy Sep 22, 2021
9f2d240
Add --json to fmt command
aslakhellesoy Sep 22, 2021
965e2e5
Output change type as string instead of int
aslakhellesoy Sep 22, 2021
2959140
Update docs
aslakhellesoy Sep 22, 2021
e859a4e
Update changelog
aslakhellesoy Sep 23, 2021
6165e4e
Merge pull request #1 from cucumber/json-output
aslakhellesoy Sep 24, 2021
c18814a
Update badges and mention this is a fork
aslakhellesoy Sep 24, 2021
5bc5114
Rename module and update dependencies
aslakhellesoy Sep 24, 2021
729e8d4
Add not about the fork
aslakhellesoy Sep 24, 2021
7a2d57a
Disable goimports since I don't know how to make it pass
aslakhellesoy Sep 24, 2021
efca9d2
Add --tag-pattern option to the release command
aslakhellesoy Nov 9, 2021
ee293f8
Rename --tag-pattern to --tag-format
aslakhellesoy Nov 9, 2021
2adf0d1
Update docs
aslakhellesoy Nov 9, 2021
7ffc53f
Merge pull request #2 from cucumber/release-tag-pattern
mattwynne Nov 9, 2021
31f4f13
Remove deprecated fields from goreleaser config
mattwynne Nov 11, 2021
b2cba8e
Merge pull request #3 from cucumber/fix-goreleaser
mattwynne Nov 11, 2021
493e3c0
Release on changes to main branch
mattwynne Nov 11, 2021
c6a2e30
Update CHANGELOG.md
mattwynne Nov 11, 2021
97ca13d
Release 0.8.0
mattwynne Nov 11, 2021
cdea822
Fix `show` command
mattwynne Nov 11, 2021
351c92e
Update changelog for #4
mattwynne Nov 11, 2021
a140f1e
Release 0.9.0
mattwynne Nov 11, 2021
7f67894
Add an ARM64 build too
mattwynne Nov 11, 2021
401bfc3
Update changelog
mattwynne Nov 11, 2021
9e79eab
Configure release action with correct environment / secrets
mattwynne Nov 11, 2021
697f82e
Release 0.9.2
mattwynne Nov 11, 2021
9ac5258
Add a latest command that shows the latest released version
mattwynne Jul 21, 2021
c28bfd1
Clarify help text
mattwynne Jul 21, 2021
b747a94
Add another test case and refactor
mattwynne Jul 21, 2021
365da0c
Update README
mattwynne Jul 21, 2021
49fa501
Add changelog entry for #77
mattwynne Aug 16, 2021
4330f9b
Move ReleasedVersions onto ChangeLog model
Sep 9, 2021
f13ad90
Update CHANGELOG
mattwynne Nov 11, 2021
d682a08
Split goreleaser action into two jobs
mattwynne Nov 11, 2021
af2e9d9
Merge branch 'main' into show-latest-version
mattwynne Nov 11, 2021
d68dab5
Fix ref to parser module
mattwynne Nov 11, 2021
3006bb6
Reformat for linter
mattwynne Nov 11, 2021
fb41359
Release 0.10.0
mattwynne Nov 11, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
pull_request:
push:
branches:
- master
- main

jobs:
golangci:
Expand All @@ -14,10 +14,10 @@ jobs:
- uses: actions/checkout@v2

- name: golangci-lint
uses: golangci/golangci-lint-action@v1
uses: golangci/golangci-lint-action@v2
with:
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
version: v1.26
version: v1.29
# Optional: working directory, useful for monorepos
# working-directory: somedir
# Optional: golangci-lint command line arguments.
Expand Down
42 changes: 22 additions & 20 deletions .github/workflows/goreleaser.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
name: goreleaser

on:
pull_request:
pull_request
push:
branches:
- master
- main
tags:
- "[0-9]+.[0-9]+.[0-9]+"

jobs:
goreleaser:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
Expand All @@ -24,25 +24,27 @@ jobs:
go-version: 1.14

- name: Build
# if: "!startsWith(github.ref, 'refs/tags/')"
uses: goreleaser/goreleaser-action@v2
with:
version: latest
args: build --snapshot --rm-dist

- name: Prepare release notes
if: "startsWith(github.ref, 'refs/tags/')"
run: ./dist/changelog_linux_amd64/changelog -f CHANGELOG.md show ${GITHUB_REF##*/} > release-notes.txt

- name: Docker login
if: "startsWith(github.ref, 'refs/tags/')"
run: docker login -u '${{ secrets.DOCKER_USERNAME }}' -p '${{ secrets.DOCKER_PASSWORD }}'

- name: Release
uses: goreleaser/goreleaser-action@v2
if: "startsWith(github.ref, 'refs/tags/')"
with:
version: latest
args: release --release-notes release-notes.txt --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
release:
runs-on: ubuntu-latest
environment: Release
needs: build
if: "startsWith(github.ref, 'refs/tags/')"
steps:
- name: Prepare release notes
run: ./dist/changelog_linux_amd64/changelog -f CHANGELOG.md show ${GITHUB_REF##*/} > release-notes.txt

- name: Docker login
run: docker login -u '${{ secrets.DOCKER_HUB_USER }}' -p '${{ secrets.DOCKER_HUB_PASSWORD }}'

- name: Release
uses: goreleaser/goreleaser-action@v2
with:
version: latest
args: release --release-notes release-notes.txt --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ release-notes.txt


# End of https://www.gitignore.io/api/go
.idea/
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ linters:
- gas
- gocyclo
- megacheck
- goimports
enable:
- gofmt
- goimports
- gosimple
- unused
- staticcheck
Expand Down
13 changes: 5 additions & 8 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,13 @@ builds:
- linux
goarch:
- amd64
- arm64
dockers:
- goos: linux
goarch: amd64
builds:
- changelog
binaries:
- changelog
dockerfile: Dockerfile.goreleaser
image_templates:
- "rcmachado/{{.ProjectName}}:{{.Tag}}"
- "rcmachado/{{.ProjectName}}:{{ .Major }}"
- "rcmachado/{{.ProjectName}}:{{ .Major }}.{{ .Minor }}"
- "rcmachado/{{.ProjectName}}:latest"
- "cucumber/{{.ProjectName}}:{{.Tag}}"
- "cucumber/{{.ProjectName}}:{{ .Major }}"
- "cucumber/{{.ProjectName}}:{{ .Major }}.{{ .Minor }}"
- "cucumber/{{.ProjectName}}:latest"
28 changes: 27 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,28 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

## [0.10.0] - 2021-11-11
### Added
- `latest` command to show latest release version number ([#5](https://github.com/cucumber/changelog/pull/5))

## [0.9.2] - 2021-11-11
### Added
- ARM64 release build

### Fixed
- config for releasing to Cucumber's docker account

## 0.9.1 - 2021-11-11

## [0.9.0] - 2021-11-11
### Fixed
- Show command was broken ([#4](https://github.com/cucumber/changelog/issues/4))

## [0.8.0] - 2021-11-11
### Added
- Add `--json` flag to `fmt` and `show` commands. ([#1](https://github.com/cucumber/changelog/pull/1))
- Add `--tag-format` to `release` command. ([#2](https://github.com/cucumber/changelog/pull/2))

## [0.7.0] - 2020-07-03
### Changed
- Install git and openssh on docker image
Expand Down Expand Up @@ -61,7 +83,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- `fmt` command to reformat changelog following the spec
- `show` command to show a specific version

[Unreleased]: https://github.com/rcmachado/changelog/compare/0.7.0...HEAD
[Unreleased]: https://github.com/rcmachado/changelog/compare/0.10.0...HEAD
[0.10.0]: https://github.com/rcmachado/changelog/compare/0.9.2...0.10.0
[0.9.2]: https://github.com/rcmachado/changelog/compare/0.9.0...0.9.2
[0.9.0]: https://github.com/rcmachado/changelog/compare/0.8.0...0.9.0
[0.8.0]: https://github.com/rcmachado/changelog/compare/0.7.0...0.8.0
[0.7.0]: https://github.com/rcmachado/changelog/compare/0.6.0...0.7.0
[0.6.0]: https://github.com/rcmachado/changelog/compare/0.5.0...0.6.0
[0.5.0]: https://github.com/rcmachado/changelog/compare/0.4.2...0.5.0
Expand Down
24 changes: 18 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# changelog

![Tests](https://github.com/rcmachado/changelog/workflows/Tests/badge.svg)
[![Coverage Status](https://coveralls.io/repos/github/rcmachado/changelog/badge.svg?branch=master)](https://coveralls.io/github/rcmachado/changelog?branch=master)
[![Go Report Card](https://goreportcard.com/badge/github.com/rcmachado/changelog)](https://goreportcard.com/report/github.com/rcmachado/changelog)
![Tests](https://github.com/cucumber/changelog/workflows/Tests/badge.svg)
[![Coverage Status](https://coveralls.io/repos/github/cucumber/changelog/badge.svg?branch=master)](https://coveralls.io/github/cucumber/changelog?branch=master)
[![Go Report Card](https://goreportcard.com/badge/github.com/cucumber/changelog)](https://goreportcard.com/report/github.com/cucumber/changelog)

(This is a fork of https://github.com/rcmachado/changelog)

`changelog` is a command-line application to read and manipulate
`CHANGELOG.md` files that follows the [keepachangelog.com][] spec.
Expand Down Expand Up @@ -34,6 +36,9 @@ $ changelog init --compare-url=https://github.com/myorg/myrepo/compare/abcdef...
$ changelog added "Initial commit"
# Create release
$ changelog release 0.1.0
# Show latest release number
$ changelog latest
=> 0.1.0
```

## Installation
Expand Down Expand Up @@ -76,6 +81,7 @@ Available Commands:
fmt Reformat the change log file
help Help about any command
init Initializes a new changelog
latest Show latest released version number
release Change Unreleased to [version]
removed Add item under 'Removed' section
security Add item under 'Security' section
Expand All @@ -95,7 +101,7 @@ Outputs a changelog with only preamble and Unreleased version to standard output

```bash
$ touch CHANGELOG.md
$ changelog init -o CHANGELOG.md --compare-url https://github.com/rcmachado/changelog/compare/abcdef...HEAD
$ changelog init -o CHANGELOG.md --compare-url https://github.com/cucumber/changelog/compare/abcdef...HEAD
Changelog file 'CHANGELOG.md' created.
```

Expand Down Expand Up @@ -130,6 +136,12 @@ Create a new release:
changelog release 1.2.4
```

If you use a prefix for git tags, specify a tag format:

```bash
changelog release --tag-format "v%s" 1.2.4
```

### Formatting

`fmt` command normalizes the changelog file. The idea is to always have
Expand All @@ -153,5 +165,5 @@ Licensed under MIT. See [LICENSE][] file for details.

[keepachangelog.com]: https://keepachangelog.com/
[LICENSE]: ./LICENSE
[Issues]: https://github.com/rcmachado/changelog
[latest version]: https://github.com/rcmachado/changelog/releases/latest
[Issues]: https://github.com/cucumber/changelog
[latest version]: https://github.com/cucumber/changelog/releases/latest
31 changes: 31 additions & 0 deletions chg/change.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package chg
//go:generate stringer -type=ChangeType

import (
"encoding/json"
"fmt"
"io"
"strings"
Expand All @@ -16,6 +17,16 @@ type ChangeList struct {
Items []*Item
}

func (cl *ChangeList) MarshalJSON() ([]byte, error) {
return json.Marshal(&struct {
Type string `json:"type"`
Items []*Item `json:"items"`
}{
Type: ChangeStringFromType(cl.Type),
Items: cl.Items,
})
}

// ChangeType is the type of the changes
type ChangeType int

Expand All @@ -30,6 +41,26 @@ const (
Security
)

// ChangeTypeFromString creates a type based on its string name
func ChangeStringFromType(ct ChangeType) string {
switch ct {
case Added:
return "added"
case Changed:
return "changed"
case Deprecated:
return "deprecated"
case Fixed:
return "fixed"
case Removed:
return "removed"
case Security:
return "security"
default:
return "unknown"
}
}

// ChangeTypeFromString creates a type based on its string name
func ChangeTypeFromString(ct string) ChangeType {
switch strings.ToLower(ct) {
Expand Down
24 changes: 17 additions & 7 deletions chg/changelog.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (
// Changelog is the main struct that holds all the data
// in a format specific to the spec
type Changelog struct {
Preamble string
Versions []*Version
Preamble string `json:"preamble"`
Versions []*Version `json:"versions"`
}

// NewChangelog creates the Changelog struct
Expand Down Expand Up @@ -78,7 +78,7 @@ func (c *Changelog) AddItem(section ChangeType, message string) {
}

// Release transforms Unreleased into the version informed
func (c *Changelog) Release(newVersion Version) (*Version, error) {
func (c *Changelog) Release(newVersion Version, tagFormat string) (*Version, error) {
oldUnreleased := c.Version("Unreleased")
var prevVersion *Version
if len(c.Versions) > 1 {
Expand All @@ -101,17 +101,17 @@ func (c *Changelog) Release(newVersion Version) (*Version, error) {
compareURL = strings.Replace(newVersion.Link, "<prev>", newVersion.Name, -1)
compareURL = strings.Replace(compareURL, "<next>", "HEAD", -1)
} else if prevVersion == nil || prevVersion.Link == "" {
r := regexp.MustCompile(`(\w[\w\.]*?)\.{2,3}(\w[\w\.]*?)$`)
r := regexp.MustCompile(`(\w[\w.]*?)\.{2,3}(\w[\w.]*?)$`)
r.MatchString(oldUnreleased.Link)
matches := r.FindStringSubmatch(oldUnreleased.Link)
compareURL = strings.Replace(oldUnreleased.Link, matches[1], newVersion.Name, -1)
compareURL = strings.Replace(oldUnreleased.Link, matches[1], fmt.Sprintf(tagFormat, newVersion.Name), -1)
} else {
compareURL = strings.Replace(oldUnreleased.Link, prevVersion.Name, newVersion.Name, -1)
compareURL = strings.Replace(oldUnreleased.Link, fmt.Sprintf(tagFormat, prevVersion.Name), fmt.Sprintf(tagFormat, newVersion.Name), -1)
}

newUnreleased.Link = compareURL

oldUnreleased.Link = strings.Replace(oldUnreleased.Link, "HEAD", newVersion.Name, -1)
oldUnreleased.Link = strings.Replace(oldUnreleased.Link, "HEAD", fmt.Sprintf(tagFormat, newVersion.Name), -1)
oldUnreleased.Name = newVersion.Name
oldUnreleased.Date = newVersion.Date

Expand Down Expand Up @@ -150,3 +150,13 @@ func (c *Changelog) Render(w io.Writer) {
w.Write(content)
}
}

func (c *Changelog) ReleasedVersions() []Version {
var result []Version
for _, version := range c.Versions {
if version.Name != "Unreleased" {
result = append(result, *version)
}
}
return result
}
Loading