@@ -22,11 +22,16 @@ import (
2222var logger = log .With ().Str ("component" , "release" ).Logger ()
2323
2424func Release (context * context.Context , repositoryPath string , version * semver.Version , sourceRef string ) {
25+ remoteName := findRemoteName ()
26+ if remoteName == "" {
27+ logger .Fatal ().Msg ("failed to find remote for coreruleset/coreruleset" )
28+ }
29+ fetchSourceRef (remoteName , sourceRef )
2530 branchName := fmt .Sprintf ("v%d.%d.%d" , version .Major (), version .Minor (), version .Patch ())
2631 createAndCheckOutBranch (context , branchName , sourceRef )
27- copyright .UpdateCopyright (context , version , uint16 (time .Now ().Year ()))
32+ copyright .UpdateCopyright (context , version , uint16 (time .Now ().Year ()), [] string { "util/crs-rules-check/examples" } )
2833 createCommit (context , branchName )
29- pushBranch (branchName )
34+ pushBranch (remoteName , branchName )
3035 createPullRequest (version , branchName , sourceRef )
3136}
3237
@@ -43,7 +48,7 @@ func createAndCheckOutBranch(context *context.Context, branchName string, source
4348}
4449
4550func createCommit (context * context.Context , branchName string ) {
46- out , err := runGit (context .RootDir (), "commit" , "-am" , "Release " + branchName )
51+ out , err := runGit (context .RootDir (), "commit" , "-am" , "chore: release " + branchName )
4752 if err != nil {
4853 logger .Fatal ().Err (err ).Bytes ("command-output" , out ).Msg ("failed to create commit for release" )
4954 }
@@ -83,14 +88,18 @@ func createPullRequest(version *semver.Version, branchName string, targetBranchN
8388 }
8489
8590 type prBody struct {
86- Title string `json:"title"`
87- Head string `json:"head"`
88- Base string `json:"base"`
91+ Title string `json:"title"`
92+ Head string `json:"head"`
93+ Base string `json:"base"`
94+ Label string `json:"label"`
95+ Reviewer string `json:"reviewer"`
8996 }
9097 bodyJson , err := json .Marshal (& prBody {
91- Title : fmt .Sprintf ("Release v%d.%d%d" , version .Major (), version .Minor (), version .Patch ()),
92- Head : "coreruleset:" + branchName ,
93- Base : targetBranchName ,
98+ Title : fmt .Sprintf ("Release v%d.%d%d" , version .Major (), version .Minor (), version .Patch ()),
99+ Head : "coreruleset:" + branchName ,
100+ Base : targetBranchName ,
101+ Label : "release:ignore" ,
102+ Reviewer : "coreruleset/core-developers" ,
94103 })
95104 if err != nil {
96105 log .Fatal ().Err (err ).Msg ("failed to serialize body of GH REST request" )
@@ -103,24 +112,15 @@ func createPullRequest(version *semver.Version, branchName string, targetBranchN
103112 defer response .Body .Close ()
104113}
105114
106- func pushBranch (branchName string ) {
107- out , err := runGit ("remote " , "-v" )
115+ func pushBranch (remoteName string , branchName string ) {
116+ out , err := runGit ("push " , remoteName , branchName )
108117 if err != nil {
109118 logger .Fatal ().Err (err ).Bytes ("command-output" , out )
110119 }
111- var remoteName string
112- scanner := bufio .NewScanner (bytes .NewReader (out ))
113- for scanner .Scan () {
114- line := scanner .Text ()
115- if strings .Contains (line , "coreruleset/coreruleset" ) {
116- remoteName = strings .Split (line , " " )[0 ]
117- }
118- }
119- if remoteName == "" {
120- logger .Fatal ().Msg ("failed to find remote to push release branch to" )
121- }
120+ }
122121
123- out , err = runGit ("push" , remoteName , branchName )
122+ func fetchSourceRef (remoteName string , sourceRef string ) {
123+ out , err := runGit ("fetch" , remoteName , sourceRef )
124124 if err != nil {
125125 logger .Fatal ().Err (err ).Bytes ("command-output" , out )
126126 }
@@ -131,3 +131,20 @@ func runGit(repositoryPath string, args ...string) ([]byte, error) {
131131 cmd .Dir = repositoryPath
132132 return cmd .CombinedOutput ()
133133}
134+
135+ func findRemoteName () string {
136+ out , err := runGit ("remote" , "-v" )
137+ if err != nil {
138+ logger .Fatal ().Err (err ).Bytes ("command-output" , out )
139+ }
140+ var remoteName string
141+ scanner := bufio .NewScanner (bytes .NewReader (out ))
142+ for scanner .Scan () {
143+ line := scanner .Text ()
144+ if strings .Contains (line , "coreruleset/coreruleset" ) {
145+ remoteName = strings .Split (line , " " )[0 ]
146+ }
147+ }
148+
149+ return remoteName
150+ }
0 commit comments