Skip to content

Commit 61a3a51

Browse files
committed
First approach to extensible shell with plugins
1 parent 3295997 commit 61a3a51

File tree

12 files changed

+622
-1
lines changed

12 files changed

+622
-1
lines changed

README.md

+6
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,12 @@ _Context: package_
409409

410410
Boot up the stack.
411411

412+
### `elastic-package shell`
413+
414+
_Context: global_
415+
416+
417+
412418
### `elastic-package stack`
413419

414420
_Context: global_

cmd/root.go

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ var commands = []*cobraext.Command{
3131
setupPublishCommand(),
3232
setupReportsCommand(),
3333
setupServiceCommand(),
34+
setupShellCommand(),
3435
setupStackCommand(),
3536
setupStatusCommand(),
3637
setupTestCommand(),

cmd/shell.go

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
2+
// or more contributor license agreements. Licensed under the Elastic License;
3+
// you may not use this file except in compliance with the Elastic License.
4+
5+
package cmd
6+
7+
import (
8+
cshell "github.com/brianstrauch/cobra-shell"
9+
"github.com/spf13/cobra"
10+
11+
"github.com/elastic/elastic-package/internal/cobraext"
12+
"github.com/elastic/elastic-package/pkg/shell"
13+
)
14+
15+
func setupShellCommand() *cobraext.Command {
16+
cmd := &cobra.Command{
17+
Use: "shell",
18+
Hidden: true,
19+
SilenceUsage: true,
20+
}
21+
cmd.CompletionOptions.DisableDefaultCmd = true
22+
cmd.CompletionOptions.HiddenDefaultCmd = true
23+
24+
shell.AttachCommands(cmd)
25+
26+
shellCmd := cshell.New(cmd, nil)
27+
28+
return cobraext.NewCommand(shellCmd, cobraext.ContextGlobal)
29+
}

go.mod

+6-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ require (
88
github.com/ProtonMail/gopenpgp/v2 v2.7.3
99
github.com/aymerick/raymond v2.0.2+incompatible
1010
github.com/boumenot/gocover-cobertura v1.2.0
11+
github.com/brianstrauch/cobra-shell v0.4.0
1112
github.com/cbroglie/mustache v1.4.0
1213
github.com/cespare/xxhash/v2 v2.2.0
1314
github.com/dustin/go-humanize v1.0.1
@@ -26,11 +27,13 @@ require (
2627
github.com/google/uuid v1.3.1
2728
github.com/jedib0t/go-pretty v4.3.0+incompatible
2829
github.com/magefile/mage v1.15.0
30+
github.com/mattn/go-sqlite3 v1.14.17
2931
github.com/mholt/archiver/v3 v3.5.1
3032
github.com/olekukonko/tablewriter v0.0.5
3133
github.com/pmezard/go-difflib v1.0.0
3234
github.com/shirou/gopsutil/v3 v3.23.7
3335
github.com/spf13/cobra v1.7.0
36+
github.com/spf13/pflag v1.0.5
3437
github.com/stretchr/testify v1.8.4
3538
golang.org/x/tools v0.12.0
3639
gopkg.in/yaml.v3 v3.0.1
@@ -58,6 +61,7 @@ require (
5861
github.com/acomagu/bufpipe v1.0.4 // indirect
5962
github.com/andybalholm/brotli v1.0.4 // indirect
6063
github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d // indirect
64+
github.com/c-bata/go-prompt v0.2.6 // indirect
6165
github.com/chai2010/gettext-go v1.0.2 // indirect
6266
github.com/cloudflare/circl v1.3.3 // indirect
6367
github.com/creasty/defaults v1.7.0 // indirect
@@ -109,6 +113,7 @@ require (
109113
github.com/mattn/go-colorable v0.1.13 // indirect
110114
github.com/mattn/go-isatty v0.0.17 // indirect
111115
github.com/mattn/go-runewidth v0.0.14 // indirect
116+
github.com/mattn/go-tty v0.0.3 // indirect
112117
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d // indirect
113118
github.com/mitchellh/copystructure v1.2.0 // indirect
114119
github.com/mitchellh/go-wordwrap v1.0.1 // indirect
@@ -126,6 +131,7 @@ require (
126131
github.com/pierrec/lz4/v4 v4.1.17 // indirect
127132
github.com/pjbgf/sha1cd v0.3.0 // indirect
128133
github.com/pkg/errors v0.9.1 // indirect
134+
github.com/pkg/term v1.2.0-beta.2 // indirect
129135
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect
130136
github.com/rivo/uniseg v0.4.3 // indirect
131137
github.com/russross/blackfriday/v2 v2.1.0 // indirect
@@ -134,7 +140,6 @@ require (
134140
github.com/shopspring/decimal v1.3.1 // indirect
135141
github.com/skeema/knownhosts v1.2.0 // indirect
136142
github.com/spf13/cast v1.5.0 // indirect
137-
github.com/spf13/pflag v1.0.5 // indirect
138143
github.com/tklauser/go-sysconf v0.3.11 // indirect
139144
github.com/tklauser/numcpus v0.6.0 // indirect
140145
github.com/ulikunitz/xz v0.5.11 // indirect

go.sum

+18
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,13 @@ github.com/aymerick/raymond v2.0.2+incompatible h1:VEp3GpgdAnv9B2GFyTvqgcKvY+mfK
5050
github.com/aymerick/raymond v2.0.2+incompatible/go.mod h1:osfaiScAUVup+UC9Nfq76eWqDhXlp+4UYaA8uhTBO6g=
5151
github.com/boumenot/gocover-cobertura v1.2.0 h1:g+VROIASoEHBrEilIyaCmgo7HGm+AV5yKEPLk0qIY+s=
5252
github.com/boumenot/gocover-cobertura v1.2.0/go.mod h1:fz7ly8dslE42VRR5ZWLt2OHGDHjkTiA2oNvKgJEjLT0=
53+
github.com/brianstrauch/cobra-shell v0.4.0 h1:oPWTBqPPbE8Vd/i3WRvQd8XWTrevIwR0bFBIS7X6gWk=
54+
github.com/brianstrauch/cobra-shell v0.4.0/go.mod h1:QkRKnD1+MfpITTqYDE8Yp8zALgsHdeYur/qAw4kNr8c=
5355
github.com/bwesterb/go-ristretto v1.2.3/go.mod h1:fUIoIZaG73pV5biE2Blr2xEzDoMj7NFEuV9ekS419A0=
5456
github.com/cbroglie/mustache v1.4.0 h1:Azg0dVhxTml5me+7PsZ7WPrQq1Gkf3WApcHMjMprYoU=
5557
github.com/cbroglie/mustache v1.4.0/go.mod h1:SS1FTIghy0sjse4DUVGV1k/40B1qE1XkD9DtDsHo9iM=
58+
github.com/c-bata/go-prompt v0.2.6 h1:POP+nrHE+DfLYx370bedwNhsqmpCUynWPxuHi0C5vZI=
59+
github.com/c-bata/go-prompt v0.2.6/go.mod h1:/LMAke8wD2FsNu9EXNdHxNLbd9MedkPnCdfpU9wwHfY=
5660
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
5761
github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44=
5862
github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
@@ -257,19 +261,27 @@ github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJ
257261
github.com/matryer/is v1.2.0 h1:92UTHpy8CDwaJ08GqLDzhhuixiBUUD1p3AU6PHddz4A=
258262
github.com/matryer/is v1.2.0/go.mod h1:2fLPjFQM9rhQ15aVEtbuwhJinnOqrmgXPNdZsdwlWXA=
259263
github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
264+
github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
265+
github.com/mattn/go-colorable v0.1.7/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
260266
github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
261267
github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4=
262268
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
263269
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
264270
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
271+
github.com/mattn/go-isatty v0.0.10/go.mod h1:qgIWMr58cqv1PHHyhnkY9lrL7etaEgOFcMEpPG5Rm84=
265272
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
266273
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
267274
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
268275
github.com/mattn/go-isatty v0.0.17 h1:BTarxUcIeDqL27Mc+vyvdWYSL28zpIhv3RoTdsLMPng=
269276
github.com/mattn/go-isatty v0.0.17/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
277+
github.com/mattn/go-runewidth v0.0.6/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
270278
github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
271279
github.com/mattn/go-runewidth v0.0.14 h1:+xnbZSEeDbOIg5/mE6JF0w6n9duR1l3/WmbinWVwUuU=
272280
github.com/mattn/go-runewidth v0.0.14/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
281+
github.com/mattn/go-sqlite3 v1.14.17 h1:mCRHCLDUBXgpKAqIKsaAaAsrAlbkeomtRFKXh2L6YIM=
282+
github.com/mattn/go-sqlite3 v1.14.17/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg=
283+
github.com/mattn/go-tty v0.0.3 h1:5OfyWorkyO7xP52Mq7tB36ajHDG5OHrmBGIS/DtakQI=
284+
github.com/mattn/go-tty v0.0.3/go.mod h1:ihxohKRERHTVzN+aSVRwACLCeqIoZAWpoICkkvrWyR0=
273285
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE=
274286
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d h1:5PJl274Y63IEHC+7izoQE9x6ikvDFZS2mDVS3drnohI=
275287
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE=
@@ -321,6 +333,8 @@ github.com/pjbgf/sha1cd v0.3.0/go.mod h1:nZ1rrWOcGJ5uZgEEVL1VUM9iRQiZvWdbZjkKyFz
321333
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
322334
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
323335
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
336+
github.com/pkg/term v1.2.0-beta.2 h1:L3y/h2jkuBVFdWiJvNfYfKmzcCnILw7mJWm2JQuMppw=
337+
github.com/pkg/term v1.2.0-beta.2/go.mod h1:E25nymQcrSllhX42Ok8MRm1+hyBdHY0dCeiKZ9jpNGw=
324338
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
325339
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
326340
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c h1:ncq/mPwQF4JjgDlrVEn3C11VoGHZN7m8qihwgMEtzYw=
@@ -470,9 +484,13 @@ golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5h
470484
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
471485
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
472486
golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
487+
golang.org/x/sys v0.0.0-20191008105621-543471e840be/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
473488
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
489+
golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
474490
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
475491
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
492+
golang.org/x/sys v0.0.0-20200909081042-eff7692f9009/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
493+
golang.org/x/sys v0.0.0-20200918174421-af09f7315aff/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
476494
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
477495
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
478496
golang.org/x/sys v0.0.0-20201204225414-ed752295db88/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=

internal/configuration/locations/locations.go

+6
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const (
1818
stackDir = "stack"
1919
packagesDir = "development"
2020
profilesDir = "profiles"
21+
pluginsDir = "shell_plugins"
2122

2223
temporaryDir = "tmp"
2324
deployerDir = "deployer"
@@ -100,6 +101,11 @@ func (loc LocationManager) FieldsCacheDir() string {
100101
return filepath.Join(loc.stackPath, fieldsCachedDir)
101102
}
102103

104+
// ShellPluginsDir returns the directory where the shell plugins will be stored.
105+
func (loc LocationManager) ShellPluginsDir() string {
106+
return filepath.Join(loc.stackPath, pluginsDir)
107+
}
108+
103109
// configurationDir returns the configuration directory location
104110
// If a environment variable named as in elasticPackageDataHome is present,
105111
// the value is used as is, overriding the value of this function.

internal/install/install.go

+13
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ func EnsureInstalled() error {
7373
return fmt.Errorf("creating service logs directory failed: %w", err)
7474
}
7575

76+
if err := createShellPluginsDir(elasticPackagePath); err != nil {
77+
return fmt.Errorf("creating shell plugins directory failed: %w", err)
78+
}
79+
7680
fmt.Fprintln(os.Stderr, "elastic-package has been installed.")
7781
return nil
7882
}
@@ -149,3 +153,12 @@ func createServiceLogsDir(elasticPackagePath *locations.LocationManager) error {
149153
}
150154
return nil
151155
}
156+
157+
func createShellPluginsDir(elasticPackagePath *locations.LocationManager) error {
158+
dirPath := elasticPackagePath.ShellPluginsDir()
159+
err := os.MkdirAll(dirPath, 0755)
160+
if err != nil {
161+
return fmt.Errorf("mkdir failed (path: %s): %w", dirPath, err)
162+
}
163+
return nil
164+
}

pkg/shell/plugins/changelog.go

+166
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
2+
// or more contributor license agreements. Licensed under the Elastic License;
3+
// you may not use this file except in compliance with the Elastic License.
4+
5+
package main
6+
7+
import (
8+
"context"
9+
"errors"
10+
"fmt"
11+
"io"
12+
"os"
13+
"path/filepath"
14+
15+
"github.com/Masterminds/semver/v3"
16+
"github.com/spf13/pflag"
17+
18+
"github.com/elastic/elastic-package/internal/cobraext"
19+
"github.com/elastic/elastic-package/internal/packages"
20+
"github.com/elastic/elastic-package/internal/packages/changelog"
21+
"github.com/elastic/elastic-package/pkg/shell"
22+
)
23+
24+
var _ shell.Command = changelogCmd{}
25+
26+
type changelogCmd struct{}
27+
28+
func (changelogCmd) Usage() string {
29+
return "changelog --next {major|minor|patch} --description desc --type {bugfix|enhancement|breaking-change} --link link"
30+
}
31+
32+
func (changelogCmd) Desc() string {
33+
return "Add an entry to the changelog file in each of the packages in context 'Shell.Packages'."
34+
}
35+
36+
func (changelogCmd) Flags() *pflag.FlagSet {
37+
flags := pflag.NewFlagSet("changelog", pflag.ContinueOnError)
38+
flags.String(cobraext.ChangelogAddNextFlagName, "", cobraext.ChangelogAddNextFlagDescription)
39+
flags.String(cobraext.ChangelogAddDescriptionFlagName, "", cobraext.ChangelogAddDescriptionFlagDescription)
40+
flags.String(cobraext.ChangelogAddTypeFlagName, "", cobraext.ChangelogAddTypeFlagDescription)
41+
flags.String(cobraext.ChangelogAddLinkFlagName, "", cobraext.ChangelogAddLinkFlagDescription)
42+
return flags
43+
}
44+
45+
func (changelogCmd) Exec(ctx context.Context, flags *pflag.FlagSet, args []string, _, stderr io.Writer) (context.Context, error) {
46+
packages, ok := ctx.Value(ctxKeyPackages).([]string)
47+
if !ok {
48+
fmt.Fprintln(stderr, "no packages found in the context")
49+
return ctx, nil
50+
}
51+
for _, pkg := range packages {
52+
packageRoot := pkg
53+
// check if we are in packages folder
54+
if _, err := os.Stat(filepath.Join(".", pkg)); err != nil {
55+
// check if we are in integrations root folder
56+
packageRoot = filepath.Join(".", "packages", pkg)
57+
if _, err := os.Stat(packageRoot); err != nil {
58+
return ctx, errors.New("you need to be in intgerations root folder or in the packages folder")
59+
}
60+
}
61+
if err := changelogAddCmdForRoot(packageRoot, flags, args); err != nil {
62+
return ctx, err
63+
}
64+
}
65+
return ctx, nil
66+
}
67+
68+
func changelogAddCmdForRoot(packageRoot string, flags *pflag.FlagSet, args []string) error {
69+
nextMode, _ := flags.GetString(cobraext.ChangelogAddNextFlagName)
70+
v, err := changelogCmdVersion(nextMode, packageRoot)
71+
if err != nil {
72+
return err
73+
}
74+
version := v.String()
75+
76+
description, _ := flags.GetString(cobraext.ChangelogAddDescriptionFlagName)
77+
changeType, _ := flags.GetString(cobraext.ChangelogAddTypeFlagName)
78+
link, _ := flags.GetString(cobraext.ChangelogAddLinkFlagName)
79+
80+
entry := changelog.Revision{
81+
Version: version,
82+
Changes: []changelog.Entry{
83+
{
84+
Description: description,
85+
Type: changeType,
86+
Link: link,
87+
},
88+
},
89+
}
90+
91+
if err := patchChangelogFile(packageRoot, entry); err != nil {
92+
return err
93+
}
94+
95+
if err := setManifestVersion(packageRoot, version); err != nil {
96+
return err
97+
}
98+
99+
return nil
100+
}
101+
102+
func changelogCmdVersion(nextMode, packageRoot string) (*semver.Version, error) {
103+
revisions, err := changelog.ReadChangelogFromPackageRoot(packageRoot)
104+
if err != nil {
105+
return nil, fmt.Errorf("failed to read current changelog: %w", err)
106+
}
107+
if len(revisions) == 0 {
108+
return semver.MustParse("0.0.0"), nil
109+
}
110+
111+
version, err := semver.NewVersion(revisions[0].Version)
112+
if err != nil {
113+
return nil, fmt.Errorf("invalid version in changelog %q: %w", revisions[0].Version, err)
114+
}
115+
116+
switch nextMode {
117+
case "":
118+
break
119+
case "major":
120+
v := version.IncMajor()
121+
version = &v
122+
case "minor":
123+
v := version.IncMinor()
124+
version = &v
125+
case "patch":
126+
v := version.IncPatch()
127+
version = &v
128+
default:
129+
return nil, fmt.Errorf("invalid value for %q: %s",
130+
cobraext.ChangelogAddNextFlagName, nextMode)
131+
}
132+
133+
return version, nil
134+
}
135+
136+
// patchChangelogFile looks for the proper place to add the new revision in the changelog,
137+
// trying to conserve original format and comments.
138+
func patchChangelogFile(packageRoot string, patch changelog.Revision) error {
139+
changelogPath := filepath.Join(packageRoot, changelog.PackageChangelogFile)
140+
d, err := os.ReadFile(changelogPath)
141+
if err != nil {
142+
return err
143+
}
144+
145+
d, err = changelog.PatchYAML(d, patch)
146+
if err != nil {
147+
return err
148+
}
149+
150+
return os.WriteFile(changelogPath, d, 0644)
151+
}
152+
153+
func setManifestVersion(packageRoot string, version string) error {
154+
manifestPath := filepath.Join(packageRoot, packages.PackageManifestFile)
155+
d, err := os.ReadFile(manifestPath)
156+
if err != nil {
157+
return err
158+
}
159+
160+
d, err = changelog.SetManifestVersion(d, version)
161+
if err != nil {
162+
return err
163+
}
164+
165+
return os.WriteFile(manifestPath, d, 0644)
166+
}

0 commit comments

Comments
 (0)