Skip to content

Commit

Permalink
refactor release-notes to handle semver v2 properly
Browse files Browse the repository at this point in the history
  • Loading branch information
crhntr committed Mar 28, 2023
1 parent 58c2e7b commit 0a061e8
Show file tree
Hide file tree
Showing 11 changed files with 69 additions and 87 deletions.
8 changes: 3 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ go 1.18
require (
github.com/Masterminds/semver v1.5.0
github.com/aws/aws-sdk-go v1.44.95
github.com/blang/semver/v4 v4.0.0
github.com/cloudfoundry/bosh-cli v6.4.1+incompatible
github.com/cloudfoundry/bosh-utils v0.0.0-20210130100352-ab14c90ad9f2
github.com/cucumber/godog v0.12.5
Expand All @@ -14,10 +15,12 @@ require (
github.com/go-git/go-billy/v5 v5.3.1
github.com/go-git/go-git/v5 v5.4.2
github.com/google/go-github/v40 v40.0.0
github.com/google/go-github/v50 v50.2.0
github.com/hashicorp/vault/api v1.9.0
github.com/hashicorp/vault/api/auth/ldap v0.4.0
github.com/masterminds/sprig v2.22.0+incompatible
github.com/maxbrunsfeld/counterfeiter/v6 v6.5.0
github.com/migueleliasweb/go-github-mock v0.0.16
github.com/moby/buildkit v0.11.2
github.com/onsi/ginkgo v1.16.4
github.com/onsi/gomega v1.18.1
Expand All @@ -44,7 +47,6 @@ require (
github.com/VividCortex/ewma v1.1.1 // indirect
github.com/acomagu/bufpipe v1.0.3 // indirect
github.com/bmatcuk/doublestar v1.3.4 // indirect
github.com/buger/jsonparser v1.1.1 // indirect
github.com/cenkalti/backoff/v3 v3.2.2 // indirect
github.com/charlievieth/fs v0.0.1 // indirect
github.com/cheggaaa/pb/v3 v3.0.5 // indirect
Expand All @@ -64,8 +66,6 @@ require (
github.com/fatih/color v1.13.0 // indirect
github.com/fsnotify/fsnotify v1.4.9 // indirect
github.com/go-git/gcfg v1.5.0 // indirect
github.com/go-kit/log v0.2.0 // indirect
github.com/go-logfmt/logfmt v0.5.1 // indirect
github.com/go-logr/logr v1.2.3 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-ole/go-ole v1.2.6 // indirect
Expand All @@ -74,7 +74,6 @@ require (
github.com/gogo/googleapis v1.4.1 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/go-github/v50 v50.2.0 // indirect
github.com/google/go-querystring v1.1.0 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/gorilla/mux v1.8.0 // indirect
Expand Down Expand Up @@ -104,7 +103,6 @@ require (
github.com/mattn/go-colorable v0.1.12 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/mattn/go-runewidth v0.0.10 // indirect
github.com/migueleliasweb/go-github-mock v0.0.16 // indirect
github.com/mitchellh/copystructure v1.2.0 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
Expand Down
16 changes: 2 additions & 14 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,6 @@ github.com/Microsoft/go-winio v0.5.2 h1:a9IhgEQBCUEk6QCdml9CiJGhAws+YwffDHEMp1VM
github.com/Microsoft/go-winio v0.5.2/go.mod h1:WpS1mjBmmwHBEWmogvA2mj8546UReBk4v8QkMxJ6pZY=
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
github.com/ProtonMail/go-crypto v0.0.0-20210428141323-04723f9f07d7/go.mod h1:z4/9nQmJSSwwds7ejkxaJwO37dru3geImFUdJlaLzQo=
github.com/ProtonMail/go-crypto v0.0.0-20210707164159-52430bf6b52c h1:FP7mMdsXy0ybzar1sJeIcZtaJka0U/ZmLTW4wRpolYk=
github.com/ProtonMail/go-crypto v0.0.0-20210707164159-52430bf6b52c/go.mod h1:z4/9nQmJSSwwds7ejkxaJwO37dru3geImFUdJlaLzQo=
github.com/ProtonMail/go-crypto v0.0.0-20230217124315-7d5c6f04bbb8 h1:wPbRQzjjwFc0ih8puEVAOFGELsn1zoIIYdxvML7mDxA=
github.com/ProtonMail/go-crypto v0.0.0-20230217124315-7d5c6f04bbb8/go.mod h1:I0gYDMZ6Z5GRU7l58bNFSkPTFN6Yl12dsUlAZ8xy98g=
github.com/StackExchange/wmi v0.0.0-20180725035823-b12b22c5341f/go.mod h1:3eOhrUMpNV+6aFIbp5/iudMxNCF27Vw2OZgy4xEx0Fg=
Expand Down Expand Up @@ -127,10 +125,11 @@ github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+Ce
github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs=
github.com/bketelsen/crypt v0.0.3-0.20200106085610-5cbc8cc4026c/go.mod h1:MKsuJmJgSg28kpZDP6UIiPt0e0Oz0kqKNGyRaWEPv84=
github.com/blang/semver v3.5.1+incompatible/go.mod h1:kRBLl5iJ+tD4TcOOxsy/0fnwebNt5EWlYSAyrTnjyyk=
github.com/blang/semver/v4 v4.0.0 h1:1PFHFE6yCCTv8C1TeyNNarDzntLi7wMI5i/pzqYIsAM=
github.com/blang/semver/v4 v4.0.0/go.mod h1:IbckMUScFkM3pff0VJDNKRiT6TG/YpiHIM2yvyW5YoQ=
github.com/bmatcuk/doublestar v1.3.3/go.mod h1:wiQtGV+rzVYxB7WIlirSN++5HPtPlXEo9MEoZQC/PmE=
github.com/bmatcuk/doublestar v1.3.4 h1:gPypJ5xD31uhX6Tf54sDPUOBXTqKH4c9aPY66CyQrS0=
github.com/bmatcuk/doublestar v1.3.4/go.mod h1:wiQtGV+rzVYxB7WIlirSN++5HPtPlXEo9MEoZQC/PmE=
github.com/buger/jsonparser v1.1.1 h1:2PnMjfWD7wBILjqQbt530v576A/cAbQvEW9gGIpYMUs=
github.com/buger/jsonparser v1.1.1/go.mod h1:6RYKKt7H4d4+iWqouImQ9R2FZql3VbhNgx27UK13J/0=
github.com/bwesterb/go-ristretto v1.2.0/go.mod h1:fUIoIZaG73pV5biE2Blr2xEzDoMj7NFEuV9ekS419A0=
github.com/cenkalti/backoff/v3 v3.0.0/go.mod h1:cIeZDE3IrqwwJl6VUwCN6trj1oXrTS4rc0ij+ULvLYs=
Expand Down Expand Up @@ -264,11 +263,9 @@ github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=
github.com/go-kit/kit v0.9.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=
github.com/go-kit/log v0.2.0 h1:7i2K3eKTos3Vc0enKCfnVcgHh2olr/MyfboYq7cAcFw=
github.com/go-kit/log v0.2.0/go.mod h1:NwTd00d/i8cPZ3xOwwiv2PO5MOcx78fFErGNcVmBjv0=
github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE=
github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk=
github.com/go-logfmt/logfmt v0.5.1 h1:otpy5pqBCBZ1ng9RQ0dPu4PN7ba75Y/aA+UpowDyNVA=
github.com/go-logfmt/logfmt v0.5.1/go.mod h1:WYhtIu8zTZfxdn5+rREduYbwxfcBr/Vr6KEVveWlfTs=
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
github.com/go-logr/logr v1.2.3 h1:2DntVwHkVopvECVRSlL5PSo9eG+cAkDCuckLubN+rq0=
Expand Down Expand Up @@ -781,7 +778,6 @@ golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm
golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.5.0 h1:U/0M97KRkSFvyD/3FSmdP5W5swImpNgle/EHFhOsQPE=
golang.org/x/crypto v0.5.0/go.mod h1:NK/OQwhpMQP3MwtdjgLlYHnH9ebylxKWv3e0fK+mkQU=
golang.org/x/crypto v0.7.0 h1:AvwMYaRytfdeVt3u6mLaxYtErKYjxA2OXjJ1HHq6t3A=
golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU=
Expand Down Expand Up @@ -822,7 +818,6 @@ golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.4.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.4.1/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 h1:6zppjxzCulZykYSLyVDYbneBfbaBIQPYMevg0bEwv2s=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/mod v0.8.0 h1:LUYupSeNrTNCGzR/hVBk2NHZO4hXcVaW1k4Qx7rjPx8=
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
Expand Down Expand Up @@ -881,7 +876,6 @@ golang.org/x/net v0.0.0-20220225172249-27dd8689420f/go.mod h1:CfG3xpIq0wQ8r1q4Su
golang.org/x/net v0.0.0-20220325170049-de3da57026de/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
golang.org/x/net v0.0.0-20220412020605-290c469a71a5/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
golang.org/x/net v0.5.0 h1:GyT4nK/YDHSqa1c4753ouYCDajOYKTja9Xb/OHtgvSw=
golang.org/x/net v0.5.0/go.mod h1:DivGGAXEgPSlEBzxGzZI+ZLohi+xUj054jfeKui00ws=
golang.org/x/net v0.8.0 h1:Zrh2ngAOFYneWTAIAPethzeaQLuHwhuBkuV6ZiRnUaQ=
golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc=
Expand All @@ -904,8 +898,6 @@ golang.org/x/oauth2 v0.0.0-20211104180415-d3ed0bb246c8/go.mod h1:KelEdhl1UZF7XfJ
golang.org/x/oauth2 v0.0.0-20220223155221-ee480838109b/go.mod h1:DAh4E804XQdzx2j+YRIaUnCqCV2RuMz24cGBJ5QYIrc=
golang.org/x/oauth2 v0.0.0-20220309155454-6242fa91716a/go.mod h1:DAh4E804XQdzx2j+YRIaUnCqCV2RuMz24cGBJ5QYIrc=
golang.org/x/oauth2 v0.0.0-20220411215720-9780585627b5/go.mod h1:DAh4E804XQdzx2j+YRIaUnCqCV2RuMz24cGBJ5QYIrc=
golang.org/x/oauth2 v0.0.0-20220524215830-622c5d57e401 h1:zwrSfklXn0gxyLRX/aR+q6cgHbV/ItVyzbPlbA+dkAw=
golang.org/x/oauth2 v0.0.0-20220524215830-622c5d57e401/go.mod h1:DAh4E804XQdzx2j+YRIaUnCqCV2RuMz24cGBJ5QYIrc=
golang.org/x/oauth2 v0.6.0 h1:Lh8GPgSKBfWSwFvtuWOfeI3aAAnbXTSutYxJiOJFgIw=
golang.org/x/oauth2 v0.6.0/go.mod h1:ycmewcwgD4Rpr3eZJLSB4Kyyljb3qDh40vJ8STE5HKw=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
Expand Down Expand Up @@ -1009,14 +1001,12 @@ golang.org/x/sys v0.0.0-20220503163025-988cb79eb6c6/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.4.0 h1:Zr2JFtRQNX3BCZ8YtxRE9hNJYC8J6I1MVbMg6owUp18=
golang.org/x/sys v0.4.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.4.0 h1:O7UWfv5+A2qiuulQk30kVinPoMtoIPeVaKLEgLpVkvg=
golang.org/x/term v0.4.0/go.mod h1:9P2UbLfCdcvo3p/nzKvsmas4TnlujnuoV9hGgYzW1lQ=
golang.org/x/term v0.6.0 h1:clScbb1cHjoCkyRbWwBEUZ5H/tIFu5TAXIqaZD0Gcjw=
golang.org/x/term v0.6.0/go.mod h1:m6U89DPEgQRMq3DNkDClhWw02AUbt2daBVO4cn4Hv9U=
Expand All @@ -1029,7 +1019,6 @@ golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.6.0 h1:3XmdazWV+ubf7QgHSTWeykHOci5oeekaGJBLkrkaw4k=
golang.org/x/text v0.6.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.8.0 h1:57P1ETyNKtuIjB4SRd15iJxuhj8Gc416Y78H3qgMh68=
golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
Expand Down Expand Up @@ -1097,7 +1086,6 @@ golang.org/x/tools v0.1.2/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
golang.org/x/tools v0.1.3/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
golang.org/x/tools v0.1.4/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
golang.org/x/tools v0.1.12 h1:VveCTK38A2rkS8ZqFY25HIDFscX5X9OoEhJd3quQmXU=
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
golang.org/x/tools v0.6.0 h1:BOw41kyTf3PuCW1pVQf8+Cyg8pMlkYB1oo9iJ6D/lKM=
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,40 +7,6 @@ This topic contains release notes [Hello Tile](https://github.com/crhntr/hello-t

## <a id='releases'></a> Releases

### <a id='0.1.4'></a> 0.1.4

**Release Date:** 07/27/2022

* **[Bug Fix]** Index page has inconsistent whitespace
* Bump hello-release to version `0.1.5`

<table border="1" class="nice">
<thead>
<tr>
<th>Component</th>
<th>Version</th>
<th>Release Notes</th>
</tr>
</thead>
<tbody>
<tr><td>ubuntu-xenial stemcell</td><td>621.0</td><td></td></tr>
<tr><td>bpm</td><td>1.1.18</td><td></td></tr>
<tr><td>hello-release</td><td>0.1.5</td>
<td>
<details>
<summary>v0.1.5</summary>
<pre style="max-width: 30em">
**[Fix]**
The HTML had inconsistent spacing
</pre>
</details>
</td>
</tr>
</tbody>
</table>



### <a id='0.1.3'></a> 0.1.3

**Release Date:** 06/26/2022
Expand Down
7 changes: 0 additions & 7 deletions internal/commands/release_notes.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,6 @@ func (r ReleaseNotes) Execute(args []string) error {
}
data.ReleaseDate, _ = r.parseReleaseDate()

nvm := data.Version
if strings.Contains(nvm.Prerelease(), "build") {
v, _ := nvm.SetPrerelease("")
nvm = &v
}
data.Version = nvm

if r.Options.DocsFile == "" {
return r.writeNotes(r.Writer, data)
}
Expand Down
7 changes: 2 additions & 5 deletions internal/commands/release_notes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

. "github.com/onsi/gomega"

"github.com/Masterminds/semver"
"github.com/blang/semver/v4"
"github.com/go-git/go-billy/v5/memfs"
"github.com/go-git/go-git/v5"
"github.com/go-git/go-git/v5/config"
Expand Down Expand Up @@ -78,7 +78,7 @@ func TestReleaseNotes_Execute(t *testing.T) {
issuesQuery = iq
return notes.Data{
ReleaseDate: mustParseTime(time.Parse(releaseDateFormat, "2021-11-04")),
Version: semver.MustParse("0.1.0-build.50000"),
Version: semver.MustParse("0.1.0"),
Issues: []*github.Issue{
{Title: strPtr("**[Feature Improvement]** Reduce default log-cache max per source")},
{Title: strPtr("**[Bug Fix]** banana metadata migration does not fail on upgrade from previous LTS")},
Expand Down Expand Up @@ -133,9 +133,6 @@ func TestReleaseNotes_Execute(t *testing.T) {
t.Log(out.String())
please.Expect(out.String()).To(Equal(releaseNotesExpectedOutput))
})

t.Run("when updating a docs file", func(t *testing.T) {
})
}

func TestReleaseNotes_checkInputs(t *testing.T) {
Expand Down
5 changes: 1 addition & 4 deletions pkg/notes/notes.go.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
{{with $releaseVersion := (printf "%d.%d.%d" .Version.Major .Version.Minor .Version.Patch) -}}

### <a id='{{ $releaseVersion }}'></a> {{ $releaseVersion }}
{{- end }}
### <a id='{{ .Version }}'></a> {{ .Version }}

{{ if not .ReleaseDate.IsZero }}**Release Date:** {{ .ReleaseDate.Format "01/02/2006" }}{{ end }}

Expand Down
21 changes: 11 additions & 10 deletions pkg/notes/notes_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
"text/template"
"time"

"github.com/Masterminds/semver"
"github.com/blang/semver/v4"
"github.com/go-git/go-git/v5"
"github.com/go-git/go-git/v5/plumbing"
"github.com/go-git/go-git/v5/plumbing/storer"
Expand All @@ -42,7 +42,7 @@ func (cd BOSHReleaseData) HasReleaseNotes() bool {
}

type Data struct {
Version *semver.Version
Version semver.Version
ReleaseDate time.Time

Issues []*github.Issue
Expand All @@ -62,6 +62,7 @@ func (notes Data) WriteVersionNotes() (TileRelease, error) {
if err != nil {
return TileRelease{}, err
}
notes.Version.Pre = nil
var buf bytes.Buffer
err = noteTemplate.Execute(&buf, notes)
if err != nil {
Expand Down Expand Up @@ -259,32 +260,32 @@ type revisionResolver interface {
ResolveRevision(rev plumbing.Revision) (*plumbing.Hash, error)
}

func (r fetchNotesData) fetchHistoricFiles(kilnfilePath, start, end string) (klInitial, klFinal cargo.KilnfileLock, kfFinal cargo.Kilnfile, _ *semver.Version, _ error) {
func (r fetchNotesData) fetchHistoricFiles(kilnfilePath, start, end string) (klInitial, klFinal cargo.KilnfileLock, kfFinal cargo.Kilnfile, _ semver.Version, _ error) {
initialCommitSHA, err := r.ResolveRevision(plumbing.Revision(start))
if err != nil {
return klInitial, klFinal, kfFinal, nil, fmt.Errorf("failed to resolve inital revision %q: %w", start, err)
return klInitial, klFinal, kfFinal, semver.Version{}, fmt.Errorf("failed to resolve inital revision %q: %w", start, err)
}
finalCommitSHA, err := r.ResolveRevision(plumbing.Revision(end))
if err != nil {
return klInitial, klFinal, kfFinal, nil, fmt.Errorf("failed to resolve final revision %q: %w", end, err)
return klInitial, klFinal, kfFinal, semver.Version{}, fmt.Errorf("failed to resolve final revision %q: %w", end, err)
}

_, klInitial, err = r.historicKilnfile(r.Storer, *initialCommitSHA, kilnfilePath)
if err != nil {
return klInitial, klFinal, kfFinal, nil, fmt.Errorf("failed to get kilnfile from initial commit: %w", err)
return klInitial, klFinal, kfFinal, semver.Version{}, fmt.Errorf("failed to get kilnfile from initial commit: %w", err)
}
kfFinal, klFinal, err = r.historicKilnfile(r.Storer, *finalCommitSHA, kilnfilePath)
if err != nil {
return klInitial, klFinal, kfFinal, nil, fmt.Errorf("failed to get kilnfile from final commit: %w", err)
return klInitial, klFinal, kfFinal, semver.Version{}, fmt.Errorf("failed to get kilnfile from final commit: %w", err)
}
version, err := r.historicVersion(r.Storer, *finalCommitSHA, kilnfilePath)
if err != nil {
return klInitial, klFinal, kfFinal, nil, fmt.Errorf("failed to get version file from final commit: %w", err)
return klInitial, klFinal, kfFinal, semver.Version{}, fmt.Errorf("failed to get version file from final commit: %w", err)
}

v, err := semver.NewVersion(version)
v, err := semver.ParseTolerant(version)
if err != nil {
return klInitial, klFinal, kfFinal, nil, fmt.Errorf("failed to parse version: %w", err)
return klInitial, klFinal, kfFinal, semver.Version{}, fmt.Errorf("failed to parse version: %w", err)
}

return klInitial, klFinal, kfFinal, v, nil
Expand Down
42 changes: 42 additions & 0 deletions pkg/notes/notes_data_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"sort"
"testing"

"github.com/blang/semver/v4"

. "github.com/onsi/gomega"

"github.com/go-git/go-billy/v5/memfs"
Expand Down Expand Up @@ -418,3 +420,43 @@ func githubResponse(t *testing.T, status int) *github.Response {
func intPtr(n int) *int { return &n }
func int64Ptr(n int64) *int64 { return &n }
func strPtr(n string) *string { return &n }

func TestData_WriteVersionNotes(t *testing.T) {
t.Run("version has the correct header", func(t *testing.T) {
please := NewWithT(t)
data := Data{
Version: semver.MustParse("4.0.0+LTS-T"),
}

releaseNotes, err := data.WriteVersionNotes()
please.Expect(err).NotTo(HaveOccurred())

// Note having '+' in the ID is not spec compliant with html4 but is for html5. So we may need
// to change this.
please.Expect(releaseNotes.Notes).To(ContainSubstring("### <a id='4.0.0+LTS-T'></a> 4.0.0+LTS-T"))
})

t.Run("version has a build pre-release suffix", func(t *testing.T) {
please := NewWithT(t)
data := Data{
Version: semver.MustParse("4.0.0-build.3"),
}

releaseNotes, err := data.WriteVersionNotes()
please.Expect(err).NotTo(HaveOccurred())

please.Expect(releaseNotes.Notes).To(ContainSubstring("### <a id='4.0.0'></a> 4.0.0"))
})

t.Run("version has a build pre-release and build metadata", func(t *testing.T) {
please := NewWithT(t)
data := Data{
Version: semver.MustParse("4.0.0-build.3+LTS-T"),
}

releaseNotes, err := data.WriteVersionNotes()
please.Expect(err).NotTo(HaveOccurred())

please.Expect(releaseNotes.Notes).To(ContainSubstring("### <a id='4.0.0+LTS-T'></a> 4.0.0+LTS-T"))
})
}
10 changes: 5 additions & 5 deletions pkg/notes/notes_page.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"regexp"
"strings"

"github.com/Masterminds/semver"
"github.com/blang/semver/v4"
)

const DefaultReleasesSentinel = "\n## <a id='releases'></a> Releases\n\n"
Expand Down Expand Up @@ -108,11 +108,11 @@ func (page *Page) Add(versionNote TileRelease) error {
if err != nil {
continue
}
if nv.Equal(tv) {
if nv.EQ(tv) {
page.Releases[i] = versionNote
return nil
}
if !nv.GreaterThan(tv) {
if !nv.GT(tv) {
continue
}
page.Releases = append(page.Releases[:i], append([]TileRelease{versionNote}, page.Releases[i:]...)...)
Expand Down Expand Up @@ -148,8 +148,8 @@ type TileRelease struct {
Notes string
}

func (notes TileRelease) version() (*semver.Version, error) {
return semver.NewVersion(notes.Version)
func (notes TileRelease) version() (semver.Version, error) {
return semver.ParseTolerant(notes.Version)
}

func stringsSliceContains(slice []string, value string) bool {
Expand Down
Loading

0 comments on commit 0a061e8

Please sign in to comment.