@@ -18,6 +18,7 @@ import (
1818 "context"
1919 "errors"
2020 "fmt"
21+ "strings"
2122
2223 "github.com/googleapis/librarian/internal/command"
2324 "github.com/googleapis/librarian/internal/config"
@@ -82,8 +83,16 @@ func runRelease(ctx context.Context, cmd *cli.Command) error {
8283 return err
8384 }
8485
86+ if cfg .Release == nil {
87+ return errReleaseConfigEmpty
88+ }
89+ lastTag , err := git .GetLastTag (ctx , gitExe , cfg .Release .Remote , cfg .Release .Branch )
90+ if err != nil {
91+ return err
92+ }
93+
8594 if all {
86- err = releaseAll (ctx , cfg )
95+ err = releaseAll (ctx , cfg , lastTag , gitExe )
8796 } else {
8897 libConfg , err := libraryByName (cfg , libraryName )
8998 if err != nil {
@@ -93,7 +102,7 @@ func runRelease(ctx context.Context, cmd *cli.Command) error {
93102 if err != nil {
94103 return err
95104 }
96- err = releaseLibrary (ctx , cfg , libConfg , srcPath )
105+ err = releaseLibrary (ctx , cfg , libConfg , srcPath , lastTag , gitExe )
97106 if err != nil {
98107 return err
99108 }
@@ -104,25 +113,41 @@ func runRelease(ctx context.Context, cmd *cli.Command) error {
104113 return yaml .Write (librarianConfigPath , cfg )
105114}
106115
107- func releaseAll (ctx context.Context , cfg * config.Config ) error {
116+ func releaseAll (ctx context.Context , cfg * config.Config , lastTag , gitExe string ) error {
117+ filesChanged , err := git .FilesChangedSince (ctx , lastTag , gitExe , cfg .Release .IgnoredChanges )
118+ if err != nil {
119+ return err
120+ }
108121 for _ , library := range cfg .Libraries {
109122 srcPath , err := getSrcPathForLanguage (cfg , library )
110123 if err != nil {
111124 return err
112125 }
113- release , err := shouldReleaseLibrary (ctx , cfg , srcPath )
114- if err != nil {
115- return err
116- }
117- if release {
118- if err := releaseLibrary (ctx , cfg , library , srcPath ); err != nil {
126+ if shouldRelease (library , filesChanged , srcPath ) {
127+ if err := releaseLibrary (ctx , cfg , library , srcPath , lastTag , gitExe ); err != nil {
119128 return err
120129 }
121130 }
122131 }
123132 return nil
124133}
125134
135+ func shouldRelease (library * config.Library , filesChanged []string , srcPath string ) bool {
136+ if library .SkipPublish {
137+ return false
138+ }
139+ pathWithTrailingSlash := srcPath
140+ if ! strings .HasSuffix (pathWithTrailingSlash , "/" ) {
141+ pathWithTrailingSlash = pathWithTrailingSlash + "/"
142+ }
143+ for _ , path := range filesChanged {
144+ if strings .Contains (path , pathWithTrailingSlash ) {
145+ return true
146+ }
147+ }
148+ return false
149+ }
150+
126151func getSrcPathForLanguage (cfg * config.Config , libConfig * config.Library ) (string , error ) {
127152 srcPath := ""
128153 switch cfg .Language {
@@ -137,11 +162,18 @@ func getSrcPathForLanguage(cfg *config.Config, libConfig *config.Library) (strin
137162 return srcPath , nil
138163}
139164
140- func releaseLibrary (ctx context.Context , cfg * config.Config , libConfig * config.Library , srcPath string ) error {
165+ func releaseLibrary (ctx context.Context , cfg * config.Config , libConfig * config.Library , srcPath , lastTag , gitExe string ) error {
141166 switch cfg .Language {
142167 case languageFake :
143168 return fakeReleaseLibrary (libConfig )
144169 case languageRust :
170+ release , err := rust .ManifestVersionNeedsBump (gitExe , lastTag , srcPath + "/Cargo.toml" )
171+ if err != nil {
172+ return err
173+ }
174+ if ! release {
175+ return nil
176+ }
145177 if err := rust .ReleaseLibrary (libConfig , srcPath ); err != nil {
146178 return err
147179 }
@@ -166,22 +198,3 @@ func libraryByName(c *config.Config, name string) (*config.Library, error) {
166198 }
167199 return nil , errLibraryNotFound
168200}
169-
170- // shouldReleaseLibrary looks up last release tag and returns true if any commits have been made
171- // in the provided path since then.
172- func shouldReleaseLibrary (ctx context.Context , cfg * config.Config , path string ) (bool , error ) {
173- if cfg .Release == nil {
174- return false , errReleaseConfigEmpty
175- }
176- gitExe := command .GetExecutablePath (cfg .Release .Preinstalled , "git" )
177- lastTag , err := git .GetLastTag (ctx , gitExe , cfg .Release .Remote , cfg .Release .Branch )
178- if err != nil {
179- return false , err
180- }
181- numberOfChanges , err := git .ChangesInDirectorySinceTag (ctx , gitExe , lastTag , path )
182- if err != nil {
183- return false , err
184- }
185-
186- return numberOfChanges > 0 , nil
187- }
0 commit comments