@@ -58,20 +58,28 @@ var Steps []Step = []Step{
5858 Step {
5959 Title : "Update version number in files" ,
6060 Run : func () {
61- UpdateReleaseVersionsInFiles ([]string {
62- "Formula/quick-lint-js.rb" ,
63- "dist/arch/PKGBUILD-dev" ,
64- "dist/arch/PKGBUILD-git" ,
65- "dist/arch/PKGBUILD-release" ,
66- "dist/chocolatey/quick-lint-js.nuspec" ,
67- "dist/chocolatey/tools/VERIFICATION.txt" ,
68- "dist/debian/README.md" ,
69- "dist/npm/BUILDING.md" ,
70- "dist/npm/package.json" ,
71- "dist/scoop/quick-lint-js.template.json" ,
72- "dist/sign-release.go" ,
73- "plugin/vscode-lsp/README.md" ,
74- "plugin/vscode/BUILDING.md" ,
61+ UpdateReleaseVersionsInFiles (map [string ]string {
62+ "Formula/quick-lint-js.rb" : "" ,
63+ "dist/arch/PKGBUILD-dev" : "" ,
64+ "dist/arch/PKGBUILD-git" : "" ,
65+ "dist/arch/PKGBUILD-release" : "" ,
66+ "dist/chocolatey/quick-lint-js.nuspec" : "" ,
67+ "dist/chocolatey/tools/VERIFICATION.txt" : "" ,
68+ "dist/debian/README.md" : "" ,
69+ "dist/npm/BUILDING.md" : "" ,
70+ "dist/npm/package.json" : "" ,
71+ "dist/scoop/quick-lint-js.template.json" : "" ,
72+ "dist/sign-release.go" : "" ,
73+ "plugin/vscode-lsp/README.md" : "" ,
74+ "plugin/vscode/BUILDING.md" : "" ,
75+
76+ "dist/msix/AppxManifest.xml" : "\\ bVersion=" ,
77+ "dist/winget/quick-lint.quick-lint-js.installer.template.yaml" : "PackageVersion:" ,
78+ "dist/winget/quick-lint.quick-lint-js.locale.en-US.template.yaml" : "PackageVersion:" ,
79+ "dist/winget/quick-lint.quick-lint-js.template.yaml" : "PackageVersion:" ,
80+ "plugin/vim/quick-lint-js.vim/doc/quick-lint-js.txt" : "This plugin version is designed for quick-lint-js version" ,
81+ "plugin/vscode-lsp/package.json" : "\" version\" :" ,
82+ "plugin/vscode/package.json" : "\" version\" :" ,
7583 })
7684 },
7785 },
@@ -105,21 +113,6 @@ var Steps []Step = []Step{
105113 },
106114 },
107115
108- Step {
109- Title : "Manually update version number and release date" ,
110- Run : func () {
111- fmt .Printf ("Change these files containing version numbers:\n " )
112- fmt .Printf ("* dist/msix/AppxManifest.xml\n " )
113- fmt .Printf ("* dist/winget/quick-lint.quick-lint-js.installer.template.yaml\n " )
114- fmt .Printf ("* dist/winget/quick-lint.quick-lint-js.locale.en-US.template.yaml\n " )
115- fmt .Printf ("* dist/winget/quick-lint.quick-lint-js.template.yaml\n " )
116- fmt .Printf ("* plugin/vim/quick-lint-js.vim/doc/quick-lint-js.txt\n " )
117- fmt .Printf ("* plugin/vscode-lsp/package.json\n " )
118- fmt .Printf ("* plugin/vscode/package.json\n " )
119- WaitForDone ()
120- },
121- },
122-
123116 Step {
124117 Title : "Re-generate man pages" ,
125118 Run : func () {
@@ -507,10 +500,12 @@ func Stop() {
507500 os .Exit (0 )
508501}
509502
510- func UpdateReleaseVersionsInFiles (paths []string ) {
503+ // Key: file path
504+ // Value: UpdateReleaseVersionsOptions.LineMatchRegexp
505+ func UpdateReleaseVersionsInFiles (pathToLineMatchRegexp map [string ]string ) {
511506 fileContents := make (map [string ][]byte )
512507
513- for _ , path := range paths {
508+ for path , _ := range pathToLineMatchRegexp {
514509 data , err := os .ReadFile (path )
515510 if err != nil {
516511 Stopf ("failed to read file: %v" , err )
@@ -519,7 +514,17 @@ func UpdateReleaseVersionsInFiles(paths []string) {
519514 }
520515
521516 for path , data := range fileContents {
522- fileContents [path ] = UpdateReleaseVersions (data , path )
517+ var err error
518+ fileContents [path ], err = UpdateReleaseVersions (UpdateReleaseVersionsOptions {
519+ FileContent : data ,
520+ PathForDebugging : path ,
521+ OldReleaseVersion : OldReleaseVersion ,
522+ NewReleaseVersion : ReleaseVersion ,
523+ LineMatchRegexp : pathToLineMatchRegexp [path ],
524+ })
525+ if err != nil {
526+ Stopf ("failed to update version numbers in %s: %v" , path , err )
527+ }
523528 }
524529
525530 for path , data := range fileContents {
@@ -530,30 +535,39 @@ func UpdateReleaseVersionsInFiles(paths []string) {
530535 }
531536}
532537
533- func UpdateReleaseVersions (fileContent []byte , pathForDebugging string ) []byte {
534- oldVersion := []byte (OldReleaseVersion )
535- newVersion := []byte (ReleaseVersion )
538+ type UpdateReleaseVersionsOptions struct {
539+ FileContent []byte
540+ PathForDebugging string
541+ OldReleaseVersion string
542+ NewReleaseVersion string
543+ LineMatchRegexp string
544+ }
545+
546+ func UpdateReleaseVersions (options UpdateReleaseVersionsOptions ) ([]byte , error ) {
547+ oldVersion := []byte (options .OldReleaseVersion )
548+ newVersion := []byte (options .NewReleaseVersion )
536549 foundOldVersion := false
537- foundUnexpectedVersion := false
538- fileContent = ThreePartVersionRegexp .ReplaceAllFunc (fileContent , func (match []byte ) []byte {
539- if bytes .Equal (match , oldVersion ) {
540- foundOldVersion = true
541- return newVersion
542- } else {
543- foundUnexpectedVersion = true
544- log .Printf ("error: found unexpected version number in %s: %s\n " , pathForDebugging , string (match ))
545- return match
546- }
550+ var foundUnexpectedVersion error = nil
551+ fullLineMatchRegexp := regexp .MustCompile ("(?m:^.*" + options .LineMatchRegexp + ".*$)" )
552+ newFileContent := fullLineMatchRegexp .ReplaceAllFunc (options .FileContent , func (lineMatch []byte ) []byte {
553+ return ThreePartVersionRegexp .ReplaceAllFunc (lineMatch , func (versionMatch []byte ) []byte {
554+ if bytes .Equal (versionMatch , oldVersion ) {
555+ foundOldVersion = true
556+ return newVersion
557+ } else {
558+ foundUnexpectedVersion = fmt .Errorf ("found unexpected version number in %s: %s" , options .PathForDebugging , string (versionMatch ))
559+ return versionMatch
560+ }
561+ })
547562 })
548- if ! foundOldVersion {
549- log .Printf ("error: failed to find old version number %s in %s\n " , OldReleaseVersion , pathForDebugging )
550- os .Exit (1 )
563+ if foundUnexpectedVersion != nil {
564+ return nil , foundUnexpectedVersion
551565 }
552- if foundUnexpectedVersion {
553- os . Exit ( 1 )
566+ if ! foundOldVersion {
567+ return nil , fmt . Errorf ( "failed to find old version number %s in %s" , options . OldReleaseVersion , options . PathForDebugging )
554568 }
555569
556- return fileContent
570+ return newFileContent , nil
557571}
558572
559573func GetCurrentCommitHash () string {
0 commit comments