From a1fecf3a87cabd56e99f4c0b3bb55e845307a1a4 Mon Sep 17 00:00:00 2001 From: Victor Martinez Date: Thu, 12 Mar 2026 17:39:24 +0100 Subject: [PATCH 1/4] ci(ff): support feature freeze automation phase 1 --- go.mod | 18 ++ go.sum | 93 +++++++++ magefile.go | 540 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 651 insertions(+) diff --git a/go.mod b/go.mod index 3f6020c326..fb6c961b57 100644 --- a/go.mod +++ b/go.mod @@ -48,11 +48,15 @@ require ( ) require ( + dario.cat/mergo v1.0.0 // indirect github.com/Microsoft/go-winio v0.6.1 // indirect + github.com/ProtonMail/go-crypto v1.0.0 // indirect github.com/apapsch/go-jsonmerge/v2 v2.0.0 // indirect github.com/armon/go-radix v1.0.0 // indirect github.com/beorn7/perks v1.0.1 // indirect github.com/cespare/xxhash/v2 v2.3.0 // indirect + github.com/cloudflare/circl v1.3.7 // indirect + github.com/cyphar/filepath-securejoin v0.2.5 // indirect github.com/davecgh/go-spew v1.1.1 // indirect github.com/dustin/go-humanize v1.0.1 // indirect github.com/elastic/elastic-transport-go/v8 v8.8.0 // indirect @@ -60,31 +64,44 @@ require ( github.com/elastic/go-sysinfo v1.15.1 // indirect github.com/elastic/go-windows v1.0.2 // indirect github.com/elastic/gosigar v0.14.3 // indirect + github.com/emirpasic/gods v1.18.1 // indirect github.com/fatih/color v1.15.0 // indirect + github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect + github.com/go-git/go-billy/v5 v5.5.0 // indirect + github.com/go-git/go-git/v5 v5.12.0 // indirect github.com/go-logr/logr v1.4.3 // indirect github.com/go-logr/stdr v1.2.2 // indirect github.com/go-ole/go-ole v1.3.0 // indirect + github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect + github.com/google/go-github/v68 v68.0.0 // indirect + github.com/google/go-querystring v1.1.0 // indirect github.com/google/uuid v1.6.0 // indirect github.com/gorilla/websocket v1.5.3 // indirect github.com/inconshreveable/mousetrap v1.1.0 // indirect + github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect github.com/josharian/intern v1.0.0 // indirect + github.com/kevinburke/ssh_config v1.2.0 // indirect github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect github.com/mattn/go-colorable v0.1.13 // indirect github.com/mattn/go-isatty v0.0.20 // indirect github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect + github.com/pjbgf/sha1cd v0.3.0 // indirect github.com/pkg/errors v0.9.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect github.com/prometheus/client_model v0.6.2 // indirect github.com/prometheus/common v0.66.1 // indirect github.com/prometheus/procfs v0.16.1 // indirect + github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 // indirect github.com/shirou/gopsutil/v4 v4.24.7 // indirect github.com/shoenig/go-m1cpu v0.1.6 // indirect + github.com/skeema/knownhosts v1.2.2 // indirect github.com/spf13/pflag v1.0.9 // indirect github.com/stretchr/objx v0.5.2 // indirect github.com/tklauser/go-sysconf v0.3.12 // indirect github.com/tklauser/numcpus v0.6.1 // indirect github.com/x448/float16 v0.8.4 // indirect + github.com/xanzy/ssh-agent v0.3.3 // indirect github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78 // indirect github.com/yusufpapurcu/wmi v1.2.4 // indirect go.elastic.co/ecszap v1.0.3 // indirect @@ -100,6 +117,7 @@ require ( golang.org/x/text v0.34.0 // indirect golang.org/x/tools v0.41.0 // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20251202230838-ff82c1b0f217 // indirect + gopkg.in/warnings.v0 v0.1.2 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect howett.net/plist v1.0.1 // indirect ) diff --git a/go.sum b/go.sum index 5400b45c66..7920f5c528 100644 --- a/go.sum +++ b/go.sum @@ -1,7 +1,12 @@ +dario.cat/mergo v1.0.0 h1:AGCNq9Evsj31mOgNPcLyXc+4PNABt905YmuqPYYpBWk= +dario.cat/mergo v1.0.0/go.mod h1:uNxQE+84aUszobStD9th8a29P2fMDhsBdgRYvZOxGmk= +github.com/Microsoft/go-winio v0.5.2/go.mod h1:WpS1mjBmmwHBEWmogvA2mj8546UReBk4v8QkMxJ6pZY= github.com/Microsoft/go-winio v0.6.1 h1:9/kr64B9VUZrLm5YYwbGtUJnMgqWVOdUAXu6Migciow= github.com/Microsoft/go-winio v0.6.1/go.mod h1:LRdKpFKfdobln8UmuiYcKPot9D2v6svN5+sAH+4kjUM= github.com/Pallinder/go-randomdata v1.2.0 h1:DZ41wBchNRb/0GfsePLiSwb0PHZmT67XY00lCDlaYPg= github.com/Pallinder/go-randomdata v1.2.0/go.mod h1:yHmJgulpD2Nfrm0cR9tI/+oAgRqCQQixsA8HyRZfV9Y= +github.com/ProtonMail/go-crypto v1.0.0 h1:LRuvITjQWX+WIfr930YHG2HNfjR1uOfyf5vE0kC2U78= +github.com/ProtonMail/go-crypto v1.0.0/go.mod h1:EjAoLdwvbIOoOQr3ihjnSoLZRtE8azugULFRteWMNc0= github.com/RaveNoX/go-jsoncommentstrip v1.0.0/go.mod h1:78ihd09MekBnJnxpICcwzCMzGrKSKYe4AqU6PDYYpjk= github.com/apapsch/go-jsonmerge/v2 v2.0.0 h1:axGnT1gRIfimI7gJifB699GoE/oq+F2MU7Dml6nw9rQ= github.com/apapsch/go-jsonmerge/v2 v2.0.0/go.mod h1:lvDnEdqiQrp0O42VQGgmlKpxL1AP2+08jFMw88y4klk= @@ -10,12 +15,18 @@ github.com/armon/go-radix v1.0.0/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgI github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= github.com/bmatcuk/doublestar v1.1.1/go.mod h1:UD6OnuiIn0yFxxA2le/rnRU1G4RaI4UvFv1sNto9p6w= +github.com/bwesterb/go-ristretto v1.2.3/go.mod h1:fUIoIZaG73pV5biE2Blr2xEzDoMj7NFEuV9ekS419A0= github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8= github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE= github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs= github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= +github.com/cloudflare/circl v1.3.3/go.mod h1:5XYMA4rFBvNIrhs50XuiBJ15vF2pZn4nnUKZrLbUZFA= +github.com/cloudflare/circl v1.3.7 h1:qlCDlTPz2n9fu58M0Nh1J/JzcFpfgkFHHX3O35r5vcU= +github.com/cloudflare/circl v1.3.7/go.mod h1:sRTcRWXGLrKw6yIGJ+l7amYJFfAXbZG0kBSc8r4zxgA= github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g= +github.com/cyphar/filepath-securejoin v0.2.5 h1:6iR5tXJ/e6tJZzzdMc1km3Sa7RRIVBKAK32O2s7AYfo= +github.com/cyphar/filepath-securejoin v0.2.5/go.mod h1:aPGpWjXOXUn2NCNjFvBE6aRxGGx79pTxQpKOJNYHHl4= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -53,6 +64,8 @@ github.com/elastic/go-windows v1.0.2 h1:yoLLsAsV5cfg9FLhZ9EXZ2n2sQFKeDYrHenkcivY github.com/elastic/go-windows v1.0.2/go.mod h1:bGcDpBzXgYSqM0Gx3DM4+UxFj300SZLixie9u9ixLM8= github.com/elastic/gosigar v0.14.3 h1:xwkKwPia+hSfg9GqrCUKYdId102m9qTJIIr7egmK/uo= github.com/elastic/gosigar v0.14.3/go.mod h1:iXRIGg2tLnu7LBdpqzyQfGDEidKCfWcCMS0WKyPWoMs= +github.com/emirpasic/gods v1.18.1 h1:FXtiHYKDGKCW2KzwZKx0iC0PQmdlorYgdFG9jPXJ1Bc= +github.com/emirpasic/gods v1.18.1/go.mod h1:8tpGGwCnJ5H4r6BWwaV6OrWmMoPhUl5jm/FMNAnJvWQ= github.com/fatih/color v1.15.0 h1:kOqh6YHBtK8aywxGerMG2Eq3H6Qgoqeo13Bk2Mv/nBs= github.com/fatih/color v1.15.0/go.mod h1:0h5ZqXfHYED7Bhv2ZJamyIOUej9KtShiJESRwBDUSsw= github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg= @@ -61,6 +74,12 @@ github.com/fxamacker/cbor/v2 v2.9.0 h1:NpKPmjDBgUfBms6tr6JZkTHtfFGcMKsw3eGcmD/sa github.com/fxamacker/cbor/v2 v2.9.0/go.mod h1:vM4b+DJCtHn+zz7h3FFp/hDAI9WNWCsZj23V5ytsSxQ= github.com/go-chi/chi/v5 v5.2.5 h1:Eg4myHZBjyvJmAFjFvWgrqDTXFyOzjj7YIm3L3mu6Ug= github.com/go-chi/chi/v5 v5.2.5/go.mod h1:X7Gx4mteadT3eDOMTsXzmI4/rwUpOwBHLpAfupzFJP0= +github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 h1:+zs/tPmkDkHx3U66DAb0lQFJrpS6731Oaa12ikc+DiI= +github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376/go.mod h1:an3vInlBmSxCcxctByoQdvwPiA7DTK7jaaFDBTtu0ic= +github.com/go-git/go-billy/v5 v5.5.0 h1:yEY4yhzCDuMGSv83oGxiBotRzhwhNr8VZyphhiu+mTU= +github.com/go-git/go-billy/v5 v5.5.0/go.mod h1:hmexnoNsr2SJU1Ju67OaNz5ASJY3+sHgFRpCtpDCKow= +github.com/go-git/go-git/v5 v5.12.0 h1:7Md+ndsjrzZxbddRDZjF14qK+NN56sy6wkqaVrjZtys= +github.com/go-git/go-git/v5 v5.12.0/go.mod h1:FTM9VKtnI2m65hNI/TenDDDnUf2Q9FHnXYjuz9i5OEY= github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= github.com/go-logr/logr v1.4.3 h1:CjnDlHq8ikf6E492q6eKboGOC0T8CDaOvkHCIg8idEI= github.com/go-logr/logr v1.4.3/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= @@ -74,11 +93,18 @@ github.com/gofrs/uuid/v5 v5.4.0 h1:EfbpCTjqMuGyq5ZJwxqzn3Cbr2d0rUZU7v5ycAk/e/0= github.com/gofrs/uuid/v5 v5.4.0/go.mod h1:CDOjlDMVAtN56jqyRUZh58JT31Tiw7/oQyEXZV+9bD8= github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= +github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da h1:oI5xCqsCo564l8iNU+DwB5epxmsaqB+rhGL0m5jtYqE= +github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek= github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps= +github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU= +github.com/google/go-github/v68 v68.0.0 h1:ZW57zeNZiXTdQ16qrDiZ0k6XucrxZ2CGmoTvcCyQG6s= +github.com/google/go-github/v68 v68.0.0/go.mod h1:K9HAUBovM2sLwM408A18h+wd9vqdLOEqTUCbnRIcx68= +github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8= +github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU= github.com/google/pprof v0.0.0-20230426061923-93006964c1fc h1:AGDHt781oIcL4EFk7cPnvBUYTwU8BEU6GDTO3ZMn1sE= github.com/google/pprof v0.0.0-20230426061923-93006964c1fc/go.mod h1:79YE0hCXdHag9sBkw2o+N/YnZtTkXi0UT9Nnixa5eYk= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= @@ -93,14 +119,21 @@ github.com/hashicorp/golang-lru/v2 v2.0.7 h1:a+bsQ5rvGLjzHuww6tVxozPZFVghXaHOwFs github.com/hashicorp/golang-lru/v2 v2.0.7/go.mod h1:QeFd9opnmA6QUJc5vARoKUSoFhyfM2/ZepoAG6RGpeM= github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= +github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A= +github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo= github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY= github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y= github.com/juju/gnuflag v0.0.0-20171113085948-2ce1bb71843d/go.mod h1:2PavIy+JPciBPrBUjwbNvtwB6RQlve+hkpll6QSNmOE= +github.com/kevinburke/ssh_config v1.2.0 h1:x584FjTGwHzMwvHx18PXxbBVzfnxogHaAReU4gf13a4= +github.com/kevinburke/ssh_config v1.2.0/go.mod h1:CT57kijsi8u/K/BOFA39wgDQJ9CxiF4nAY/ojJ6r6mM= github.com/klauspost/compress v1.18.0 h1:c/Cqfb0r+Yi+JtIEq73FWXVkRonBlf0CRNYc8Zttxdo= github.com/klauspost/compress v1.18.0/go.mod h1:2Pp+KzxcywXVXMr50+X0Q/Lsb43OQHYWRCY2AiWywWQ= +github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= +github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc= @@ -135,6 +168,8 @@ github.com/opencontainers/image-spec v1.0.2 h1:9yCKha/T5XdGtO0q9Q9a6T5NUCsTn/DrB github.com/opencontainers/image-spec v1.0.2/go.mod h1:BtxoFyWECRxE4U/7sNtV5W15zMzWCbyJoFRP3s7yZA0= github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58 h1:onHthvaw9LFnH4t2DcNVpwGmV9E1BkGknEliJkfwQj0= github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58/go.mod h1:DXv8WO4yhMYhSNPKjeNKa5WY9YCIEBRbNzFFPJbWO6Y= +github.com/pjbgf/sha1cd v0.3.0 h1:4D5XXmUUBUl/xQ6IjCkEAbqXskkq/4O7LmGn0AqMDs4= +github.com/pjbgf/sha1cd v0.3.0/go.mod h1:nZ1rrWOcGJ5uZgEEVL1VUM9iRQiZvWdbZjkKyFzPPsI= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= @@ -158,12 +193,17 @@ github.com/rs/zerolog v1.31.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWR github.com/rs/zerolog v1.34.0 h1:k43nTLIwcTVQAncfCw4KZ2VY6ukYoZaBPNOE8txlOeY= github.com/rs/zerolog v1.34.0/go.mod h1:bJsvje4Z08ROH4Nhs5iH600c3IkWhwp44iRc54W6wYQ= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= +github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 h1:n661drycOFuPLCN3Uc8sB6B/s6Z4t2xvBgU1htSHuq8= +github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3/go.mod h1:A0bzQcvG0E7Rwjx0REVgAGH58e96+X0MeOfepqsbeW4= github.com/shirou/gopsutil/v4 v4.24.7 h1:V9UGTK4gQ8HvcnPKf6Zt3XHyQq/peaekfxpJ2HSocJk= github.com/shirou/gopsutil/v4 v4.24.7/go.mod h1:0uW/073rP7FYLOkvxolUQM5rMOLTNmRXnFKafpb71rw= github.com/shoenig/go-m1cpu v0.1.6 h1:nxdKQNcEB6vzgA2E2bvzKIYRuNj7XNJ4S/aRSwKzFtM= github.com/shoenig/go-m1cpu v0.1.6/go.mod h1:1JJMcUBvfNwpq05QDQVAnx3gUHr9IYF7GNg9SUEw2VQ= github.com/shoenig/test v0.6.4 h1:kVTaSd7WLz5WZ2IaoM0RSzRsUD+m8wRR+5qvntpn4LU= github.com/shoenig/test v0.6.4/go.mod h1:byHiCGXqrVaflBLAMq/srcZIHynQPQgeyvkvXnjqq0k= +github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0= +github.com/skeema/knownhosts v1.2.2 h1:Iug2P4fLmDw9f41PB6thxUkNUkJzB5i+1/exaj40L3A= +github.com/skeema/knownhosts v1.2.2/go.mod h1:xYbVRSPxqBZFrdmDyMmsOs+uX1UZC3nTN3ThzgDxUwo= github.com/spf13/cobra v1.10.2 h1:DMTTonx5m65Ic0GOoRY2c16WCbHxOOw6xxezuLaBpcU= github.com/spf13/cobra v1.10.2/go.mod h1:7C1pvHqHw5A4vrJfjNwvOdzYu0Gml16OCs2GRiTUUS4= github.com/spf13/pflag v1.0.9 h1:9exaQaMOCwffKiiiYk6/BndUBv+iRViNW+4lEMi0PvY= @@ -172,6 +212,7 @@ github.com/spkg/bom v0.0.0-20160624110644-59b7046e48ad/go.mod h1:qLr4V1qq6nMqFKk github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY= github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= +github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= @@ -183,8 +224,11 @@ github.com/tklauser/numcpus v0.6.1 h1:ng9scYS7az0Bk4OZLvrNXNSAO2Pxr1XXRAPyjhIx+F github.com/tklauser/numcpus v0.6.1/go.mod h1:1XfjsgE2zo8GVw7POkMbHENHzVg3GzmoZ9fESEdAacY= github.com/x448/float16 v0.8.4 h1:qLwI1I70+NjRFUR3zs1JPUCgaCXSh3SW62uAKT1mSBM= github.com/x448/float16 v0.8.4/go.mod h1:14CWIYCyZA/cWjXOioeEpHeN/83MdbZDRQHoFcYsOfg= +github.com/xanzy/ssh-agent v0.3.3 h1:+/15pJfg/RsTxqYcX6fHqOXZwwMP+2VyYWJeWM2qQFM= +github.com/xanzy/ssh-agent v0.3.3/go.mod h1:6dzNDKs0J9rVPHPhaGCukekBHKqfl+L3KghI1Bc68Uw= github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78 h1:ilQV1hzziu+LLM3zUTJ0trRztfwgjqKnBWNtSRkbmwM= github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78/go.mod h1:aL8wCCfTfSfmXjznFBSZNN13rSJjlIOI1fUNAtF7rmI= +github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= github.com/yusufpapurcu/wmi v1.2.4 h1:zFUKzehAFReQwLys1b/iSMl+JQGSCSjtVqQn9bBrPo0= github.com/yusufpapurcu/wmi v1.2.4/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0= go.elastic.co/apm/module/apmchiv5/v2 v2.7.4 h1:X46uD2aE3cY4PU9Z7jV3id+4oHKhGz3Ej/bmbfD0JOU= @@ -228,19 +272,48 @@ go.uber.org/zap v1.27.1/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E= go.yaml.in/yaml/v2 v2.4.2 h1:DzmwEr2rDGHl7lsFgAHxmNz/1NlQ7xLIrlN2h5d1eGI= go.yaml.in/yaml/v2 v2.4.2/go.mod h1:081UH+NErpNdqlCXm3TtEran0rJZGxAYx9hb/ELlsPU= go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= +golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= +golang.org/x/crypto v0.3.1-0.20221117191849-2c476679df9a/go.mod h1:hebNnKkNXi2UzZN1eVRvBB7co0a+JxK6XbPiWVs/3J4= +golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU= golang.org/x/crypto v0.48.0 h1:/VRzVqiRSggnhY7gNRxPauEQ5Drw9haKdM0jqfcCFts= golang.org/x/crypto v0.48.0/go.mod h1:r0kV5h3qnFPlQnBSrULhlsRfryS2pmewsg+XfMgkVos= +golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= +golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/mod v0.32.0 h1:9F4d3PHLljb6x//jOyokMv3eX+YDeepZSEo3mFJy93c= golang.org/x/mod v0.32.0/go.mod h1:SgipZ/3h2Ci89DlEtEXWUk/HteuRin+HHhN+WbNhguU= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= +golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= +golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= +golang.org/x/net v0.2.0/go.mod h1:KqCZLdyyvdV855qA2rE3GC2aiw5xGR5TEjj8smXukLY= +golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= +golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc= golang.org/x/net v0.51.0 h1:94R/GTO7mt3/4wIKpcR5gkGmRLOuE/2hNGeWq/GBIFo= golang.org/x/net v0.51.0/go.mod h1:aamm+2QF5ogm02fjy5Bb7CQ0WMt1/WVM7FtyaTLlA9Y= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.20.0 h1:e0PTpb7pjO8GAtTs2dQ6jYa5BWYlMuX047Dco/pItO4= golang.org/x/sync v0.20.0/go.mod h1:9xrNwdLfx4jkKbNva9FpL6vEN7evnE43NNNJQ2LF3+0= golang.org/x/sys v0.0.0-20180810173357-98c5dad5d1a0/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201204225414-ed752295db88/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +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.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= @@ -248,12 +321,29 @@ golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.41.0 h1:Ivj+2Cp/ylzLiEU89QhWblYnOE9zerudt9Ftecq2C6k= golang.org/x/sys v0.41.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks= +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.2.0/go.mod h1:TVmDHMZPmdnySmBfhjOoOdhjzdE1h4u1VwSiw2l1Nuc= +golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= +golang.org/x/term v0.6.0/go.mod h1:m6U89DPEgQRMq3DNkDClhWw02AUbt2daBVO4cn4Hv9U= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.3/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.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= +golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= +golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= golang.org/x/text v0.34.0 h1:oL/Qq0Kdaqxa1KbNeMKwQq0reLCCaFtqu2eNuSeNHbk= golang.org/x/text v0.34.0/go.mod h1:homfLqTYRFyVYemLBFl5GgL/DWEiH5wcsQ5gSh1yziA= golang.org/x/time v0.15.0 h1:bbrp8t3bGUeFOx08pvsMYRTCVSMk89u4tKbNOZbp88U= golang.org/x/time v0.15.0/go.mod h1:Y4YMaQmXwGQZoFaVFk4YpCt4FLQMYKZe9oeV/f4MSno= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= +golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= golang.org/x/tools v0.41.0 h1:a9b8iMweWG+S0OBnlU36rzLp20z1Rp10w+IY2czHTQc= golang.org/x/tools v0.41.0/go.mod h1:XSY6eDqxVNiYgezAVqqCeihT4j1U2CCsqvH3WhQpnlg= +golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= gonum.org/v1/gonum v0.16.0 h1:5+ul4Swaf3ESvrOnidPp4GZbzf0mxVQpDCYUQE7OJfk= gonum.org/v1/gonum v0.16.0/go.mod h1:fef3am4MQ93R2HHpKnLk4/Tbh/s0+wqD5nfa6Pnwy4E= @@ -264,10 +354,13 @@ google.golang.org/grpc v1.79.2/go.mod h1:KmT0Kjez+0dde/v2j9vzwoAScgEPx/Bw1CYChhH google.golang.org/protobuf v1.36.11 h1:fV6ZwhNocDyBLK0dj+fg8ektcVegBBuEolpbTQyBNVE= google.golang.org/protobuf v1.36.11/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= gopkg.in/mcuadros/go-syslog.v2 v2.3.0 h1:kcsiS+WsTKyIEPABJBJtoG0KkOS6yzvJ+/eZlhD79kk= gopkg.in/mcuadros/go-syslog.v2 v2.3.0/go.mod h1:l5LPIyOOyIdQquNg+oU6Z3524YwrcqEm0aKH+5zpt2U= +gopkg.in/warnings.v0 v0.1.2 h1:wFXVbFY8DY5/xOe1ECiWdKCzZlxgshcYVNkBHstARME= +gopkg.in/warnings.v0 v0.1.2/go.mod h1:jksf8JmL6Qr/oQM2OXTHunEvvTAsrWBLb6OOjuVWRNI= gopkg.in/yaml.v1 v1.0.0-20140924161607-9f9df34309c0/go.mod h1:WDnlLJ4WF5VGsH/HVa3CI79GS0ol3YnhVnKP89i0kNg= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= diff --git a/magefile.go b/magefile.go index 06aecf9878..6b92365d3e 100644 --- a/magefile.go +++ b/magefile.go @@ -40,6 +40,11 @@ import ( "sync" "time" + "github.com/go-git/go-git/v5" + "github.com/go-git/go-git/v5/config" + "github.com/go-git/go-git/v5/plumbing" + "github.com/go-git/go-git/v5/plumbing/object" + "github.com/google/go-github/v68/github" "github.com/magefile/mage/mg" "github.com/magefile/mage/sh" "gopkg.in/yaml.v3" @@ -364,6 +369,9 @@ type Test mg.Namespace // Docker is the namespace for docker related tasks. type Docker mg.Namespace +// Release is the namespace for release automation. +type Release mg.Namespace + // envToBool reads the env var string s and parses it as a bool. func envToBool(s string) bool { v, ok := os.LookupEnv(s) @@ -2255,3 +2263,535 @@ func (Test) CloudE2ERun() error { err = errors.Join(err, os.WriteFile(filepath.Join("build", "test-cloude2e.out"), b.Bytes(), 0o644)) return err } + +// ============================================================================ +// Release Automation Functions +// ============================================================================ + +// ReleaseConfig holds configuration for release operations +type ReleaseConfig struct { + Version string + BaseBranch string + ReleaseBranch string + Owner string + Repo string + AuthorName string + AuthorEmail string +} + +// loadReleaseConfigFromEnv loads release configuration from environment variables +func loadReleaseConfigFromEnv() (*ReleaseConfig, error) { + version := os.Getenv("CURRENT_RELEASE") + if version == "" { + return nil, fmt.Errorf("CURRENT_RELEASE environment variable not set") + } + + baseBranch := os.Getenv("BASE_BRANCH") + if baseBranch == "" { + baseBranch = "main" + } + + // Extract major.minor for release branch (e.g., "9.4.0" -> "9.4") + parts := strings.Split(version, ".") + if len(parts) < 2 { + return nil, fmt.Errorf("invalid version format: %s (expected X.Y.Z)", version) + } + releaseBranch := fmt.Sprintf("%s.%s", parts[0], parts[1]) + + owner := os.Getenv("PROJECT_OWNER") + if owner == "" { + owner = "elastic" + } + + repo := os.Getenv("PROJECT_REPO") + if repo == "" { + repo = "fleet-server" + } + + authorName := os.Getenv("GITHUB_USERNAME") + if authorName == "" { + authorName = "elasticmachine" + } + + authorEmail := os.Getenv("GITHUB_EMAIL") + if authorEmail == "" { + authorEmail = "infra-root+elasticmachine@elastic.co" + } + + return &ReleaseConfig{ + Version: version, + BaseBranch: baseBranch, + ReleaseBranch: releaseBranch, + Owner: owner, + Repo: repo, + AuthorName: authorName, + AuthorEmail: authorEmail, + }, nil +} + +// UpdateVersion updates the version in version/version.go +func (Release) UpdateVersion(newVersion string) error { + versionFile := "version/version.go" + + content, err := os.ReadFile(versionFile) + if err != nil { + return fmt.Errorf("failed to read %s: %w", versionFile, err) + } + + // Replace the version string + // Pattern: const DefaultVersion = "X.Y.Z" + re := regexp.MustCompile(`(const\s+DefaultVersion\s*=\s*)"[^"]+"`) + newContent := re.ReplaceAllString(string(content), `${1}"`+newVersion+`"`) + + if newContent == string(content) { + return fmt.Errorf("version pattern not found in %s", versionFile) + } + + err = os.WriteFile(versionFile, []byte(newContent), 0644) + if err != nil { + return fmt.Errorf("failed to write %s: %w", versionFile, err) + } + + fmt.Printf("✓ Updated version to %s in %s\n", newVersion, versionFile) + return nil +} + +// UpdateMergify adds a new backport rule to .mergify.yml +func (Release) UpdateMergify(version string) error { + mergifyFile := ".mergify.yml" + + // Read the YAML file + content, err := os.ReadFile(mergifyFile) + if err != nil { + return fmt.Errorf("failed to read %s: %w", mergifyFile, err) + } + + // Extract major.minor from version (e.g., "9.4.0" -> "9.4") + parts := strings.Split(version, ".") + if len(parts) < 2 { + return fmt.Errorf("invalid version format: %s (expected X.Y.Z)", version) + } + branchVersion := fmt.Sprintf("%s.%s", parts[0], parts[1]) + + // Check if rule already exists + searchPattern := fmt.Sprintf("backport patches to %s branch", branchVersion) + if strings.Contains(string(content), searchPattern) { + fmt.Printf(" Backport rule for %s already exists\n", branchVersion) + return nil + } + + // Create new backport rule following the existing format + newRule := fmt.Sprintf(` - name: backport patches to %s branch + conditions: + - merged + - label=backport-%s + actions: + backport: + branches: + - "%s" +`, branchVersion, branchVersion, branchVersion) + + // Append the new rule to the end of the file + output := string(content) + newRule + + // Write back to file + err = os.WriteFile(mergifyFile, []byte(output), 0644) + if err != nil { + return fmt.Errorf("failed to write %s: %w", mergifyFile, err) + } + + fmt.Printf("✓ Added backport rule for %s to %s\n", branchVersion, mergifyFile) + return nil +} + +// GitRepo represents a Git repository with common operations +type GitRepo struct { + repo *git.Repository +} + +// openRepo opens the Git repository at the given path +func openRepo(path string) (*GitRepo, error) { + repo, err := git.PlainOpen(path) + if err != nil { + return nil, fmt.Errorf("failed to open git repo: %w", err) + } + return &GitRepo{repo: repo}, nil +} + +// createBranch creates and checks out a new branch +func (g *GitRepo) createBranch(branchName string) error { + w, err := g.repo.Worktree() + if err != nil { + return fmt.Errorf("failed to get worktree: %w", err) + } + + // Get current HEAD reference + headRef, err := g.repo.Head() + if err != nil { + return fmt.Errorf("failed to get HEAD: %w", err) + } + + // Create new branch reference + refName := plumbing.NewBranchReferenceName(branchName) + ref := plumbing.NewHashReference(refName, headRef.Hash()) + + err = g.repo.Storer.SetReference(ref) + if err != nil { + return fmt.Errorf("failed to create branch: %w", err) + } + + // Checkout the new branch + err = w.Checkout(&git.CheckoutOptions{ + Branch: refName, + }) + if err != nil { + return fmt.Errorf("failed to checkout branch: %w", err) + } + + fmt.Printf("✓ Created and checked out branch: %s\n", branchName) + return nil +} + +// commitAll commits all changes with the given message +func (g *GitRepo) commitAll(message, authorName, authorEmail string) error { + w, err := g.repo.Worktree() + if err != nil { + return fmt.Errorf("failed to get worktree: %w", err) + } + + // Add all changes + err = w.AddWithOptions(&git.AddOptions{ + All: true, + }) + if err != nil { + return fmt.Errorf("failed to add changes: %w", err) + } + + // Create commit + commit, err := w.Commit(message, &git.CommitOptions{ + Author: &object.Signature{ + Name: authorName, + Email: authorEmail, + When: time.Now(), + }, + }) + if err != nil { + return fmt.Errorf("failed to commit: %w", err) + } + + fmt.Printf("✓ Committed changes: %s\n", commit.String()[:7]) + return nil +} + +// push pushes the current branch to the remote +func (g *GitRepo) push(remoteName string, dryRun bool) error { + if dryRun { + fmt.Printf(" [DRY RUN] Would push to remote: %s\n", remoteName) + return nil + } + + err := g.repo.Push(&git.PushOptions{ + RemoteName: remoteName, + }) + if err != nil && !errors.Is(err, git.NoErrAlreadyUpToDate) { + return fmt.Errorf("failed to push: %w", err) + } + + if errors.Is(err, git.NoErrAlreadyUpToDate) { + fmt.Println(" Branch already up to date on remote") + } else { + fmt.Printf("✓ Pushed to remote: %s\n", remoteName) + } + return nil +} + +// getCurrentBranch returns the name of the current branch +func (g *GitRepo) getCurrentBranch() (string, error) { + ref, err := g.repo.Head() + if err != nil { + return "", fmt.Errorf("failed to get HEAD: %w", err) + } + + if !ref.Name().IsBranch() { + return "", fmt.Errorf("HEAD is not a branch") + } + + return ref.Name().Short(), nil +} + +// setRemoteURL sets the URL for a remote +func (g *GitRepo) setRemoteURL(remoteName, url string) error { + _, err := g.repo.Remote(remoteName) + if errors.Is(err, git.ErrRemoteNotFound) { + // Remote doesn't exist, create it + _, err = g.repo.CreateRemote(&config.RemoteConfig{ + Name: remoteName, + URLs: []string{url}, + }) + if err != nil { + return fmt.Errorf("failed to create remote: %w", err) + } + fmt.Printf("✓ Created remote %s: %s\n", remoteName, url) + return nil + } else if err != nil { + return fmt.Errorf("failed to get remote: %w", err) + } + + // Update remote URL + err = g.repo.DeleteRemote(remoteName) + if err != nil { + return fmt.Errorf("failed to delete remote: %w", err) + } + + _, err = g.repo.CreateRemote(&config.RemoteConfig{ + Name: remoteName, + URLs: []string{url}, + }) + if err != nil { + return fmt.Errorf("failed to recreate remote: %w", err) + } + + fmt.Printf("✓ Updated remote %s: %s\n", remoteName, url) + return nil +} + +// newGitHubClient creates a new GitHub client from environment +func newGitHubClient() (*github.Client, error) { + token := os.Getenv("GITHUB_TOKEN") + if token == "" { + return nil, fmt.Errorf("GITHUB_TOKEN environment variable not set") + } + + client := github.NewClient(nil).WithAuthToken(token) + return client, nil +} + +// createPR creates a pull request on GitHub +func createPR(client *github.Client, cfg *ReleaseConfig, title, body, head, base string, dryRun bool) (*github.PullRequest, error) { + if dryRun { + fmt.Printf(" [DRY RUN] Would create PR:\n") + fmt.Printf(" Title: %s\n", title) + fmt.Printf(" Head: %s\n", head) + fmt.Printf(" Base: %s\n", base) + return nil, nil + } + + pr, _, err := client.PullRequests.Create(context.Background(), cfg.Owner, cfg.Repo, &github.NewPullRequest{ + Title: github.String(title), + Head: github.String(head), + Base: github.String(base), + Body: github.String(body), + }) + if err != nil { + return nil, fmt.Errorf("failed to create PR: %w", err) + } + + fmt.Printf("✓ Created PR #%d: %s\n", *pr.Number, *pr.HTMLURL) + return pr, nil +} + +// PrepareMajorMinor prepares files for a major/minor release +func (Release) PrepareMajorMinor() error { + cfg, err := loadReleaseConfigFromEnv() + if err != nil { + return err + } + + fmt.Printf("Preparing major/minor release for version %s\n", cfg.Version) + + // Update version + r := Release{} + if err := r.UpdateVersion(cfg.Version); err != nil { + return err + } + + // Update mergify + if err := r.UpdateMergify(cfg.Version); err != nil { + return err + } + + fmt.Println("✓ Major/minor release preparation complete") + fmt.Printf(" Next steps:\n") + fmt.Printf(" 1. Review changes: git diff\n") + fmt.Printf(" 2. Create branch: mage release:createBranch\n") + fmt.Printf(" 3. Create PR: mage release:createPR\n") + + return nil +} + +// CreateBranch creates a release branch with all changes committed +func (Release) CreateBranch() error { + cfg, err := loadReleaseConfigFromEnv() + if err != nil { + return err + } + + dryRun := os.Getenv("DRY_RUN") == "true" + + repo, err := openRepo(".") + if err != nil { + return err + } + + branchName := cfg.ReleaseBranch + fmt.Printf("Creating release branch: %s\n", branchName) + + if !dryRun { + // Create and checkout branch + if err := repo.createBranch(branchName); err != nil { + return err + } + + // Commit all changes + commitMsg := fmt.Sprintf("[Release] Prepare %s release", cfg.Version) + if err := repo.commitAll(commitMsg, cfg.AuthorName, cfg.AuthorEmail); err != nil { + return err + } + } else { + fmt.Printf(" [DRY RUN] Would create branch %s and commit changes\n", branchName) + } + + // Push to remote + if err := repo.push("origin", dryRun); err != nil { + return err + } + + return nil +} + +// CreatePR creates a pull request for the release +func (Release) CreatePR() error { + cfg, err := loadReleaseConfigFromEnv() + if err != nil { + return err + } + + dryRun := os.Getenv("DRY_RUN") == "true" + + client, err := newGitHubClient() + if err != nil { + return err + } + + title := fmt.Sprintf("[Release] %s", cfg.Version) + body := fmt.Sprintf("## Release %s\n\nThis PR prepares the %s release.\n\n### Changes\n- Updated version to %s\n- Added mergify backport rule for %s\n", + cfg.Version, cfg.Version, cfg.Version, cfg.ReleaseBranch) + + _, err = createPR(client, cfg, title, body, cfg.ReleaseBranch, cfg.BaseBranch, dryRun) + return err +} + +// RunMajorMinor orchestrates the complete major/minor release workflow +func (Release) RunMajorMinor() error { + cfg, err := loadReleaseConfigFromEnv() + if err != nil { + return err + } + + dryRun := os.Getenv("DRY_RUN") == "true" + if dryRun { + fmt.Println("🔍 DRY RUN MODE - No changes will be pushed") + } + + fmt.Printf("🚀 Starting major/minor release workflow for %s\n\n", cfg.Version) + + // Step 1: Prepare files + fmt.Println("Step 1: Preparing release files...") + r := Release{} + if err := r.PrepareMajorMinor(); err != nil { + return fmt.Errorf("failed to prepare release: %w", err) + } + + // Step 2: Create branch + fmt.Println("\nStep 2: Creating release branch...") + if err := r.CreateBranch(); err != nil { + return fmt.Errorf("failed to create branch: %w", err) + } + + // Step 3: Create PR + fmt.Println("\nStep 3: Creating pull request...") + if err := r.CreatePR(); err != nil { + return fmt.Errorf("failed to create PR: %w", err) + } + + fmt.Printf("\n✅ Major/minor release workflow complete for %s\n", cfg.Version) + return nil +} + +// PreparePatch prepares files for a patch release +func (Release) PreparePatch() error { + cfg, err := loadReleaseConfigFromEnv() + if err != nil { + return err + } + + fmt.Printf("Preparing patch release for version %s\n", cfg.Version) + + // Update version + r := Release{} + if err := r.UpdateVersion(cfg.Version); err != nil { + return err + } + + fmt.Println("✓ Patch release preparation complete") + return nil +} + +// RunPatch orchestrates the complete patch release workflow +func (Release) RunPatch() error { + cfg, err := loadReleaseConfigFromEnv() + if err != nil { + return err + } + + dryRun := os.Getenv("DRY_RUN") == "true" + if dryRun { + fmt.Println("🔍 DRY RUN MODE - No changes will be pushed") + } + + fmt.Printf("🚀 Starting patch release workflow for %s\n\n", cfg.Version) + + // Prepare files + fmt.Println("Preparing patch release files...") + r := Release{} + if err := r.PreparePatch(); err != nil { + return fmt.Errorf("failed to prepare patch release: %w", err) + } + + fmt.Printf("\n✅ Patch release workflow complete for %s\n", cfg.Version) + fmt.Println(" Review changes and commit to the release branch") + return nil +} + +// PrepareNext prepares files for the next development cycle +func (Release) PrepareNext() error { + // Get current version + currentVersion := os.Getenv("CURRENT_RELEASE") + if currentVersion == "" { + return fmt.Errorf("CURRENT_RELEASE environment variable not set") + } + + // Calculate next version (increment minor) + parts := strings.Split(currentVersion, ".") + if len(parts) < 3 { + return fmt.Errorf("invalid version format: %s", currentVersion) + } + + minor, err := strconv.Atoi(parts[1]) + if err != nil { + return fmt.Errorf("invalid minor version: %s", parts[1]) + } + + nextVersion := fmt.Sprintf("%s.%d.0", parts[0], minor+1) + + fmt.Printf("Preparing next development cycle: %s -> %s\n", currentVersion, nextVersion) + + // Update version + r := Release{} + if err := r.UpdateVersion(nextVersion); err != nil { + return err + } + + fmt.Printf("✓ Next release preparation complete: %s\n", nextVersion) + return nil +} From 23422b96cf39cff68aa72809842cddf10959e519 Mon Sep 17 00:00:00 2001 From: Victor Martinez Date: Thu, 12 Mar 2026 17:47:55 +0100 Subject: [PATCH 2/4] ci(ff): support feature freeze automation phase 2 --- RELEASE.md | 464 +++++++++++++++++++++++++++++++++++++++++++++++ magefile_test.go | 378 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 842 insertions(+) create mode 100644 RELEASE.md create mode 100644 magefile_test.go diff --git a/RELEASE.md b/RELEASE.md new file mode 100644 index 0000000000..c21df14b31 --- /dev/null +++ b/RELEASE.md @@ -0,0 +1,464 @@ +# Fleet-Server Release Automation + +This document describes the fleet-server release automation implemented using Mage, following the architecture patterns established in elastic-agent. + +## Quick Start + +### Prerequisites + +- Go 1.25+ +- Mage installed (`go install github.com/magefile/mage@latest`) +- GitHub token with repo permissions +- Clean git working directory + +### Major/Minor Release (e.g., 9.5.0) + +```bash +export CURRENT_RELEASE="9.5.0" +export GITHUB_TOKEN="ghp_your_token" +export DRY_RUN=true + +# Test first (updates files locally, no push/PR) +mage release:runMajorMinor + +# Review changes +git status +git diff + +# Run for real +export DRY_RUN=false +mage release:runMajorMinor +``` + +### Patch Release (e.g., 9.4.1) + +```bash +# Checkout base branch +git checkout 9.4 +git pull + +export CURRENT_RELEASE="9.4.1" +export BASE_BRANCH="9.4" +export GITHUB_TOKEN="ghp_your_token" + +mage release:runPatch +``` + +## Available Commands + +### Orchestration Commands (Recommended) + +These commands run the full release workflow: + +- `mage release:runMajorMinor` - Complete major/minor release workflow +- `mage release:runPatch` - Complete patch release workflow + +### Individual Commands + +For manual control or debugging: + +- `mage release:updateVersion ` - Update version in version/version.go +- `mage release:updateMergify ` - Add backport rule to .mergify.yml +- `mage release:prepareMajorMinor` - Prepare all files for major/minor release +- `mage release:preparePatch` - Prepare files for patch release +- `mage release:prepareNext` - Prepare next development cycle +- `mage release:createBranch` - Create and push release branch +- `mage release:createPR` - Create GitHub pull request + +## Environment Variables + +### Required + +| Variable | Description | Example | +|----------|-------------|---------| +| `CURRENT_RELEASE` | Version to release | `9.5.0` | +| `GITHUB_TOKEN` | GitHub API token | `ghp_xxx` | + +### Optional + +| Variable | Description | Default | +|----------|-------------|---------| +| `DRY_RUN` | Test mode (no push/PR) | `false` | +| `BASE_BRANCH` | Base branch for PR | `main` | +| `PROJECT_OWNER` | GitHub repository owner | `elastic` | +| `PROJECT_REPO` | GitHub repository name | `fleet-server` | +| `GITHUB_USERNAME` | Git commit author name | `elasticmachine` | +| `GITHUB_EMAIL` | Git commit author email | `infra-root+elasticmachine@elastic.co` | + +## Workflows + +### Major/Minor Release Workflow + +The `runMajorMinor` command performs these steps: + +1. **Prepare Files** + - Updates `version/version.go` with new version + - Adds backport rule to `.mergify.yml` + +2. **Create Branch** + - Creates release branch (e.g., `9.5`) + - Commits all changes + - Pushes to remote (unless DRY_RUN=true) + +3. **Create PR** + - Creates pull request from release branch to main + - Includes version update details + - (Skipped if DRY_RUN=true) + +### Patch Release Workflow + +The `runPatch` command performs these steps: + +1. **Prepare Files** + - Updates `version/version.go` with patch version + +2. **Commit & Review** + - Changes are prepared for manual review + - No automatic branch creation + - Commit to the current release branch manually + +### Next Development Cycle + +The `prepareNext` command: + +- Increments minor version (e.g., 9.4.0 → 9.5.0) +- Updates `version/version.go` +- Used after a release to bump version on main + +## DRY_RUN Mode + +DRY_RUN mode allows you to test the release process safely: + +```bash +export DRY_RUN=true +mage release:runMajorMinor +``` + +**What DRY_RUN does:** +- ✅ Updates local files (version/version.go, .mergify.yml) +- ✅ Shows what would be committed +- ❌ Does NOT create branches +- ❌ Does NOT push to remote +- ❌ Does NOT create pull requests + +**After DRY_RUN:** +- Review changes with `git diff` +- Discard changes with `git checkout .` +- Or proceed with `DRY_RUN=false` + +## Testing on a Fork + +Before using the release automation in production, it's **highly recommended** to test on your personal fork first. This allows you to verify the workflow end-to-end without affecting the official repository. + +### Step 1: Fork and Clone + +1. Fork the fleet-server repository on GitHub to your account +2. Clone your fork locally: + ```bash + git clone https://github.com/YOUR-USERNAME/fleet-server.git + cd fleet-server + ``` + +3. Ensure you're on a clean main branch: + ```bash + git checkout main + git pull origin main + ``` + +### Step 2: Configure Environment + +Set environment variables to point to your fork: + +```bash +# Point to your fork +export PROJECT_OWNER="your-username" +export PROJECT_REPO="fleet-server" + +# Use a test version to avoid confusion +export CURRENT_RELEASE="9.5.0-test" + +# Your GitHub personal access token +export GITHUB_TOKEN="ghp_your_token" + +# Important: Set to false to actually create branches and PRs +export DRY_RUN=false +``` + +### Step 3: Run the Workflow + +Execute the major/minor release workflow: + +```bash +mage release:runMajorMinor +``` + +This will: +- Update `version/version.go` to `9.5.0-test` +- Add backport rule for `9.5` to `.mergify.yml` +- Create branch `9.5` on your fork +- Push the branch to your fork +- Create a PR from `9.5` → `main` on your fork + +### Step 4: Verify the Results + +Check what was created: + +```bash +# View the created branch +git branch -a | grep 9.5 + +# View the created PR +gh pr list --repo YOUR-USERNAME/fleet-server +``` + +Or visit GitHub: `https://github.com/YOUR-USERNAME/fleet-server/pulls` + +### Step 5: Review and Clean Up + +1. Review the PR on your fork to ensure: + - Version was updated correctly + - Mergify rule was added properly + - Commit message is appropriate + +2. If satisfied, close the PR and delete the test branch: + ```bash + gh pr close BRANCH-NUMBER --repo YOUR-USERNAME/fleet-server --delete-branch + ``` + +3. Reset your fork's main branch: + ```bash + git checkout main + git reset --hard origin/main + ``` + +### Testing Different Scenarios + +#### Test Patch Release on Fork + +```bash +export PROJECT_OWNER="your-username" +export CURRENT_RELEASE="9.4.1-test" +export BASE_BRANCH="9.4" +export GITHUB_TOKEN="ghp_your_token" + +# Create the release branch first if it doesn't exist +git checkout -b 9.4 +git push -u origin 9.4 + +# Run patch workflow +mage release:runPatch +``` + +#### Test with DRY_RUN First + +For extra safety, test with DRY_RUN before creating real branches: + +```bash +export PROJECT_OWNER="your-username" +export DRY_RUN=true +mage release:runMajorMinor + +# Review local changes +git diff + +# If satisfied, run for real +export DRY_RUN=false +mage release:runMajorMinor +``` + +### Troubleshooting Fork Testing + +**Issue: "failed to push: authentication required"** +- Ensure your GITHUB_TOKEN has write access to your fork +- Verify: `gh auth status` + +**Issue: "branch already exists"** +- Delete the existing branch first: + ```bash + git branch -D 9.5 + git push origin --delete 9.5 + ``` + +**Issue: "PR already exists"** +- Close or merge the existing PR first +- Or use a different version number (e.g., `9.5.0-test2`) + +### Best Practices + +1. **Always test on fork first** before running in production +2. **Use test version numbers** (e.g., `X.Y.Z-test`) to distinguish from real releases +3. **Clean up test branches and PRs** after testing to keep your fork tidy +4. **Test both workflows**: major/minor AND patch releases +5. **Verify DRY_RUN mode** works correctly before relying on it + +## Troubleshooting + +### "CURRENT_RELEASE environment variable not set" + +Set the required environment variable: +```bash +export CURRENT_RELEASE="9.5.0" +``` + +### "GITHUB_TOKEN environment variable not set" + +Set your GitHub token: +```bash +export GITHUB_TOKEN=$(gh auth token) +``` + +Or create a personal access token at: https://github.com/settings/tokens + +### "failed to open git repo" + +Ensure you're in the fleet-server repository root: +```bash +cd /path/to/fleet-server +``` + +### "version pattern not found" + +The version file format has changed. Check that `version/version.go` contains: +```go +const DefaultVersion = "X.Y.Z" +``` + +### Uncommitted changes warning + +The workflow warns about uncommitted files but continues. To avoid confusion: +```bash +git status +git stash # or commit your changes +``` + +## Architecture + +Fleet-server follows the same architecture as elastic-agent but is simpler: + +**Key Differences from elastic-agent:** +- Fewer files to update (only 1: `version/version.go`) +- No docs/K8s manifest updates needed +- All code in `magefile.go` (no separate package) +- Simpler implementation (~540 lines vs ~2000+ in elastic-agent) + +**Libraries used:** +- `github.com/go-git/go-git/v5` - Git operations +- `github.com/google/go-github/v68` - GitHub API +- `gopkg.in/yaml.v3` - YAML parsing (already present) + +**No external tools:** +- ❌ No `hub` CLI +- ❌ No `gh` CLI +- ❌ No `sed` / `awk` +- ❌ No `yq` +- ✅ Pure Go implementation + +## Examples + +### Complete Major/Minor Release + +```bash +# 1. Start on main branch +git checkout main +git pull + +# 2. Set up environment +export CURRENT_RELEASE="9.5.0" +export GITHUB_TOKEN=$(gh auth token) + +# 3. Test with dry run +export DRY_RUN=true +mage release:runMajorMinor + +# 4. Review changes +git diff version/version.go +git diff .mergify.yml + +# 5. Run for real +export DRY_RUN=false +mage release:runMajorMinor + +# 6. Check the PR that was created +gh pr list +``` + +### Patch Release on Existing Branch + +```bash +# 1. Checkout release branch +git checkout 9.4 +git pull + +# 2. Set up environment +export CURRENT_RELEASE="9.4.1" +export BASE_BRANCH="9.4" +export GITHUB_TOKEN=$(gh auth token) + +# 3. Run patch workflow +mage release:runPatch + +# 4. Review and commit +git diff +git add version/version.go +git commit -m "Bump version to 9.4.1" +git push +``` + +### Bump Version After Release + +```bash +# 1. After 9.5.0 release, bump main to 9.6.0 +git checkout main + +# 2. Run next version prep +export CURRENT_RELEASE="9.5.0" +mage release:prepareNext + +# 3. Commit the change +git add version/version.go +git commit -m "Bump version to 9.6.0" +git push +``` + +## Testing + +Run unit tests for release functions: + +```bash +go test -v -tags=mage -run "TestUpdate|TestLoad|TestPrepare" . +``` + +Check test coverage: + +```bash +go test -v -tags=mage -coverprofile=coverage.out . +go tool cover -func=coverage.out | grep -E "(UpdateVersion|UpdateMergify)" +``` + +## Migration from Makefile + +This replaces the old Makefile-based release process: + +| Old (Makefile) | New (Mage) | +|----------------|------------| +| `make prepare-major-minor-release` | `mage release:runMajorMinor` | +| `make prepare-patch-release` | `mage release:runPatch` | +| `make update-version VERSION=9.5.0` | `mage release:updateVersion 9.5.0` | +| `make prepare-next-release` | `mage release:prepareNext` | + +**Benefits of Mage:** +- Pure Go (no sed, hub, Python dependencies) +- Type-safe with compile-time checks +- Built-in DRY_RUN mode +- Better error messages +- Easier to test and maintain + +## Support + +- **Issues**: https://github.com/elastic/fleet-server/issues +- **Documentation**: This file and migration plan +- **Code**: `magefile.go` (search for "Release Automation") + +--- + +**Last Updated**: 2026-03-12 diff --git a/magefile_test.go b/magefile_test.go new file mode 100644 index 0000000000..a468713400 --- /dev/null +++ b/magefile_test.go @@ -0,0 +1,378 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License; +// you may not use this file except in compliance with the Elastic License. + +//go:build mage + +package main + +import ( + "os" + "path/filepath" + "strings" + "testing" +) + +func TestUpdateVersion(t *testing.T) { + tests := []struct { + name string + initial string + newVersion string + wantErr bool + wantContent string + }{ + { + name: "update version successfully", + initial: `const DefaultVersion = "9.4.0"`, + newVersion: "9.5.0", + wantErr: false, + wantContent: `const DefaultVersion = "9.5.0"`, + }, + { + name: "update to snapshot version", + initial: `const DefaultVersion = "9.4.0"`, + newVersion: "9.5.0-SNAPSHOT", + wantErr: false, + wantContent: `const DefaultVersion = "9.5.0-SNAPSHOT"`, + }, + { + name: "update with different spacing", + initial: `const DefaultVersion = "9.4.0"`, + newVersion: "9.5.0", + wantErr: false, + wantContent: `const DefaultVersion = "9.5.0"`, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + // Create temp directory and file + tmpDir := t.TempDir() + versionDir := filepath.Join(tmpDir, "version") + err := os.Mkdir(versionDir, 0755) + if err != nil { + t.Fatalf("failed to create version dir: %v", err) + } + + versionFile := filepath.Join(versionDir, "version.go") + initialContent := `// Copyright header + +package version + +` + tt.initial + ` +` + err = os.WriteFile(versionFile, []byte(initialContent), 0644) + if err != nil { + t.Fatalf("failed to write initial file: %v", err) + } + + // Save current dir and change to temp dir + origDir, _ := os.Getwd() + defer os.Chdir(origDir) + os.Chdir(tmpDir) + + // Run UpdateVersion + r := Release{} + err = r.UpdateVersion(tt.newVersion) + + if (err != nil) != tt.wantErr { + t.Errorf("UpdateVersion() error = %v, wantErr %v", err, tt.wantErr) + return + } + + if !tt.wantErr { + // Verify file content + content, err := os.ReadFile(versionFile) + if err != nil { + t.Fatalf("failed to read updated file: %v", err) + } + + if !strings.Contains(string(content), tt.wantContent) { + t.Errorf("UpdateVersion() content = %s, want to contain %s", string(content), tt.wantContent) + } + } + }) + } +} + +func TestUpdateMergify(t *testing.T) { + tests := []struct { + name string + version string + wantErr bool + wantBranch string + wantLabel string + shouldAppend bool + }{ + { + name: "add new backport rule", + version: "9.5.0", + wantErr: false, + wantBranch: "9.5", + wantLabel: "backport-9.5", + shouldAppend: true, + }, + { + name: "version with patch", + version: "10.0.1", + wantErr: false, + wantBranch: "10.0", + wantLabel: "backport-10.0", + shouldAppend: true, + }, + { + name: "invalid version format", + version: "9", + wantErr: true, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + // Create temp directory and file + tmpDir := t.TempDir() + mergifyFile := filepath.Join(tmpDir, ".mergify.yml") + + initialContent := `pull_request_rules: + - name: backport patches to 9.3 branch + conditions: + - merged + - label=backport-9.3 + actions: + backport: + branches: + - "9.3" +` + err := os.WriteFile(mergifyFile, []byte(initialContent), 0644) + if err != nil { + t.Fatalf("failed to write initial file: %v", err) + } + + // Save current dir and change to temp dir + origDir, _ := os.Getwd() + defer os.Chdir(origDir) + os.Chdir(tmpDir) + + // Run UpdateMergify + r := Release{} + err = r.UpdateMergify(tt.version) + + if (err != nil) != tt.wantErr { + t.Errorf("UpdateMergify() error = %v, wantErr %v", err, tt.wantErr) + return + } + + if !tt.wantErr && tt.shouldAppend { + // Verify file content + content, err := os.ReadFile(mergifyFile) + if err != nil { + t.Fatalf("failed to read updated file: %v", err) + } + + contentStr := string(content) + + // Check that the new rule was added + expectedName := "backport patches to " + tt.wantBranch + " branch" + if !strings.Contains(contentStr, expectedName) { + t.Errorf("UpdateMergify() missing rule name: %s", expectedName) + } + + if !strings.Contains(contentStr, tt.wantLabel) { + t.Errorf("UpdateMergify() missing label: %s", tt.wantLabel) + } + + if !strings.Contains(contentStr, `"`+tt.wantBranch+`"`) { + t.Errorf("UpdateMergify() missing branch: %s", tt.wantBranch) + } + + // Verify old rule is still there + if !strings.Contains(contentStr, "9.3") { + t.Error("UpdateMergify() removed existing rules") + } + } + }) + } +} + +func TestUpdateMergify_Idempotent(t *testing.T) { + // Create temp directory and file + tmpDir := t.TempDir() + mergifyFile := filepath.Join(tmpDir, ".mergify.yml") + + initialContent := `pull_request_rules: + - name: backport patches to 9.5 branch + conditions: + - merged + - label=backport-9.5 + actions: + backport: + branches: + - "9.5" +` + err := os.WriteFile(mergifyFile, []byte(initialContent), 0644) + if err != nil { + t.Fatalf("failed to write initial file: %v", err) + } + + // Save current dir and change to temp dir + origDir, _ := os.Getwd() + defer os.Chdir(origDir) + os.Chdir(tmpDir) + + // Run UpdateMergify twice with same version + r := Release{} + err = r.UpdateMergify("9.5.0") + if err != nil { + t.Fatalf("first UpdateMergify() failed: %v", err) + } + + // Get content after first run + content1, _ := os.ReadFile(mergifyFile) + + err = r.UpdateMergify("9.5.0") + if err != nil { + t.Fatalf("second UpdateMergify() failed: %v", err) + } + + // Get content after second run + content2, _ := os.ReadFile(mergifyFile) + + // Content should be identical (idempotent) + if string(content1) != string(content2) { + t.Error("UpdateMergify() is not idempotent - content changed on second run") + } + + // Should only have one rule for 9.5 + count := strings.Count(string(content2), "backport patches to 9.5 branch") + if count != 1 { + t.Errorf("UpdateMergify() created %d rules for 9.5, want 1", count) + } +} + +func TestLoadReleaseConfigFromEnv(t *testing.T) { + tests := []struct { + name string + envVars map[string]string + wantErr bool + wantCheck func(*testing.T, *ReleaseConfig) + }{ + { + name: "all env vars set", + envVars: map[string]string{ + "CURRENT_RELEASE": "9.5.0", + "BASE_BRANCH": "main", + "PROJECT_OWNER": "elastic", + "PROJECT_REPO": "fleet-server", + }, + wantErr: false, + wantCheck: func(t *testing.T, cfg *ReleaseConfig) { + if cfg.Version != "9.5.0" { + t.Errorf("Version = %s, want 9.5.0", cfg.Version) + } + if cfg.ReleaseBranch != "9.5" { + t.Errorf("ReleaseBranch = %s, want 9.5", cfg.ReleaseBranch) + } + if cfg.BaseBranch != "main" { + t.Errorf("BaseBranch = %s, want main", cfg.BaseBranch) + } + }, + }, + { + name: "defaults applied", + envVars: map[string]string{ + "CURRENT_RELEASE": "10.0.0", + }, + wantErr: false, + wantCheck: func(t *testing.T, cfg *ReleaseConfig) { + if cfg.BaseBranch != "main" { + t.Errorf("BaseBranch = %s, want main (default)", cfg.BaseBranch) + } + if cfg.Owner != "elastic" { + t.Errorf("Owner = %s, want elastic (default)", cfg.Owner) + } + if cfg.Repo != "fleet-server" { + t.Errorf("Repo = %s, want fleet-server (default)", cfg.Repo) + } + }, + }, + { + name: "missing CURRENT_RELEASE", + envVars: map[string]string{}, + wantErr: true, + }, + { + name: "invalid version format", + envVars: map[string]string{ + "CURRENT_RELEASE": "9", + }, + wantErr: true, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + // Clear env and set test values + os.Clearenv() + for k, v := range tt.envVars { + os.Setenv(k, v) + } + + cfg, err := loadReleaseConfigFromEnv() + + if (err != nil) != tt.wantErr { + t.Errorf("loadReleaseConfigFromEnv() error = %v, wantErr %v", err, tt.wantErr) + return + } + + if !tt.wantErr && tt.wantCheck != nil { + tt.wantCheck(t, cfg) + } + }) + } +} + +func TestPrepareNext(t *testing.T) { + // Create temp directory and file + tmpDir := t.TempDir() + versionDir := filepath.Join(tmpDir, "version") + err := os.Mkdir(versionDir, 0755) + if err != nil { + t.Fatalf("failed to create version dir: %v", err) + } + + versionFile := filepath.Join(versionDir, "version.go") + initialContent := `package version + +const DefaultVersion = "9.4.0" +` + err = os.WriteFile(versionFile, []byte(initialContent), 0644) + if err != nil { + t.Fatalf("failed to write initial file: %v", err) + } + + // Save current dir and change to temp dir + origDir, _ := os.Getwd() + defer os.Chdir(origDir) + os.Chdir(tmpDir) + + // Set env var + os.Setenv("CURRENT_RELEASE", "9.4.0") + + // Run PrepareNext + r := Release{} + err = r.PrepareNext() + if err != nil { + t.Fatalf("PrepareNext() failed: %v", err) + } + + // Verify version was incremented + content, err := os.ReadFile(versionFile) + if err != nil { + t.Fatalf("failed to read updated file: %v", err) + } + + expectedVersion := "9.5.0" + if !strings.Contains(string(content), expectedVersion) { + t.Errorf("PrepareNext() = %s, want %s", string(content), expectedVersion) + } +} From a666488077ce4f04fdca8ed17ae73e8037a7181f Mon Sep 17 00:00:00 2001 From: Victor Martinez Date: Thu, 12 Mar 2026 18:21:30 +0100 Subject: [PATCH 3/4] update --- go.mod | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/go.mod b/go.mod index fb6c961b57..14a0608c62 100644 --- a/go.mod +++ b/go.mod @@ -14,8 +14,10 @@ require ( github.com/elastic/go-ucfg v0.9.1 github.com/fxamacker/cbor/v2 v2.9.0 github.com/go-chi/chi/v5 v5.2.5 + github.com/go-git/go-git/v5 v5.12.0 github.com/gofrs/uuid/v5 v5.4.0 github.com/google/go-cmp v0.7.0 + github.com/google/go-github/v68 v68.0.0 github.com/hashicorp/go-cleanhttp v0.5.2 github.com/hashicorp/go-version v1.8.0 github.com/hashicorp/golang-lru/v2 v2.0.7 @@ -68,12 +70,10 @@ require ( github.com/fatih/color v1.15.0 // indirect github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect github.com/go-git/go-billy/v5 v5.5.0 // indirect - github.com/go-git/go-git/v5 v5.12.0 // indirect github.com/go-logr/logr v1.4.3 // indirect github.com/go-logr/stdr v1.2.2 // indirect github.com/go-ole/go-ole v1.3.0 // indirect github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect - github.com/google/go-github/v68 v68.0.0 // indirect github.com/google/go-querystring v1.1.0 // indirect github.com/google/uuid v1.6.0 // indirect github.com/gorilla/websocket v1.5.3 // indirect From eff7847ee8d4fec539d99a10ba1b26d9993a6645 Mon Sep 17 00:00:00 2001 From: Victor Martinez Date: Thu, 12 Mar 2026 18:59:25 +0100 Subject: [PATCH 4/4] fix linting --- go.sum | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/go.sum b/go.sum index 7920f5c528..b83ba7e17d 100644 --- a/go.sum +++ b/go.sum @@ -8,10 +8,14 @@ github.com/Pallinder/go-randomdata v1.2.0/go.mod h1:yHmJgulpD2Nfrm0cR9tI/+oAgRqC github.com/ProtonMail/go-crypto v1.0.0 h1:LRuvITjQWX+WIfr930YHG2HNfjR1uOfyf5vE0kC2U78= github.com/ProtonMail/go-crypto v1.0.0/go.mod h1:EjAoLdwvbIOoOQr3ihjnSoLZRtE8azugULFRteWMNc0= github.com/RaveNoX/go-jsoncommentstrip v1.0.0/go.mod h1:78ihd09MekBnJnxpICcwzCMzGrKSKYe4AqU6PDYYpjk= +github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be h1:9AeTilPcZAjCFIImctFaOjnTIavg87rW78vTPkQqLI8= +github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be/go.mod h1:ySMOLuWl6zY27l47sB3qLNK6tF2fkHG55UZxx8oIVo4= github.com/apapsch/go-jsonmerge/v2 v2.0.0 h1:axGnT1gRIfimI7gJifB699GoE/oq+F2MU7Dml6nw9rQ= github.com/apapsch/go-jsonmerge/v2 v2.0.0/go.mod h1:lvDnEdqiQrp0O42VQGgmlKpxL1AP2+08jFMw88y4klk= github.com/armon/go-radix v1.0.0 h1:F4z6KzEeeQIMeLFa97iZU6vupzoecKdU5TX24SNppXI= github.com/armon/go-radix v1.0.0/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8= +github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio= +github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs= github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= github.com/bmatcuk/doublestar v1.1.1/go.mod h1:UD6OnuiIn0yFxxA2le/rnRU1G4RaI4UvFv1sNto9p6w= @@ -64,6 +68,8 @@ github.com/elastic/go-windows v1.0.2 h1:yoLLsAsV5cfg9FLhZ9EXZ2n2sQFKeDYrHenkcivY github.com/elastic/go-windows v1.0.2/go.mod h1:bGcDpBzXgYSqM0Gx3DM4+UxFj300SZLixie9u9ixLM8= github.com/elastic/gosigar v0.14.3 h1:xwkKwPia+hSfg9GqrCUKYdId102m9qTJIIr7egmK/uo= github.com/elastic/gosigar v0.14.3/go.mod h1:iXRIGg2tLnu7LBdpqzyQfGDEidKCfWcCMS0WKyPWoMs= +github.com/elazarl/goproxy v0.0.0-20230808193330-2592e75ae04a h1:mATvB/9r/3gvcejNsXKSkQ6lcIaNec2nyfOdlTBR2lU= +github.com/elazarl/goproxy v0.0.0-20230808193330-2592e75ae04a/go.mod h1:Ro8st/ElPeALwNFlcTpWmkr6IoMFfkjXAvTHpevnDsM= github.com/emirpasic/gods v1.18.1 h1:FXtiHYKDGKCW2KzwZKx0iC0PQmdlorYgdFG9jPXJ1Bc= github.com/emirpasic/gods v1.18.1/go.mod h1:8tpGGwCnJ5H4r6BWwaV6OrWmMoPhUl5jm/FMNAnJvWQ= github.com/fatih/color v1.15.0 h1:kOqh6YHBtK8aywxGerMG2Eq3H6Qgoqeo13Bk2Mv/nBs= @@ -72,12 +78,16 @@ github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2 github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U= github.com/fxamacker/cbor/v2 v2.9.0 h1:NpKPmjDBgUfBms6tr6JZkTHtfFGcMKsw3eGcmD/sapM= github.com/fxamacker/cbor/v2 v2.9.0/go.mod h1:vM4b+DJCtHn+zz7h3FFp/hDAI9WNWCsZj23V5ytsSxQ= +github.com/gliderlabs/ssh v0.3.7 h1:iV3Bqi942d9huXnzEF2Mt+CY9gLu8DNM4Obd+8bODRE= +github.com/gliderlabs/ssh v0.3.7/go.mod h1:zpHEXBstFnQYtGnB8k8kQLol82umzn/2/snG7alWVD8= github.com/go-chi/chi/v5 v5.2.5 h1:Eg4myHZBjyvJmAFjFvWgrqDTXFyOzjj7YIm3L3mu6Ug= github.com/go-chi/chi/v5 v5.2.5/go.mod h1:X7Gx4mteadT3eDOMTsXzmI4/rwUpOwBHLpAfupzFJP0= github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 h1:+zs/tPmkDkHx3U66DAb0lQFJrpS6731Oaa12ikc+DiI= github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376/go.mod h1:an3vInlBmSxCcxctByoQdvwPiA7DTK7jaaFDBTtu0ic= github.com/go-git/go-billy/v5 v5.5.0 h1:yEY4yhzCDuMGSv83oGxiBotRzhwhNr8VZyphhiu+mTU= github.com/go-git/go-billy/v5 v5.5.0/go.mod h1:hmexnoNsr2SJU1Ju67OaNz5ASJY3+sHgFRpCtpDCKow= +github.com/go-git/go-git-fixtures/v4 v4.3.2-0.20231010084843-55a94097c399 h1:eMje31YglSBqCdIqdhKBW8lokaMrL3uTkpGYlE2OOT4= +github.com/go-git/go-git-fixtures/v4 v4.3.2-0.20231010084843-55a94097c399/go.mod h1:1OCfN199q1Jm3HZlxleg+Dw/mwps2Wbk9frAWm+4FII= github.com/go-git/go-git/v5 v5.12.0 h1:7Md+ndsjrzZxbddRDZjF14qK+NN56sy6wkqaVrjZtys= github.com/go-git/go-git/v5 v5.12.0/go.mod h1:FTM9VKtnI2m65hNI/TenDDDnUf2Q9FHnXYjuz9i5OEY= github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= @@ -160,6 +170,8 @@ github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ= github.com/oapi-codegen/runtime v1.2.0 h1:RvKc1CVS1QeKSNzO97FBQbSMZyQ8s6rZd+LpmzwHMP4= github.com/oapi-codegen/runtime v1.2.0/go.mod h1:Y7ZhmmlE8ikZOmuHRRndiIm7nf3xcVv+YMweKgG1DT0= +github.com/onsi/gomega v1.27.10 h1:naR28SdDFlqrG6kScpT8VWpu1xWY5nJRCF3XaYyBjhI= +github.com/onsi/gomega v1.27.10/go.mod h1:RsS8tutOdbdgzbPtzzATp12yT7kM5I5aElG3evPbQ0M= github.com/open-telemetry/opamp-go v0.23.0 h1:k7h7w/muprut9/DAhUC4anX4v7hIdgO02gIsSjV4uq0= github.com/open-telemetry/opamp-go v0.23.0/go.mod h1:DIIVdkLefdqPW5L+4I2twmAicVrTB0Bp5XJAfedZzAM= github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U= @@ -326,6 +338,8 @@ golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuX golang.org/x/term v0.2.0/go.mod h1:TVmDHMZPmdnySmBfhjOoOdhjzdE1h4u1VwSiw2l1Nuc= golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= golang.org/x/term v0.6.0/go.mod h1:m6U89DPEgQRMq3DNkDClhWw02AUbt2daBVO4cn4Hv9U= +golang.org/x/term v0.40.0 h1:36e4zGLqU4yhjlmxEaagx2KuYbJq3EwY8K943ZsHcvg= +golang.org/x/term v0.40.0/go.mod h1:w2P8uVp06p2iyKKuvXIm7N/y0UCRt3UfJTfZ7oOpglM= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=