From ecaf9a992691e49904cc1ecbffcbd2eada0ac210 Mon Sep 17 00:00:00 2001 From: vicentepinto98 Date: Mon, 19 Feb 2024 16:55:14 +0000 Subject: [PATCH 01/20] First draft of the automatic tag script --- .../authentication/service_account_key.json | 16 +++ go.work | 1 + go.work.sum | 7 + scripts/automatic-tag.go | 118 ++++++++++++++++ scripts/go.mod | 29 ++++ scripts/go.sum | 129 ++++++++++++++++++ 6 files changed, 300 insertions(+) create mode 100644 examples/authentication/service_account_key.json create mode 100644 go.work.sum create mode 100644 scripts/automatic-tag.go create mode 100644 scripts/go.mod create mode 100644 scripts/go.sum diff --git a/examples/authentication/service_account_key.json b/examples/authentication/service_account_key.json new file mode 100644 index 000000000..13298f069 --- /dev/null +++ b/examples/authentication/service_account_key.json @@ -0,0 +1,16 @@ +{ + "id": "b96b30a0-2f92-41c8-9b86-ecaebed825c7", + "publicKey": "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAmRR7zmFSJBXI5dAa7sqT\nwbUhC0QOOfKs9hZcV9TfCG49WkgxInDqG/aYBxxAVSq+qDJqbohUbqcgbLv1qcJF\n1ijGch0P6zazuMbnmigq5zbmuZUWtCVos3IOYBKPAVWvLo3tBd7wpirPC9FOYWzX\nNllhXWrSo0Um17SejcZ6waa6hk7ejBk6G2IFNaDw/W6wXcVN6OTmKp3+EsOixiC2\n8HEnEvpUC3kpWfW1D3czbfB05Y8sPrCScUpIZk/LXseLUVvRRxhQ++4YkudSXpWU\nG2dRFKypU5OvdlxYZsg1mlPJ+8QgY6R7L42thwLhdrGt1h771MrgvJFczTtX0VcL\nBwIDAQAB\n-----END PUBLIC KEY-----", + "createdAt": "2024-01-08T17:21:31.079+00:00", + "keyType": "USER_MANAGED", + "keyOrigin": "GENERATED", + "keyAlgorithm": "RSA_2048", + "active": true, + "credentials": { + "kid": "b96b30a0-2f92-41c8-9b86-ecaebed825c7", + "iss": "my-service-account-84obm21@sa.stackit.cloud", + "sub": "c51ea797-c0fc-4e2e-b26a-bc185e7a180e", + "aud": "https://stackit-service-account-prod.apps.01.cf.eu01.stackit.cloud", + "privateKey": "-----BEGIN PRIVATE KEY-----\nMIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQCZFHvOYVIkFcjl\n0BruypPBtSELRA458qz2FlxX1N8Ibj1aSDEicOob9pgHHEBVKr6oMmpuiFRupyBs\nu/WpwkXWKMZyHQ/rNrO4xueaKCrnNua5lRa0JWizcg5gEo8BVa8uje0F3vCmKs8L\n0U5hbNc2WWFdatKjRSbXtJ6NxnrBprqGTt6MGTobYgU1oPD9brBdxU3o5OYqnf4S\nw6LGILbwcScS+lQLeSlZ9bUPdzNt8HTljyw+sJJxSkhmT8tex4tRW9FHGFD77hiS\n51JelZQbZ1EUrKlTk692XFhmyDWaU8n7xCBjpHsvja2HAuF2sa3WHvvUyuC8kVzN\nO1fRVwsHAgMBAAECggEAHtIT90J68k78iuCye3+H7klUpNsH7jzg/A8WeoyedykS\n6zl7ww5u5EBq7YuPnFYl2uGDskt6jGjTy3CwjoRR4UOGaPVW/imeV8acXNpXgQP5\nwkW1M4IQqYh+QnOaHU+uHLZwkW0IkLwvwZZbrJvoXMX0J4XZcQv8PRPdlHfwwUpL\nrlz1iTz89Gk6XlPemrMfhZi1F895g5qP8wX7M/QfUVvRjGEY/oYJ7k18OSX23brY\nIWrgoqIfw0jKN5vtsQ5VM6zJf0DN03sdeliu/fEcc+PVE6AJ5ixvRRwi7Plcijbl\nU+TBtuvw4kPlOZ1uujWfUmOYT3n0bBTvq7wc6bUIiQKBgQDHM9mn9iS4hmHKuCbe\n0FPJA/+do0KY3nc9Nk3k087jkNUOioBeai8DMJ46MSuwEcVFonGDEPoFyrDsS3Js\ndPo9h/HT2XZRqlJjBGoLSVsh/WKhGYuh5+4WAOCnyj5UeTxrBosjkAsEYFX/X4Ru\n+SP2L4p637+4h6xbzDG6AoX3YwKBgQDEuhFWXHpy7SMsqmfVydCIxltWM4COit/P\nv//k59YtDmmnf1Nr2XSq+eDKxRvEKpCx4s7GMWdsW+6jW659zOm4w+x11PVOECZB\nLcBcWp/tHxRxIZ5yuZNLoTmlr7iMh0nwh6R6dMXMwM5/E6wmZ9E+Mst5Mf9OCdYM\n4k9j6v0JDQKBgQCV4T9dDuhmJkYiHxiwARNpZabIVvRezNPurJNDHtLFik2kGTWo\n1D/3KHeE1UZHvbcuQ6Egun9EKFOiFspLLGC0NzsO6MoLfBltAv8+6ry1AE9bYzsa\nYMVUrOhbluH68RUyecPqyBBiBJHwCVA9pxsVuoN5HCzGjN50W1j22bsufQKBgQCG\njFgFP/TDm6q+BsJDtub4VOntOAZJ93OBrGiBD4stf7kFRREyJyUjNwnmxQ7riM0z\nzNLtPKbmtq2tbqwWAEsuAlo8cO1heawgUgFJaPYOgH5DreGnx4KVbGx4BIntGy6X\n4r28vxb1pjzVLwhDsCetKaJ+fpKFtjZ+013HEdYEFQKBgAcrkrZvg7cjphtUa1Bz\n4vgyiYQ5hfYC0FMUKLwzK8L7WIRP6Y5k99i6V5lhSXndEBu5M4D47A/PrG1jzybB\nJeKwWFlXn+sTT2Sfs63tfDfsKVAXry+OL+IvS0Q5WKSUgdz8IjZU0SHTkNeN+90k\nOzaANONSg1Kp4FodJ0sFqkZ4\n-----END PRIVATE KEY-----" + } +} diff --git a/go.work b/go.work index 740f4c3bb..4d1898bae 100644 --- a/go.work +++ b/go.work @@ -2,6 +2,7 @@ go 1.18 use ( ./core + ./scripts ./examples/argus ./examples/authentication ./examples/authorization diff --git a/go.work.sum b/go.work.sum new file mode 100644 index 000000000..81c8f6e4e --- /dev/null +++ b/go.work.sum @@ -0,0 +1,7 @@ +golang.org/x/crypto v0.19.0 h1:ENy+Az/9Y1vSrlrvBSyna3PITt4tiZLf7sgCjZBX7Wo= +golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU= +golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= +golang.org/x/sys v0.17.0 h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y= +golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/term v0.17.0/go.mod h1:lLRBjIVuehSbZlaOtGMbcMncT+aqLLLmKrsjNrUguwk= +golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= diff --git a/scripts/automatic-tag.go b/scripts/automatic-tag.go new file mode 100644 index 000000000..065e5c2e5 --- /dev/null +++ b/scripts/automatic-tag.go @@ -0,0 +1,118 @@ +package main + +import ( + "fmt" + "os" + "strings" + + "github.com/go-git/go-git/v5" + "github.com/go-git/go-git/v5/plumbing/object" + "golang.org/x/mod/semver" +) + +const ( + sdkRepo = "https://github.com/stackitcloud/stackit-sdk-go" +) + +var ( + updateTypes = []string{"minor", "patch"} +) + +func main() { + if len(os.Args) != 2 && len(os.Args) != 3 { + fmt.Println("wrong number of arguments. Usage: go run automatic-tag.go [minor|patch] --core-only") + os.Exit(1) + } + + updateType := os.Args[1] + valid := false + for _, t := range updateTypes { + if updateType == t { + valid = true + break + } + } + if !valid { + fmt.Printf("the provided argument `%s` is not valid, the valid values are: [%s]\n", updateType, strings.Join(updateTypes, ",")) + os.Exit(1) + } + + tempDir, err := os.MkdirTemp("", "") + if err != nil { + fmt.Printf("create temporary directory: %s", err.Error()) + os.Exit(1) + } + + r, err := git.PlainClone(tempDir, false, &git.CloneOptions{ + URL: sdkRepo, + }) + if err != nil { + fmt.Printf("clone SDK repo: %s", err.Error()) + os.Exit(1) + } + + tags, err := r.TagObjects() + if err != nil { + fmt.Printf("get tags: %s", err.Error()) + os.Exit(1) + } + + var coreOnly bool + if len(os.Args) == 3 { + if os.Args[3] != "--core-only" { + fmt.Println("wrong arguments. Usage: go run automatic-tag.go [minor|patch] --core-only") + os.Exit(1) + } + coreOnly = true + } + + existingTags := map[string]string{} + err = tags.ForEach(func(t *object.Tag) error { + tagName, _ := strings.CutSuffix(t.Name, "refs/tags/") + splitTag := strings.Split(tagName, "/") + + if coreOnly { + if len(splitTag) != 2 || splitTag[0] != "core" { + return nil + } + + version := splitTag[1] + if semver.Prerelease(version) != "" { + return nil + } + + // invalid (or empty) semantic version are considered less than a valid one + if semver.Compare(existingTags["core"], version) == -1 { + existingTags["core"] = version + } + + } else { + if len(splitTag) != 3 || splitTag[0] != "services" { + return nil + } + + service := splitTag[1] + version := splitTag[2] + if semver.Prerelease(version) != "" { + return nil + } + + // invalid (or empty) semantic version are considered less than a valid one + if semver.Compare(existingTags[service], version) == -1 { + existingTags[service] = version + } + } + return nil + }) + if err != nil { + fmt.Printf("iterate over existing tags: %s\n", err.Error()) + os.Exit(1) + } + + for t := range existingTags { + fmt.Println(t) + } + + // TO-DO: Update tags + // TO-DO: Push tags +} diff --git a/scripts/go.mod b/scripts/go.mod new file mode 100644 index 000000000..b08bb44ba --- /dev/null +++ b/scripts/go.mod @@ -0,0 +1,29 @@ +module github.com/stackitcloud/stackit-sdk-go/scripts + +go 1.18 + +require github.com/go-git/go-git/v5 v5.11.0 + +require ( + dario.cat/mergo v1.0.0 // indirect + github.com/Microsoft/go-winio v0.6.1 // indirect + github.com/ProtonMail/go-crypto v0.0.0-20230828082145-3c4c8a2d2371 // indirect + github.com/cloudflare/circl v1.3.3 // indirect + github.com/cyphar/filepath-securejoin v0.2.4 // indirect + github.com/emirpasic/gods v1.18.1 // 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/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect + github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect + github.com/kevinburke/ssh_config v1.2.0 // indirect + github.com/pjbgf/sha1cd v0.3.0 // indirect + github.com/sergi/go-diff v1.1.0 // indirect + github.com/skeema/knownhosts v1.2.1 // indirect + github.com/xanzy/ssh-agent v0.3.3 // indirect + golang.org/x/crypto v0.16.0 // indirect + golang.org/x/mod v0.12.0 + golang.org/x/net v0.19.0 // indirect + golang.org/x/sys v0.15.0 // indirect + golang.org/x/tools v0.13.0 // indirect + gopkg.in/warnings.v0 v0.1.2 // indirect +) diff --git a/scripts/go.sum b/scripts/go.sum new file mode 100644 index 000000000..ecd578cc5 --- /dev/null +++ b/scripts/go.sum @@ -0,0 +1,129 @@ +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/ProtonMail/go-crypto v0.0.0-20230828082145-3c4c8a2d2371 h1:kkhsdkhsCvIsutKu5zLMgWtgh9YxGCNAw8Ad8hjwfYg= +github.com/ProtonMail/go-crypto v0.0.0-20230828082145-3c4c8a2d2371/go.mod h1:EjAoLdwvbIOoOQr3ihjnSoLZRtE8azugULFRteWMNc0= +github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be h1:9AeTilPcZAjCFIImctFaOjnTIavg87rW78vTPkQqLI8= +github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio= +github.com/bwesterb/go-ristretto v1.2.3/go.mod h1:fUIoIZaG73pV5biE2Blr2xEzDoMj7NFEuV9ekS419A0= +github.com/cloudflare/circl v1.3.3 h1:fE/Qz0QdIGqeWfnwq0RE0R7MI51s0M2E4Ga9kq5AEMs= +github.com/cloudflare/circl v1.3.3/go.mod h1:5XYMA4rFBvNIrhs50XuiBJ15vF2pZn4nnUKZrLbUZFA= +github.com/cyphar/filepath-securejoin v0.2.4 h1:Ugdm7cg7i6ZK6x3xDF1oEu1nfkyfH53EtKeQYTC3kyg= +github.com/cyphar/filepath-securejoin v0.2.4/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= +github.com/elazarl/goproxy v0.0.0-20230808193330-2592e75ae04a h1:mATvB/9r/3gvcejNsXKSkQ6lcIaNec2nyfOdlTBR2lU= +github.com/emirpasic/gods v1.18.1 h1:FXtiHYKDGKCW2KzwZKx0iC0PQmdlorYgdFG9jPXJ1Bc= +github.com/emirpasic/gods v1.18.1/go.mod h1:8tpGGwCnJ5H4r6BWwaV6OrWmMoPhUl5jm/FMNAnJvWQ= +github.com/gliderlabs/ssh v0.3.5 h1:OcaySEmAQJgyYcArR+gGGTHCyE7nvhEMTlYY+Dp8CpY= +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/v5 v5.11.0 h1:XIZc1p+8YzypNr34itUfSvYJcv+eYdTnTvOZ2vD3cA4= +github.com/go-git/go-git/v5 v5.11.0/go.mod h1:6GFcX2P3NM7FPBfpePbpLd21XxsgdAt+lKqXmCUiUCY= +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/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= +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/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/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= +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/onsi/gomega v1.27.10 h1:naR28SdDFlqrG6kScpT8VWpu1xWY5nJRCF3XaYyBjhI= +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= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M= +github.com/sergi/go-diff v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0= +github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM= +github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0= +github.com/skeema/knownhosts v1.2.1 h1:SHWdIUa82uGZz+F+47k8SY4QhhI291cXCpopT1lK2AQ= +github.com/skeema/knownhosts v1.2.1/go.mod h1:xYbVRSPxqBZFrdmDyMmsOs+uX1UZC3nTN3ThzgDxUwo= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= +github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= +github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= +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/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= +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.16.0 h1:mMMrFzRSCF0GvB7Ne27XVtVAaXLrPmgPC7/v0tkwHaY= +golang.org/x/crypto v0.16.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4= +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.12.0 h1:rmsUpXtvNzj340zd98LZ4KntptpfRHwpFOHG188oHXc= +golang.org/x/mod v0.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= +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.19.0 h1:zTwKpTd2XuCqf8huc7Fo2iSy+4RHPd10s4KzeTnVr1c= +golang.org/x/net v0.19.0/go.mod h1:CfAk/cbD4CthTvqiEl8NpboMuiuOYsAr/7NOjZJtv1U= +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.3.0 h1:ftCYgMx6zT/asHUrPw8BLLscYtGznsLAnjq5RH9P66E= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +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-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.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.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc= +golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +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/term v0.15.0 h1:y/Oo/a/q3IXu26lQgl04j/gjuBDOBlx7X6Om1j2CPW4= +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.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= +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.13.0 h1:Iey4qkscZuv0VvIt8E0neZjtPVQFSc870HQ448QgEmQ= +golang.org/x/tools v0.13.0/go.mod h1:HvlwmtVNQAhOuCjW7xxvovg8wbNq7LwfXh/k7wXUl58= +golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +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/warnings.v0 v0.1.2 h1:wFXVbFY8DY5/xOe1ECiWdKCzZlxgshcYVNkBHstARME= +gopkg.in/warnings.v0 v0.1.2/go.mod h1:jksf8JmL6Qr/oQM2OXTHunEvvTAsrWBLb6OOjuVWRNI= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= From f0b96a5717fdc9bfcdff56e629b2f6b41c3e7e4f Mon Sep 17 00:00:00 2001 From: vicentepinto98 Date: Wed, 21 Feb 2024 12:55:45 +0000 Subject: [PATCH 02/20] Create and push tags --- go.work.sum | 4 ++ scripts/automatic-tag.go | 102 ++++++++++++++++++++++++++++++++++----- scripts/go.mod | 11 +++-- scripts/go.sum | 36 ++++++++++++++ 4 files changed, 138 insertions(+), 15 deletions(-) diff --git a/go.work.sum b/go.work.sum index 81c8f6e4e..de9ed414a 100644 --- a/go.work.sum +++ b/go.work.sum @@ -1,3 +1,6 @@ +github.com/go-git/go-git v1.0.0 h1:YcN9iDGDoXuIw0vHls6rINwV416HYa0EB2X+RBsyYp4= +github.com/go-git/go-git v1.0.0/go.mod h1:6+421e08gnZWn30y26Vchf7efgYLe4dl5OQbBSUXShE= +github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y= golang.org/x/crypto v0.19.0 h1:ENy+Az/9Y1vSrlrvBSyna3PITt4tiZLf7sgCjZBX7Wo= golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU= golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= @@ -5,3 +8,4 @@ golang.org/x/sys v0.17.0 h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y= golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.17.0/go.mod h1:lLRBjIVuehSbZlaOtGMbcMncT+aqLLLmKrsjNrUguwk= golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= +gopkg.in/yaml.v2 v2.2.4 h1:/eiJrUcujPVeJ3xlSWaiNi3uSVmDGBK1pDHUHAnao1I= diff --git a/scripts/automatic-tag.go b/scripts/automatic-tag.go index 065e5c2e5..b203d6d47 100644 --- a/scripts/automatic-tag.go +++ b/scripts/automatic-tag.go @@ -3,19 +3,23 @@ package main import ( "fmt" "os" + "strconv" "strings" "github.com/go-git/go-git/v5" - "github.com/go-git/go-git/v5/plumbing/object" + "github.com/go-git/go-git/v5/config" + "github.com/go-git/go-git/v5/plumbing" "golang.org/x/mod/semver" ) const ( sdkRepo = "https://github.com/stackitcloud/stackit-sdk-go" + patch = "patch" + minor = "minor" ) var ( - updateTypes = []string{"minor", "patch"} + updateTypes = []string{minor, patch} ) func main() { @@ -44,14 +48,15 @@ func main() { } r, err := git.PlainClone(tempDir, false, &git.CloneOptions{ - URL: sdkRepo, + URL: sdkRepo, + RecurseSubmodules: git.DefaultSubmoduleRecursionDepth, }) if err != nil { fmt.Printf("clone SDK repo: %s", err.Error()) os.Exit(1) } - tags, err := r.TagObjects() + tagrefs, err := r.Tags() if err != nil { fmt.Printf("get tags: %s", err.Error()) os.Exit(1) @@ -59,7 +64,7 @@ func main() { var coreOnly bool if len(os.Args) == 3 { - if os.Args[3] != "--core-only" { + if os.Args[2] != "--core-only" { fmt.Println("wrong arguments. Usage: go run automatic-tag.go [minor|patch] --core-only") os.Exit(1) } @@ -67,8 +72,8 @@ func main() { } existingTags := map[string]string{} - err = tags.ForEach(func(t *object.Tag) error { - tagName, _ := strings.CutSuffix(t.Name, "refs/tags/") + err = tagrefs.ForEach(func(t *plumbing.Reference) error { + tagName, _ := strings.CutPrefix(t.Name().String(), "refs/tags/") splitTag := strings.Split(tagName, "/") if coreOnly { @@ -109,10 +114,85 @@ func main() { os.Exit(1) } - for t := range existingTags { - fmt.Println(t) + for service, version := range existingTags { + canonicalVersion := semver.Canonical(version) + splitVersion := strings.Split(canonicalVersion, ".") + if len(splitVersion) != 3 { + fmt.Printf("Invalid canonical version for service %s with version %s, this tag will be skipped\n", service, version) + continue + } + switch updateType { + case patch: + patchNumber, err := strconv.Atoi(splitVersion[2]) + if err != nil { + fmt.Printf("Couldnt convert patch number to int for service %s with version %s, this tag will be skipped\n", service, version) + continue + } + updatedPatchNumber := patchNumber + 1 + splitVersion[2] = fmt.Sprint(updatedPatchNumber) + case minor: + minorNumber, err := strconv.Atoi(splitVersion[1]) + if err != nil { + fmt.Printf("Couldnt convert minor number to int for service %s with version %s, this tag will be skipped\n", service, version) + continue + } + updatedPatchNumber := minorNumber + 1 + splitVersion[1] = fmt.Sprint(updatedPatchNumber) + splitVersion[2] = "0" + default: + fmt.Println("Update type not supported in version increment, fix the script") + os.Exit(1) + } + updatedVersion := strings.Join(splitVersion, ".") + var newTag string + if coreOnly { + newTag = fmt.Sprintf("core/%s", updatedVersion) + } else { + newTag = fmt.Sprintf("services/%s/%s", service, updatedVersion) + } + err := createTag(r, newTag) + if err != nil { + fmt.Printf("Create tag %s returned error: %s", newTag, err) + continue + } + fmt.Printf("Created tag %s", newTag) + } + + err = pushTags(r) + if err != nil { + fmt.Printf("push tags: %s", err) + os.Exit(1) + } + +} + +func createTag(r *git.Repository, tag string) error { + h, err := r.Head() + if err != nil { + return fmt.Errorf("get HEAD: %w", err) + } + _, err = r.CreateTag(tag, h.Hash(), nil) + if err != nil { + return fmt.Errorf("create tag: %w", err) + } + return nil +} + +func pushTags(r *git.Repository) error { + + po := &git.PushOptions{ + RemoteName: "origin", + Progress: os.Stdout, + RefSpecs: []config.RefSpec{config.RefSpec("refs/tags/*:refs/tags/*")}, + } + err := r.Push(po) + + if err != nil { + if err == git.NoErrAlreadyUpToDate { + return fmt.Errorf("origin remote was up to date, no push done") + } + return fmt.Errorf("push to remote origin: %w", err) } - // TO-DO: Update tags - // TO-DO: Push tags + return nil } diff --git a/scripts/go.mod b/scripts/go.mod index b08bb44ba..2540c1e8a 100644 --- a/scripts/go.mod +++ b/scripts/go.mod @@ -6,19 +6,22 @@ require github.com/go-git/go-git/v5 v5.11.0 require ( dario.cat/mergo v1.0.0 // indirect - github.com/Microsoft/go-winio v0.6.1 // indirect github.com/ProtonMail/go-crypto v0.0.0-20230828082145-3c4c8a2d2371 // indirect github.com/cloudflare/circl v1.3.3 // indirect github.com/cyphar/filepath-securejoin v0.2.4 // indirect - github.com/emirpasic/gods v1.18.1 // 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/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect + github.com/pjbgf/sha1cd v0.3.0 // indirect + github.com/skeema/knownhosts v1.2.1 // indirect +) + +require ( + github.com/Microsoft/go-winio v0.6.1 // indirect + github.com/emirpasic/gods v1.18.1 // indirect github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect github.com/kevinburke/ssh_config v1.2.0 // indirect - github.com/pjbgf/sha1cd v0.3.0 // indirect github.com/sergi/go-diff v1.1.0 // indirect - github.com/skeema/knownhosts v1.2.1 // indirect github.com/xanzy/ssh-agent v0.3.3 // indirect golang.org/x/crypto v0.16.0 // indirect golang.org/x/mod v0.12.0 diff --git a/scripts/go.sum b/scripts/go.sum index ecd578cc5..75e75959e 100644 --- a/scripts/go.sum +++ b/scripts/go.sum @@ -5,60 +5,84 @@ github.com/Microsoft/go-winio v0.6.1 h1:9/kr64B9VUZrLm5YYwbGtUJnMgqWVOdUAXu6Migc github.com/Microsoft/go-winio v0.6.1/go.mod h1:LRdKpFKfdobln8UmuiYcKPot9D2v6svN5+sAH+4kjUM= github.com/ProtonMail/go-crypto v0.0.0-20230828082145-3c4c8a2d2371 h1:kkhsdkhsCvIsutKu5zLMgWtgh9YxGCNAw8Ad8hjwfYg= github.com/ProtonMail/go-crypto v0.0.0-20230828082145-3c4c8a2d2371/go.mod h1:EjAoLdwvbIOoOQr3ihjnSoLZRtE8azugULFRteWMNc0= +github.com/alcortesm/tgz v0.0.0-20161220082320-9c5fe88206d7/go.mod h1:6zEj6s6u/ghQa61ZWa/C2Aw3RkjiTBOix7dkqa1VLIs= +github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239/go.mod h1:2FmKhYUyUczH0OGQWaF5ceTx0UBShxjsH6f8oGKYe2c= github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be h1:9AeTilPcZAjCFIImctFaOjnTIavg87rW78vTPkQqLI8= 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/bwesterb/go-ristretto v1.2.3/go.mod h1:fUIoIZaG73pV5biE2Blr2xEzDoMj7NFEuV9ekS419A0= github.com/cloudflare/circl v1.3.3 h1:fE/Qz0QdIGqeWfnwq0RE0R7MI51s0M2E4Ga9kq5AEMs= github.com/cloudflare/circl v1.3.3/go.mod h1:5XYMA4rFBvNIrhs50XuiBJ15vF2pZn4nnUKZrLbUZFA= +github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY= github.com/cyphar/filepath-securejoin v0.2.4 h1:Ugdm7cg7i6ZK6x3xDF1oEu1nfkyfH53EtKeQYTC3kyg= github.com/cyphar/filepath-securejoin v0.2.4/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= github.com/elazarl/goproxy v0.0.0-20230808193330-2592e75ae04a h1:mATvB/9r/3gvcejNsXKSkQ6lcIaNec2nyfOdlTBR2lU= +github.com/emirpasic/gods v1.12.0/go.mod h1:YfzfFFoVP/catgzJb4IKIqXjX78Ha8FMSDh3ymbK86o= github.com/emirpasic/gods v1.18.1 h1:FXtiHYKDGKCW2KzwZKx0iC0PQmdlorYgdFG9jPXJ1Bc= github.com/emirpasic/gods v1.18.1/go.mod h1:8tpGGwCnJ5H4r6BWwaV6OrWmMoPhUl5jm/FMNAnJvWQ= +github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc= +github.com/gliderlabs/ssh v0.2.2/go.mod h1:U7qILu1NlMHj9FlMhZLlkCdDnU1DBEAqr0aevW3Awn0= github.com/gliderlabs/ssh v0.3.5 h1:OcaySEmAQJgyYcArR+gGGTHCyE7nvhEMTlYY+Dp8CpY= 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 v4.7.0+incompatible h1:+W9rgGY4DOKKdX2x6HxSR7HNeTxqiKrOvKnuittYVdA= +github.com/go-git/go-git v4.7.0+incompatible/go.mod h1:6+421e08gnZWn30y26Vchf7efgYLe4dl5OQbBSUXShE= github.com/go-git/go-git-fixtures/v4 v4.3.2-0.20231010084843-55a94097c399 h1:eMje31YglSBqCdIqdhKBW8lokaMrL3uTkpGYlE2OOT4= github.com/go-git/go-git/v5 v5.11.0 h1:XIZc1p+8YzypNr34itUfSvYJcv+eYdTnTvOZ2vD3cA4= github.com/go-git/go-git/v5 v5.11.0/go.mod h1:6GFcX2P3NM7FPBfpePbpLd21XxsgdAt+lKqXmCUiUCY= 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/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= 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/kevinburke/ssh_config v0.0.0-20190725054713-01f96b0aa0cd/go.mod h1:CT57kijsi8u/K/BOFA39wgDQJ9CxiF4nAY/ojJ6r6mM= 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/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/pty v1.1.8/go.mod h1:O1sed60cT9XZ5uDucP5qwvh+TE3NnUj51EiZO/lmSfw= 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/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= github.com/onsi/gomega v1.27.10 h1:naR28SdDFlqrG6kScpT8VWpu1xWY5nJRCF3XaYyBjhI= +github.com/pelletier/go-buffruneio v0.2.0/go.mod h1:JkE26KsDizTr40EUHkXVtNPvgGtbSNq5BcowyYOWdKo= 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.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= 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= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M= +github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo= github.com/sergi/go-diff v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0= github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM= github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0= github.com/skeema/knownhosts v1.2.1 h1:SHWdIUa82uGZz+F+47k8SY4QhhI291cXCpopT1lK2AQ= github.com/skeema/knownhosts v1.2.1/go.mod h1:xYbVRSPxqBZFrdmDyMmsOs+uX1UZC3nTN3ThzgDxUwo= +github.com/src-d/gcfg v1.4.0 h1:xXbNR5AlLSA315x2UO+fTSSAXCDf+Ar38/6oyGbDKQ4= +github.com/src-d/gcfg v1.4.0/go.mod h1:p/UMsR43ujA89BJY9duynAwIpvqEujIH/jFlfL7jWoI= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE= 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.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= +github.com/xanzy/ssh-agent v0.2.1/go.mod h1:mLlQY/MoOhWBj+gOGMQkOeiEvkx+8pJSI+0Bx9h2kr4= 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/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= +golang.org/x/crypto v0.0.0-20190219172222-a4c6cb3142f2/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= 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= @@ -69,7 +93,9 @@ golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91 golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/mod v0.12.0 h1:rmsUpXtvNzj340zd98LZ4KntptpfRHwpFOHG188oHXc= golang.org/x/mod v0.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20190724013045-ca1201d0de80/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= @@ -83,6 +109,9 @@ golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.3.0 h1:ftCYgMx6zT/asHUrPw8BLLscYtGznsLAnjq5RH9P66E= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190221075227-b4e8571b14e0/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/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-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -104,6 +133,7 @@ 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.15.0 h1:y/Oo/a/q3IXu26lQgl04j/gjuBDOBlx7X6Om1j2CPW4= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= 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= @@ -112,6 +142,7 @@ 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.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190729092621-ff9f1409240a/go.mod h1:jcCCGcm9btYwXyDqrUWc6MKQKKGJCWEQ3AfLSRIbEuI= 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= @@ -119,8 +150,13 @@ golang.org/x/tools v0.13.0 h1:Iey4qkscZuv0VvIt8E0neZjtPVQFSc870HQ448QgEmQ= golang.org/x/tools v0.13.0/go.mod h1:HvlwmtVNQAhOuCjW7xxvovg8wbNq7LwfXh/k7wXUl58= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/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/src-d/go-billy.v4 v4.3.2/go.mod h1:nDjArDMp+XMs1aFAESLRjfGSgfvoYN0hDfzEk0GjC98= +gopkg.in/src-d/go-git-fixtures.v3 v3.5.0/go.mod h1:dLBcvytrw/TYZsNTWCnkNF2DSIlzWYqTe3rJR56Ac7g= +gopkg.in/src-d/go-git.v4 v4.13.1 h1:SRtFyV8Kxc0UP7aCHcijOMQGPxHSmMOPrzulQWolkYE= +gopkg.in/src-d/go-git.v4 v4.13.1/go.mod h1:nx5NYcxdKxq5fpltdHnPa2Exj4Sx0EclMWZQbYDu2z8= 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.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= From 433d56fc0f0d598dd52caec9db89bdf394bfa4d7 Mon Sep 17 00:00:00 2001 From: vicentepinto98 Date: Wed, 21 Feb 2024 18:06:54 +0000 Subject: [PATCH 03/20] Finish script, add to lint --- go.work | 2 +- go.work.sum | 42 ++++++++-- scripts/automatic-tag.go | 144 +++++++++++++++++++++------------- scripts/go.mod | 6 +- scripts/go.sum | 47 +---------- scripts/lint-golangci-lint.sh | 7 ++ 6 files changed, 139 insertions(+), 109 deletions(-) diff --git a/go.work b/go.work index 4d1898bae..760c65bfa 100644 --- a/go.work +++ b/go.work @@ -2,7 +2,6 @@ go 1.18 use ( ./core - ./scripts ./examples/argus ./examples/authentication ./examples/authorization @@ -25,6 +24,7 @@ use ( ./examples/serviceaccount ./examples/ske ./examples/waiter + ./scripts ./services/argus ./services/authorization ./services/dns diff --git a/go.work.sum b/go.work.sum index de9ed414a..a1abc44d5 100644 --- a/go.work.sum +++ b/go.work.sum @@ -1,11 +1,41 @@ -github.com/go-git/go-git v1.0.0 h1:YcN9iDGDoXuIw0vHls6rINwV416HYa0EB2X+RBsyYp4= -github.com/go-git/go-git v1.0.0/go.mod h1:6+421e08gnZWn30y26Vchf7efgYLe4dl5OQbBSUXShE= -github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y= -golang.org/x/crypto v0.19.0 h1:ENy+Az/9Y1vSrlrvBSyna3PITt4tiZLf7sgCjZBX7Wo= +github.com/alcortesm/tgz v0.0.0-20161220082320-9c5fe88206d7/go.mod h1:6zEj6s6u/ghQa61ZWa/C2Aw3RkjiTBOix7dkqa1VLIs= +github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239/go.mod h1:2FmKhYUyUczH0OGQWaF5ceTx0UBShxjsH6f8oGKYe2c= +github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs= +github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY= +github.com/emirpasic/gods v1.12.0/go.mod h1:YfzfFFoVP/catgzJb4IKIqXjX78Ha8FMSDh3ymbK86o= +github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc= +github.com/gliderlabs/ssh v0.2.2/go.mod h1:U7qILu1NlMHj9FlMhZLlkCdDnU1DBEAqr0aevW3Awn0= +github.com/go-git/go-git v4.7.0+incompatible h1:+W9rgGY4DOKKdX2x6HxSR7HNeTxqiKrOvKnuittYVdA= +github.com/go-git/go-git v4.7.0+incompatible/go.mod h1:6+421e08gnZWn30y26Vchf7efgYLe4dl5OQbBSUXShE= +github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= +github.com/kevinburke/ssh_config v0.0.0-20190725054713-01f96b0aa0cd/go.mod h1:CT57kijsi8u/K/BOFA39wgDQJ9CxiF4nAY/ojJ6r6mM= +github.com/kr/pty v1.1.8/go.mod h1:O1sed60cT9XZ5uDucP5qwvh+TE3NnUj51EiZO/lmSfw= +github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= +github.com/pelletier/go-buffruneio v0.2.0/go.mod h1:JkE26KsDizTr40EUHkXVtNPvgGtbSNq5BcowyYOWdKo= +github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo= +github.com/src-d/gcfg v1.4.0/go.mod h1:p/UMsR43ujA89BJY9duynAwIpvqEujIH/jFlfL7jWoI= +github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE= +github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +github.com/xanzy/ssh-agent v0.2.1/go.mod h1:mLlQY/MoOhWBj+gOGMQkOeiEvkx+8pJSI+0Bx9h2kr4= +golang.org/x/crypto v0.0.0-20190219172222-a4c6cb3142f2/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= +golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.16.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4= golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190724013045-ca1201d0de80/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= -golang.org/x/sys v0.17.0 h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y= +golang.org/x/net v0.19.0/go.mod h1:CfAk/cbD4CthTvqiEl8NpboMuiuOYsAr/7NOjZJtv1U= +golang.org/x/sys v0.0.0-20190221075227-b4e8571b14e0/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.17.0/go.mod h1:lLRBjIVuehSbZlaOtGMbcMncT+aqLLLmKrsjNrUguwk= golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= -gopkg.in/yaml.v2 v2.2.4 h1:/eiJrUcujPVeJ3xlSWaiNi3uSVmDGBK1pDHUHAnao1I= +golang.org/x/tools v0.0.0-20190729092621-ff9f1409240a/go.mod h1:jcCCGcm9btYwXyDqrUWc6MKQKKGJCWEQ3AfLSRIbEuI= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/src-d/go-billy.v4 v4.3.2/go.mod h1:nDjArDMp+XMs1aFAESLRjfGSgfvoYN0hDfzEk0GjC98= +gopkg.in/src-d/go-git-fixtures.v3 v3.5.0/go.mod h1:dLBcvytrw/TYZsNTWCnkNF2DSIlzWYqTe3rJR56Ac7g= +gopkg.in/src-d/go-git.v4 v4.13.1/go.mod h1:nx5NYcxdKxq5fpltdHnPa2Exj4Sx0EclMWZQbYDu2z8= diff --git a/scripts/automatic-tag.go b/scripts/automatic-tag.go index b203d6d47..1daf78bfd 100644 --- a/scripts/automatic-tag.go +++ b/scripts/automatic-tag.go @@ -1,6 +1,7 @@ package main import ( + "errors" "fmt" "os" "strconv" @@ -9,11 +10,12 @@ import ( "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/transport/ssh" "golang.org/x/mod/semver" ) const ( - sdkRepo = "https://github.com/stackitcloud/stackit-sdk-go" + sdkRepo = "git@github.com:stackitcloud/stackit-sdk-go.git" patch = "patch" minor = "minor" ) @@ -23,8 +25,9 @@ var ( ) func main() { - if len(os.Args) != 2 && len(os.Args) != 3 { - fmt.Println("wrong number of arguments. Usage: go run automatic-tag.go [minor|patch] --core-only") + // Parse arguments + if len(os.Args) != 3 && len(os.Args) != 4 { + fmt.Println("wrong number of arguments. Usage: go run automatic-tag.go [minor|patch] private-key-file-path --core-only") os.Exit(1) } @@ -37,22 +40,53 @@ func main() { } } if !valid { - fmt.Printf("the provided argument `%s` is not valid, the valid values are: [%s]\n", updateType, strings.Join(updateTypes, ",")) + fmt.Printf("the provided argument for update type `%s` is not valid, the valid values are: [%s]\n", updateType, strings.Join(updateTypes, ",")) os.Exit(1) } + privateKeyFile := os.Args[2] + _, err := os.Stat(privateKeyFile) + if err != nil { + fmt.Printf("the provided private key file path %s is not valid: %s\nUsage: go run automatic-tag.go [minor|patch] private-key-file-path --core-only\n", privateKeyFile, err) + os.Exit(1) + } + + // Parse flag + var coreOnly bool + if len(os.Args) == 4 { + if os.Args[3] != "--core-only" { + fmt.Println("wrong arguments. Usage: go run automatic-tag.go [minor|patch] --core-only") + os.Exit(1) + } + coreOnly = true + } + tempDir, err := os.MkdirTemp("", "") if err != nil { fmt.Printf("create temporary directory: %s", err.Error()) os.Exit(1) } + defer func() { + tempErr := os.RemoveAll(tempDir) + if tempErr != nil { + fmt.Printf("temporary directory %s could not be removed: %s", tempDir, tempErr.Error()) + } + }() + + publicKeys, err := ssh.NewPublicKeysFromFile("git", privateKeyFile, "") + if err != nil { + fmt.Printf("get public keys from private key file: %s\n", err.Error()) + os.Exit(1) + } + r, err := git.PlainClone(tempDir, false, &git.CloneOptions{ + Auth: publicKeys, URL: sdkRepo, RecurseSubmodules: git.DefaultSubmoduleRecursionDepth, }) if err != nil { - fmt.Printf("clone SDK repo: %s", err.Error()) + fmt.Printf("clone SDK repo: %s\n", err.Error()) os.Exit(1) } @@ -62,15 +96,6 @@ func main() { os.Exit(1) } - var coreOnly bool - if len(os.Args) == 3 { - if os.Args[2] != "--core-only" { - fmt.Println("wrong arguments. Usage: go run automatic-tag.go [minor|patch] --core-only") - os.Exit(1) - } - coreOnly = true - } - existingTags := map[string]string{} err = tagrefs.ForEach(func(t *plumbing.Reference) error { tagName, _ := strings.CutPrefix(t.Name().String(), "refs/tags/") @@ -90,7 +115,6 @@ func main() { if semver.Compare(existingTags["core"], version) == -1 { existingTags["core"] = version } - } else { if len(splitTag) != 3 || splitTag[0] != "services" { return nil @@ -115,55 +139,63 @@ func main() { } for service, version := range existingTags { - canonicalVersion := semver.Canonical(version) - splitVersion := strings.Split(canonicalVersion, ".") - if len(splitVersion) != 3 { - fmt.Printf("Invalid canonical version for service %s with version %s, this tag will be skipped\n", service, version) + newTag, err := incrementTag(service, version, updateType, coreOnly) + if err != nil { + fmt.Printf("Error for %s with version %s, this tag will be skipped\n", service, version) continue } - switch updateType { - case patch: - patchNumber, err := strconv.Atoi(splitVersion[2]) - if err != nil { - fmt.Printf("Couldnt convert patch number to int for service %s with version %s, this tag will be skipped\n", service, version) - continue - } - updatedPatchNumber := patchNumber + 1 - splitVersion[2] = fmt.Sprint(updatedPatchNumber) - case minor: - minorNumber, err := strconv.Atoi(splitVersion[1]) - if err != nil { - fmt.Printf("Couldnt convert minor number to int for service %s with version %s, this tag will be skipped\n", service, version) - continue - } - updatedPatchNumber := minorNumber + 1 - splitVersion[1] = fmt.Sprint(updatedPatchNumber) - splitVersion[2] = "0" - default: - fmt.Println("Update type not supported in version increment, fix the script") - os.Exit(1) - } - updatedVersion := strings.Join(splitVersion, ".") - var newTag string - if coreOnly { - newTag = fmt.Sprintf("core/%s", updatedVersion) - } else { - newTag = fmt.Sprintf("services/%s/%s", service, updatedVersion) - } - err := createTag(r, newTag) + + err = createTag(r, newTag) if err != nil { - fmt.Printf("Create tag %s returned error: %s", newTag, err) + fmt.Printf("Create tag %s returned error: %s\n", newTag, err) continue } - fmt.Printf("Created tag %s", newTag) + fmt.Printf("Created tag %s\n", newTag) } - err = pushTags(r) + err = pushTags(r, publicKeys) if err != nil { - fmt.Printf("push tags: %s", err) + fmt.Printf("push tags: %s\n", err) os.Exit(1) } +} +func incrementTag(service, version, updateType string, coreOnly bool) (string, error) { + canonicalVersion := semver.Canonical(version) + splitVersion := strings.Split(canonicalVersion, ".") + if len(splitVersion) != 3 { + return "", fmt.Errorf("invalid canonical version") + } + + switch updateType { + case patch: + patchNumber, err := strconv.Atoi(splitVersion[2]) + if err != nil { + return "", fmt.Errorf("couldnt convert patch number to int") + } + updatedPatchNumber := patchNumber + 1 + splitVersion[2] = fmt.Sprint(updatedPatchNumber) + case minor: + minorNumber, err := strconv.Atoi(splitVersion[1]) + if err != nil { + return "", fmt.Errorf("couldnt convert minor number to int") + } + updatedPatchNumber := minorNumber + 1 + splitVersion[1] = fmt.Sprint(updatedPatchNumber) + splitVersion[2] = "0" + default: + fmt.Println("Update type not supported in version increment, fix the script") + os.Exit(1) + } + + updatedVersion := strings.Join(splitVersion, ".") + var newTag string + if coreOnly { + newTag = fmt.Sprintf("core/%s", updatedVersion) + } else { + newTag = fmt.Sprintf("services/%s/%s", service, updatedVersion) + } + return newTag, nil } func createTag(r *git.Repository, tag string) error { @@ -178,9 +210,9 @@ func createTag(r *git.Repository, tag string) error { return nil } -func pushTags(r *git.Repository) error { - +func pushTags(r *git.Repository, publicKeys *ssh.PublicKeys) error { po := &git.PushOptions{ + Auth: publicKeys, RemoteName: "origin", Progress: os.Stdout, RefSpecs: []config.RefSpec{config.RefSpec("refs/tags/*:refs/tags/*")}, @@ -188,7 +220,7 @@ func pushTags(r *git.Repository) error { err := r.Push(po) if err != nil { - if err == git.NoErrAlreadyUpToDate { + if errors.Is(err, git.NoErrAlreadyUpToDate) { return fmt.Errorf("origin remote was up to date, no push done") } return fmt.Errorf("push to remote origin: %w", err) diff --git a/scripts/go.mod b/scripts/go.mod index 2540c1e8a..587f6b2e3 100644 --- a/scripts/go.mod +++ b/scripts/go.mod @@ -23,10 +23,10 @@ require ( github.com/kevinburke/ssh_config v1.2.0 // indirect github.com/sergi/go-diff v1.1.0 // indirect github.com/xanzy/ssh-agent v0.3.3 // indirect - golang.org/x/crypto v0.16.0 // indirect + golang.org/x/crypto v0.19.0 // indirect golang.org/x/mod v0.12.0 - golang.org/x/net v0.19.0 // indirect - golang.org/x/sys v0.15.0 // indirect + golang.org/x/net v0.21.0 // indirect + golang.org/x/sys v0.17.0 // indirect golang.org/x/tools v0.13.0 // indirect gopkg.in/warnings.v0 v0.1.2 // indirect ) diff --git a/scripts/go.sum b/scripts/go.sum index 75e75959e..4b6b0d1bf 100644 --- a/scripts/go.sum +++ b/scripts/go.sum @@ -5,113 +5,82 @@ github.com/Microsoft/go-winio v0.6.1 h1:9/kr64B9VUZrLm5YYwbGtUJnMgqWVOdUAXu6Migc github.com/Microsoft/go-winio v0.6.1/go.mod h1:LRdKpFKfdobln8UmuiYcKPot9D2v6svN5+sAH+4kjUM= github.com/ProtonMail/go-crypto v0.0.0-20230828082145-3c4c8a2d2371 h1:kkhsdkhsCvIsutKu5zLMgWtgh9YxGCNAw8Ad8hjwfYg= github.com/ProtonMail/go-crypto v0.0.0-20230828082145-3c4c8a2d2371/go.mod h1:EjAoLdwvbIOoOQr3ihjnSoLZRtE8azugULFRteWMNc0= -github.com/alcortesm/tgz v0.0.0-20161220082320-9c5fe88206d7/go.mod h1:6zEj6s6u/ghQa61ZWa/C2Aw3RkjiTBOix7dkqa1VLIs= -github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239/go.mod h1:2FmKhYUyUczH0OGQWaF5ceTx0UBShxjsH6f8oGKYe2c= github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be h1:9AeTilPcZAjCFIImctFaOjnTIavg87rW78vTPkQqLI8= 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/bwesterb/go-ristretto v1.2.3/go.mod h1:fUIoIZaG73pV5biE2Blr2xEzDoMj7NFEuV9ekS419A0= github.com/cloudflare/circl v1.3.3 h1:fE/Qz0QdIGqeWfnwq0RE0R7MI51s0M2E4Ga9kq5AEMs= github.com/cloudflare/circl v1.3.3/go.mod h1:5XYMA4rFBvNIrhs50XuiBJ15vF2pZn4nnUKZrLbUZFA= -github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY= github.com/cyphar/filepath-securejoin v0.2.4 h1:Ugdm7cg7i6ZK6x3xDF1oEu1nfkyfH53EtKeQYTC3kyg= github.com/cyphar/filepath-securejoin v0.2.4/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= github.com/elazarl/goproxy v0.0.0-20230808193330-2592e75ae04a h1:mATvB/9r/3gvcejNsXKSkQ6lcIaNec2nyfOdlTBR2lU= -github.com/emirpasic/gods v1.12.0/go.mod h1:YfzfFFoVP/catgzJb4IKIqXjX78Ha8FMSDh3ymbK86o= github.com/emirpasic/gods v1.18.1 h1:FXtiHYKDGKCW2KzwZKx0iC0PQmdlorYgdFG9jPXJ1Bc= github.com/emirpasic/gods v1.18.1/go.mod h1:8tpGGwCnJ5H4r6BWwaV6OrWmMoPhUl5jm/FMNAnJvWQ= -github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc= -github.com/gliderlabs/ssh v0.2.2/go.mod h1:U7qILu1NlMHj9FlMhZLlkCdDnU1DBEAqr0aevW3Awn0= github.com/gliderlabs/ssh v0.3.5 h1:OcaySEmAQJgyYcArR+gGGTHCyE7nvhEMTlYY+Dp8CpY= 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 v4.7.0+incompatible h1:+W9rgGY4DOKKdX2x6HxSR7HNeTxqiKrOvKnuittYVdA= -github.com/go-git/go-git v4.7.0+incompatible/go.mod h1:6+421e08gnZWn30y26Vchf7efgYLe4dl5OQbBSUXShE= github.com/go-git/go-git-fixtures/v4 v4.3.2-0.20231010084843-55a94097c399 h1:eMje31YglSBqCdIqdhKBW8lokaMrL3uTkpGYlE2OOT4= github.com/go-git/go-git/v5 v5.11.0 h1:XIZc1p+8YzypNr34itUfSvYJcv+eYdTnTvOZ2vD3cA4= github.com/go-git/go-git/v5 v5.11.0/go.mod h1:6GFcX2P3NM7FPBfpePbpLd21XxsgdAt+lKqXmCUiUCY= 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/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= 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/kevinburke/ssh_config v0.0.0-20190725054713-01f96b0aa0cd/go.mod h1:CT57kijsi8u/K/BOFA39wgDQJ9CxiF4nAY/ojJ6r6mM= 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/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= -github.com/kr/pty v1.1.8/go.mod h1:O1sed60cT9XZ5uDucP5qwvh+TE3NnUj51EiZO/lmSfw= 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/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= github.com/onsi/gomega v1.27.10 h1:naR28SdDFlqrG6kScpT8VWpu1xWY5nJRCF3XaYyBjhI= -github.com/pelletier/go-buffruneio v0.2.0/go.mod h1:JkE26KsDizTr40EUHkXVtNPvgGtbSNq5BcowyYOWdKo= 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.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= 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= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M= -github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo= github.com/sergi/go-diff v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0= github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM= github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0= github.com/skeema/knownhosts v1.2.1 h1:SHWdIUa82uGZz+F+47k8SY4QhhI291cXCpopT1lK2AQ= github.com/skeema/knownhosts v1.2.1/go.mod h1:xYbVRSPxqBZFrdmDyMmsOs+uX1UZC3nTN3ThzgDxUwo= -github.com/src-d/gcfg v1.4.0 h1:xXbNR5AlLSA315x2UO+fTSSAXCDf+Ar38/6oyGbDKQ4= -github.com/src-d/gcfg v1.4.0/go.mod h1:p/UMsR43ujA89BJY9duynAwIpvqEujIH/jFlfL7jWoI= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE= 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.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= -github.com/xanzy/ssh-agent v0.2.1/go.mod h1:mLlQY/MoOhWBj+gOGMQkOeiEvkx+8pJSI+0Bx9h2kr4= 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/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= -golang.org/x/crypto v0.0.0-20190219172222-a4c6cb3142f2/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= 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.16.0 h1:mMMrFzRSCF0GvB7Ne27XVtVAaXLrPmgPC7/v0tkwHaY= -golang.org/x/crypto v0.16.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4= +golang.org/x/crypto v0.19.0 h1:ENy+Az/9Y1vSrlrvBSyna3PITt4tiZLf7sgCjZBX7Wo= 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.12.0 h1:rmsUpXtvNzj340zd98LZ4KntptpfRHwpFOHG188oHXc= golang.org/x/mod v0.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= -golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20190724013045-ca1201d0de80/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.19.0 h1:zTwKpTd2XuCqf8huc7Fo2iSy+4RHPd10s4KzeTnVr1c= -golang.org/x/net v0.19.0/go.mod h1:CfAk/cbD4CthTvqiEl8NpboMuiuOYsAr/7NOjZJtv1U= +golang.org/x/net v0.21.0 h1:AQyQV4dYCvJ7vGmJyKki9+PBdyvhkSd8EIx/qb0AYv4= 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.3.0 h1:ftCYgMx6zT/asHUrPw8BLLscYtGznsLAnjq5RH9P66E= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190221075227-b4e8571b14e0/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/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-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -124,16 +93,14 @@ 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.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc= -golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.17.0 h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y= 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/term v0.15.0 h1:y/Oo/a/q3IXu26lQgl04j/gjuBDOBlx7X6Om1j2CPW4= +golang.org/x/term v0.17.0 h1:mkTF7LCd6WGJNL3K1Ad7kwxNfYAW6a8a8QqtMblp/4U= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= 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= @@ -142,7 +109,6 @@ 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.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20190729092621-ff9f1409240a/go.mod h1:jcCCGcm9btYwXyDqrUWc6MKQKKGJCWEQ3AfLSRIbEuI= 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= @@ -150,13 +116,8 @@ golang.org/x/tools v0.13.0 h1:Iey4qkscZuv0VvIt8E0neZjtPVQFSc870HQ448QgEmQ= golang.org/x/tools v0.13.0/go.mod h1:HvlwmtVNQAhOuCjW7xxvovg8wbNq7LwfXh/k7wXUl58= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/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/src-d/go-billy.v4 v4.3.2/go.mod h1:nDjArDMp+XMs1aFAESLRjfGSgfvoYN0hDfzEk0GjC98= -gopkg.in/src-d/go-git-fixtures.v3 v3.5.0/go.mod h1:dLBcvytrw/TYZsNTWCnkNF2DSIlzWYqTe3rJR56Ac7g= -gopkg.in/src-d/go-git.v4 v4.13.1 h1:SRtFyV8Kxc0UP7aCHcijOMQGPxHSmMOPrzulQWolkYE= -gopkg.in/src-d/go-git.v4 v4.13.1/go.mod h1:nx5NYcxdKxq5fpltdHnPa2Exj4Sx0EclMWZQbYDu2z8= 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.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= diff --git a/scripts/lint-golangci-lint.sh b/scripts/lint-golangci-lint.sh index 28cdd476c..15a8de611 100755 --- a/scripts/lint-golangci-lint.sh +++ b/scripts/lint-golangci-lint.sh @@ -11,6 +11,7 @@ fi ROOT_DIR=$(git rev-parse --show-toplevel) CORE_PATH="${ROOT_DIR}/core" +SCRIPTS_PATH="${ROOT_DIR}/scripts" SERVICES_PATH="${ROOT_DIR}/services" EXAMPLES_PATH="${ROOT_DIR}/examples" GOLANG_CI_YAML_PATH="${ROOT_DIR}/golang-ci.yaml" @@ -29,6 +30,12 @@ if [ "${SKIP_NON_GENERATED_FILES}" = false ]; then golangci-lint run ${GOLANG_CI_ARGS} fi +if [ "${SKIP_NON_GENERATED_FILES}" = false ]; then + echo ">> Linting scripts" + cd ${SCRIPTS_PATH} + golangci-lint run ${GOLANG_CI_ARGS} +fi + for service_dir in ${SERVICES_PATH}/*; do service=$(basename ${service_dir}) echo ">> Linting service ${service}" From 4cdcd823b5e04973d4056bafa0275c8df3066e3a Mon Sep 17 00:00:00 2001 From: vicentepinto98 Date: Thu, 22 Feb 2024 16:22:48 +0000 Subject: [PATCH 04/20] Unit tests --- go.work.sum | 39 ---- .../{automatic-tag.go => automatic_tag.go} | 136 ++++++------ scripts/automatic_tag_test.go | 199 ++++++++++++++++++ scripts/test-go.sh | 6 + 4 files changed, 278 insertions(+), 102 deletions(-) rename scripts/{automatic-tag.go => automatic_tag.go} (55%) create mode 100644 scripts/automatic_tag_test.go diff --git a/go.work.sum b/go.work.sum index a1abc44d5..f2cf57865 100644 --- a/go.work.sum +++ b/go.work.sum @@ -1,41 +1,2 @@ -github.com/alcortesm/tgz v0.0.0-20161220082320-9c5fe88206d7/go.mod h1:6zEj6s6u/ghQa61ZWa/C2Aw3RkjiTBOix7dkqa1VLIs= -github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239/go.mod h1:2FmKhYUyUczH0OGQWaF5ceTx0UBShxjsH6f8oGKYe2c= -github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs= -github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY= -github.com/emirpasic/gods v1.12.0/go.mod h1:YfzfFFoVP/catgzJb4IKIqXjX78Ha8FMSDh3ymbK86o= -github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc= -github.com/gliderlabs/ssh v0.2.2/go.mod h1:U7qILu1NlMHj9FlMhZLlkCdDnU1DBEAqr0aevW3Awn0= -github.com/go-git/go-git v4.7.0+incompatible h1:+W9rgGY4DOKKdX2x6HxSR7HNeTxqiKrOvKnuittYVdA= -github.com/go-git/go-git v4.7.0+incompatible/go.mod h1:6+421e08gnZWn30y26Vchf7efgYLe4dl5OQbBSUXShE= -github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= -github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= -github.com/kevinburke/ssh_config v0.0.0-20190725054713-01f96b0aa0cd/go.mod h1:CT57kijsi8u/K/BOFA39wgDQJ9CxiF4nAY/ojJ6r6mM= -github.com/kr/pty v1.1.8/go.mod h1:O1sed60cT9XZ5uDucP5qwvh+TE3NnUj51EiZO/lmSfw= -github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= -github.com/pelletier/go-buffruneio v0.2.0/go.mod h1:JkE26KsDizTr40EUHkXVtNPvgGtbSNq5BcowyYOWdKo= -github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= -github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo= -github.com/src-d/gcfg v1.4.0/go.mod h1:p/UMsR43ujA89BJY9duynAwIpvqEujIH/jFlfL7jWoI= -github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE= -github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= -github.com/xanzy/ssh-agent v0.2.1/go.mod h1:mLlQY/MoOhWBj+gOGMQkOeiEvkx+8pJSI+0Bx9h2kr4= -golang.org/x/crypto v0.0.0-20190219172222-a4c6cb3142f2/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= -golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/crypto v0.16.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4= golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU= -golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20190724013045-ca1201d0de80/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= -golang.org/x/net v0.19.0/go.mod h1:CfAk/cbD4CthTvqiEl8NpboMuiuOYsAr/7NOjZJtv1U= -golang.org/x/sys v0.0.0-20190221075227-b4e8571b14e0/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/term v0.17.0/go.mod h1:lLRBjIVuehSbZlaOtGMbcMncT+aqLLLmKrsjNrUguwk= -golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= -golang.org/x/tools v0.0.0-20190729092621-ff9f1409240a/go.mod h1:jcCCGcm9btYwXyDqrUWc6MKQKKGJCWEQ3AfLSRIbEuI= -gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/src-d/go-billy.v4 v4.3.2/go.mod h1:nDjArDMp+XMs1aFAESLRjfGSgfvoYN0hDfzEk0GjC98= -gopkg.in/src-d/go-git-fixtures.v3 v3.5.0/go.mod h1:dLBcvytrw/TYZsNTWCnkNF2DSIlzWYqTe3rJR56Ac7g= -gopkg.in/src-d/go-git.v4 v4.13.1/go.mod h1:nx5NYcxdKxq5fpltdHnPa2Exj4Sx0EclMWZQbYDu2z8= diff --git a/scripts/automatic-tag.go b/scripts/automatic_tag.go similarity index 55% rename from scripts/automatic-tag.go rename to scripts/automatic_tag.go index 1daf78bfd..24fceec52 100644 --- a/scripts/automatic-tag.go +++ b/scripts/automatic_tag.go @@ -15,9 +15,11 @@ import ( ) const ( - sdkRepo = "git@github.com:stackitcloud/stackit-sdk-go.git" + //sdkRepo = "git@github.com:stackitcloud/stackit-sdk-go.git" + sdkRepo = "git@github.com:vicentepinto98/gh.git" patch = "patch" minor = "minor" + usage = "go run automatic_tag.go [minor|patch] private-key-file-path --core-only" ) var ( @@ -27,7 +29,7 @@ var ( func main() { // Parse arguments if len(os.Args) != 3 && len(os.Args) != 4 { - fmt.Println("wrong number of arguments. Usage: go run automatic-tag.go [minor|patch] private-key-file-path --core-only") + fmt.Printf("wrong number of arguments. Usage: %s\n", usage) os.Exit(1) } @@ -47,7 +49,7 @@ func main() { privateKeyFile := os.Args[2] _, err := os.Stat(privateKeyFile) if err != nil { - fmt.Printf("the provided private key file path %s is not valid: %s\nUsage: go run automatic-tag.go [minor|patch] private-key-file-path --core-only\n", privateKeyFile, err) + fmt.Printf("The provided private key file path %s is not valid: %s\nUsage: %s\n", privateKeyFile, err, usage) os.Exit(1) } @@ -55,29 +57,35 @@ func main() { var coreOnly bool if len(os.Args) == 4 { if os.Args[3] != "--core-only" { - fmt.Println("wrong arguments. Usage: go run automatic-tag.go [minor|patch] --core-only") + fmt.Printf("Wrong arguments. Usage: %s\n", usage) os.Exit(1) } coreOnly = true } - tempDir, err := os.MkdirTemp("", "") + err = automaticTagUpdate(updateType, privateKeyFile, coreOnly) if err != nil { - fmt.Printf("create temporary directory: %s", err.Error()) + fmt.Printf("Error updating tags: %s\n", err.Error()) os.Exit(1) } +} + +func automaticTagUpdate(updateType, privateKeyFile string, coreOnly bool) error { + tempDir, err := os.MkdirTemp("", "") + if err != nil { + return fmt.Errorf("create temporary directory: %w", err) + } defer func() { tempErr := os.RemoveAll(tempDir) - if tempErr != nil { - fmt.Printf("temporary directory %s could not be removed: %s", tempDir, tempErr.Error()) + if tempErr != nil && err == nil { + err = fmt.Errorf("temporary directory %s could not be removed: %w", tempDir, tempErr) } }() publicKeys, err := ssh.NewPublicKeysFromFile("git", privateKeyFile, "") if err != nil { - fmt.Printf("get public keys from private key file: %s\n", err.Error()) - os.Exit(1) + return fmt.Errorf("get public keys from private key file: %w", err) } r, err := git.PlainClone(tempDir, false, &git.CloneOptions{ @@ -86,62 +94,27 @@ func main() { RecurseSubmodules: git.DefaultSubmoduleRecursionDepth, }) if err != nil { - fmt.Printf("clone SDK repo: %s\n", err.Error()) - os.Exit(1) + return fmt.Errorf("clone SDK repo: %w", err) } tagrefs, err := r.Tags() if err != nil { - fmt.Printf("get tags: %s", err.Error()) - os.Exit(1) + return fmt.Errorf("get tags: %w", err) } - existingTags := map[string]string{} + latestTags := map[string]string{} err = tagrefs.ForEach(func(t *plumbing.Reference) error { - tagName, _ := strings.CutPrefix(t.Name().String(), "refs/tags/") - splitTag := strings.Split(tagName, "/") - - if coreOnly { - if len(splitTag) != 2 || splitTag[0] != "core" { - return nil - } - - version := splitTag[1] - if semver.Prerelease(version) != "" { - return nil - } - - // invalid (or empty) semantic version are considered less than a valid one - if semver.Compare(existingTags["core"], version) == -1 { - existingTags["core"] = version - } - } else { - if len(splitTag) != 3 || splitTag[0] != "services" { - return nil - } - - service := splitTag[1] - version := splitTag[2] - if semver.Prerelease(version) != "" { - return nil - } - - // invalid (or empty) semantic version are considered less than a valid one - if semver.Compare(existingTags[service], version) == -1 { - existingTags[service] = version - } - } + latestTags = storeLatestTag(t, latestTags, coreOnly) return nil }) if err != nil { - fmt.Printf("iterate over existing tags: %s\n", err.Error()) - os.Exit(1) + return fmt.Errorf("iterate over existing tags: %w", err) } - for service, version := range existingTags { - newTag, err := incrementTag(service, version, updateType, coreOnly) + for service, version := range latestTags { + newTag, err := computeUpdatedTag(service, version, updateType, coreOnly) if err != nil { - fmt.Printf("Error for %s with version %s, this tag will be skipped\n", service, version) + fmt.Printf("Error for %s with version %s, this tag will be skipped. Error: %s\n", service, version, err.Error()) continue } @@ -155,12 +128,49 @@ func main() { err = pushTags(r, publicKeys) if err != nil { - fmt.Printf("push tags: %s\n", err) - os.Exit(1) + return fmt.Errorf("push tags: %w", err) } + return nil } -func incrementTag(service, version, updateType string, coreOnly bool) (string, error) { +func storeLatestTag(t *plumbing.Reference, latestTags map[string]string, coreOnly bool) map[string]string { + tagName, _ := strings.CutPrefix(t.Name().String(), "refs/tags/") + splitTag := strings.Split(tagName, "/") + + if coreOnly { + if len(splitTag) != 2 || splitTag[0] != "core" { + return latestTags + } + + version := splitTag[1] + if semver.Prerelease(version) != "" { + return latestTags + } + + // invalid (or empty) semantic version are considered less than a valid one + if semver.Compare(latestTags["core"], version) == -1 { + latestTags["core"] = version + } + } else { + if len(splitTag) != 3 || splitTag[0] != "services" { + return latestTags + } + + service := splitTag[1] + version := splitTag[2] + if semver.Prerelease(version) != "" { + return latestTags + } + + // invalid (or empty) semantic version are considered less than a valid one + if semver.Compare(latestTags[service], version) == -1 { + latestTags[service] = version + } + } + return latestTags +} + +func computeUpdatedTag(service, version, updateType string, coreOnly bool) (string, error) { canonicalVersion := semver.Canonical(version) splitVersion := strings.Split(canonicalVersion, ".") if len(splitVersion) != 3 { @@ -184,18 +194,18 @@ func incrementTag(service, version, updateType string, coreOnly bool) (string, e splitVersion[1] = fmt.Sprint(updatedPatchNumber) splitVersion[2] = "0" default: - fmt.Println("Update type not supported in version increment, fix the script") - os.Exit(1) + return "", fmt.Errorf("update type not supported in version increment, fix the script") } updatedVersion := strings.Join(splitVersion, ".") - var newTag string if coreOnly { - newTag = fmt.Sprintf("core/%s", updatedVersion) - } else { - newTag = fmt.Sprintf("services/%s/%s", service, updatedVersion) + if service != "core" { + return "", fmt.Errorf("--core-only was provided but store latest tag from another service: %s", service) + } + return fmt.Sprintf("core/%s", updatedVersion), nil } - return newTag, nil + + return fmt.Sprintf("services/%s/%s", service, updatedVersion), nil } func createTag(r *git.Repository, tag string) error { diff --git a/scripts/automatic_tag_test.go b/scripts/automatic_tag_test.go new file mode 100644 index 000000000..d4c064c5c --- /dev/null +++ b/scripts/automatic_tag_test.go @@ -0,0 +1,199 @@ +package main + +import ( + "reflect" + "testing" + + "github.com/go-git/go-git/v5/plumbing" +) + +func TestStoreLatestTag(t *testing.T) { + for _, test := range []struct { + desc string + tag *plumbing.Reference + latestTags map[string]string + coreOnly bool + expectedLatestTags map[string]string + }{ + { + desc: "valid service latest version", + tag: plumbing.NewReferenceFromStrings("refs/tags/services/foo/v0.2.0", ""), + latestTags: map[string]string{ + "foo": "v0.1.0", + "bar": "v0.1.0", + }, + coreOnly: false, + expectedLatestTags: map[string]string{ + "foo": "v0.2.0", + "bar": "v0.1.0", + }, + }, + { + desc: "valid service no update", + tag: plumbing.NewReferenceFromStrings("refs/tags/services/foo/v0.1.0", ""), + latestTags: map[string]string{ + "foo": "v0.1.0", + "bar": "v0.1.0", + }, + coreOnly: false, + expectedLatestTags: map[string]string{ + "foo": "v0.1.0", + "bar": "v0.1.0", + }, + }, + { + desc: "valid core latest version", + tag: plumbing.NewReferenceFromStrings("refs/tags/core/v0.2.0", ""), + latestTags: map[string]string{ + "foo": "v0.1.0", + "bar": "v0.1.0", + "core": "v0.1.0", + }, + coreOnly: true, + expectedLatestTags: map[string]string{ + "foo": "v0.1.0", + "bar": "v0.1.0", + "core": "v0.2.0", + }, + }, + { + desc: "valid core latest version", + tag: plumbing.NewReferenceFromStrings("refs/tags/core/v0.2.0", ""), + latestTags: map[string]string{ + "foo": "v0.1.0", + "bar": "v0.1.0", + "core": "v0.1.0", + }, + coreOnly: true, + expectedLatestTags: map[string]string{ + "foo": "v0.1.0", + "bar": "v0.1.0", + "core": "v0.2.0", + }, + }, + { + desc: "invalid service tag", + tag: plumbing.NewReferenceFromStrings("refs/tags/foo/v0.2.0", ""), + latestTags: map[string]string{ + "foo": "v0.1.0", + "bar": "v0.1.0", + }, + coreOnly: false, + expectedLatestTags: map[string]string{ + "foo": "v0.1.0", + "bar": "v0.1.0", + }, + }, + { + desc: "valid service tag but coreOnly", + tag: plumbing.NewReferenceFromStrings("refs/tags/services/foo/v0.2.0", ""), + latestTags: map[string]string{ + "foo": "v0.1.0", + "bar": "v0.1.0", + }, + coreOnly: true, + expectedLatestTags: map[string]string{ + "foo": "v0.1.0", + "bar": "v0.1.0", + }, + }, + { + desc: "dont update to pre-release", + tag: plumbing.NewReferenceFromStrings("refs/tags/services/foo/v0.2.0-pre-release", ""), + latestTags: map[string]string{ + "foo": "v0.1.0", + "bar": "v0.1.0", + }, + coreOnly: true, + expectedLatestTags: map[string]string{ + "foo": "v0.1.0", + "bar": "v0.1.0", + }, + }, + } { + t.Run(test.desc, func(t *testing.T) { + updatedLatestTags := storeLatestTag(test.tag, test.latestTags, test.coreOnly) + if !reflect.DeepEqual(test.expectedLatestTags, updatedLatestTags) { + t.Fatalf("Updated tags are wrong, expected %v, got %v", test.expectedLatestTags, updatedLatestTags) + } + }) + } +} + +func TestComputeUpdatedTag(t *testing.T) { + for _, test := range []struct { + desc string + service string + version string + updateType string + coreOnly bool + expectedTag string + isValid bool + }{ + { + desc: "valid service minor update", + service: "foo", + version: "v0.1.0", + updateType: "minor", + expectedTag: "services/foo/v0.2.0", + isValid: true, + }, + { + desc: "valid service patch update", + service: "foo", + version: "v0.1.0", + updateType: "patch", + expectedTag: "services/foo/v0.1.1", + isValid: true, + }, + { + desc: "valid core minor update", + service: "core", + version: "v0.1.0", + updateType: "minor", + coreOnly: true, + expectedTag: "core/v0.2.0", + isValid: true, + }, + { + desc: "valid core patch update", + service: "core", + version: "v0.1.0", + updateType: "patch", + coreOnly: true, + expectedTag: "core/v0.1.1", + isValid: true, + }, + { + desc: "invalid update type", + service: "foo", + version: "v0.1.0", + updateType: "major", + isValid: false, + }, + { + desc: "invalid core update with wrong name - this should never happen", + service: "foo", + version: "v0.1.0", + updateType: "patch", + coreOnly: true, + isValid: false, + }, + } { + t.Run(test.desc, func(t *testing.T) { + updatedTag, err := computeUpdatedTag(test.service, test.version, test.updateType, test.coreOnly) + + if err != nil && test.isValid { + t.Fatalf("Test returned error on valid test case: %v", err) + } + + if err == nil && !test.isValid { + t.Fatalf("Test didn't return error on invalid test case") + } + + if test.isValid && test.expectedTag != updatedTag { + t.Fatalf("updated tag is wrong: expected %s, got %s", test.expectedTag, updatedTag) + } + }) + } +} diff --git a/scripts/test-go.sh b/scripts/test-go.sh index 869dcdbaf..f096438c0 100755 --- a/scripts/test-go.sh +++ b/scripts/test-go.sh @@ -12,6 +12,7 @@ fi ROOT_DIR=$(git rev-parse --show-toplevel) GOTEST_ARGS="-timeout=5m -cover -count=1" CORE_PATH="${ROOT_DIR}/core" +SCRIPTS_PATH="${ROOT_DIR}/scripts" SERVICES_PATH="${ROOT_DIR}/services" if type -p go >/dev/null; then @@ -26,6 +27,11 @@ if [ "${SKIP_NON_GENERATED_FILES}" = false ]; then cd ${CORE_PATH} go test ./... ${GOTEST_ARGS} fi +if [ "${SKIP_NON_GENERATED_FILES}" = false ]; then + echo ">> Testing scripts" + cd ${SCRIPTS_PATH} + go test ./... ${GOTEST_ARGS} +fi for service_dir in ${SERVICES_PATH}/*; do service=$(basename ${service_dir}) From de3b97e515eb6061ffb542c4d6ee439b7521a3e1 Mon Sep 17 00:00:00 2001 From: vicentepinto98 Date: Thu, 22 Feb 2024 16:23:51 +0000 Subject: [PATCH 05/20] Replace url --- scripts/automatic_tag.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/scripts/automatic_tag.go b/scripts/automatic_tag.go index 24fceec52..574fdd568 100644 --- a/scripts/automatic_tag.go +++ b/scripts/automatic_tag.go @@ -15,8 +15,7 @@ import ( ) const ( - //sdkRepo = "git@github.com:stackitcloud/stackit-sdk-go.git" - sdkRepo = "git@github.com:vicentepinto98/gh.git" + sdkRepo = "git@github.com:stackitcloud/stackit-sdk-go.git" patch = "patch" minor = "minor" usage = "go run automatic_tag.go [minor|patch] private-key-file-path --core-only" From 195ccec6c5db5f0e269247d114d3c068ecd9864d Mon Sep 17 00:00:00 2001 From: vicentepinto98 Date: Thu, 22 Feb 2024 16:25:22 +0000 Subject: [PATCH 06/20] Rename variables --- scripts/automatic_tag.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/scripts/automatic_tag.go b/scripts/automatic_tag.go index 574fdd568..74add2617 100644 --- a/scripts/automatic_tag.go +++ b/scripts/automatic_tag.go @@ -18,7 +18,7 @@ const ( sdkRepo = "git@github.com:stackitcloud/stackit-sdk-go.git" patch = "patch" minor = "minor" - usage = "go run automatic_tag.go [minor|patch] private-key-file-path --core-only" + usage = "go run automatic_tag.go [minor|patch] ssh-private-key-file-path --core-only" ) var ( @@ -45,10 +45,10 @@ func main() { os.Exit(1) } - privateKeyFile := os.Args[2] - _, err := os.Stat(privateKeyFile) + sshPrivateKeyFilePath := os.Args[2] + _, err := os.Stat(sshPrivateKeyFilePath) if err != nil { - fmt.Printf("The provided private key file path %s is not valid: %s\nUsage: %s\n", privateKeyFile, err, usage) + fmt.Printf("The provided private key file path %s is not valid: %s\nUsage: %s\n", sshPrivateKeyFilePath, err, usage) os.Exit(1) } @@ -62,14 +62,14 @@ func main() { coreOnly = true } - err = automaticTagUpdate(updateType, privateKeyFile, coreOnly) + err = automaticTagUpdate(updateType, sshPrivateKeyFilePath, coreOnly) if err != nil { fmt.Printf("Error updating tags: %s\n", err.Error()) os.Exit(1) } } -func automaticTagUpdate(updateType, privateKeyFile string, coreOnly bool) error { +func automaticTagUpdate(updateType, sshPrivateKeyFilePath string, coreOnly bool) error { tempDir, err := os.MkdirTemp("", "") if err != nil { return fmt.Errorf("create temporary directory: %w", err) @@ -82,7 +82,7 @@ func automaticTagUpdate(updateType, privateKeyFile string, coreOnly bool) error } }() - publicKeys, err := ssh.NewPublicKeysFromFile("git", privateKeyFile, "") + publicKeys, err := ssh.NewPublicKeysFromFile("git", sshPrivateKeyFilePath, "") if err != nil { return fmt.Errorf("get public keys from private key file: %w", err) } From f5504ff9b6f90e952e162cf4d31f455ec1489e11 Mon Sep 17 00:00:00 2001 From: vicentepinto98 Date: Thu, 22 Feb 2024 16:26:10 +0000 Subject: [PATCH 07/20] Remove key --- examples/authentication/service_account_key.json | 16 ---------------- 1 file changed, 16 deletions(-) delete mode 100644 examples/authentication/service_account_key.json diff --git a/examples/authentication/service_account_key.json b/examples/authentication/service_account_key.json deleted file mode 100644 index 13298f069..000000000 --- a/examples/authentication/service_account_key.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "id": "b96b30a0-2f92-41c8-9b86-ecaebed825c7", - "publicKey": "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAmRR7zmFSJBXI5dAa7sqT\nwbUhC0QOOfKs9hZcV9TfCG49WkgxInDqG/aYBxxAVSq+qDJqbohUbqcgbLv1qcJF\n1ijGch0P6zazuMbnmigq5zbmuZUWtCVos3IOYBKPAVWvLo3tBd7wpirPC9FOYWzX\nNllhXWrSo0Um17SejcZ6waa6hk7ejBk6G2IFNaDw/W6wXcVN6OTmKp3+EsOixiC2\n8HEnEvpUC3kpWfW1D3czbfB05Y8sPrCScUpIZk/LXseLUVvRRxhQ++4YkudSXpWU\nG2dRFKypU5OvdlxYZsg1mlPJ+8QgY6R7L42thwLhdrGt1h771MrgvJFczTtX0VcL\nBwIDAQAB\n-----END PUBLIC KEY-----", - "createdAt": "2024-01-08T17:21:31.079+00:00", - "keyType": "USER_MANAGED", - "keyOrigin": "GENERATED", - "keyAlgorithm": "RSA_2048", - "active": true, - "credentials": { - "kid": "b96b30a0-2f92-41c8-9b86-ecaebed825c7", - "iss": "my-service-account-84obm21@sa.stackit.cloud", - "sub": "c51ea797-c0fc-4e2e-b26a-bc185e7a180e", - "aud": "https://stackit-service-account-prod.apps.01.cf.eu01.stackit.cloud", - "privateKey": "-----BEGIN PRIVATE KEY-----\nMIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQCZFHvOYVIkFcjl\n0BruypPBtSELRA458qz2FlxX1N8Ibj1aSDEicOob9pgHHEBVKr6oMmpuiFRupyBs\nu/WpwkXWKMZyHQ/rNrO4xueaKCrnNua5lRa0JWizcg5gEo8BVa8uje0F3vCmKs8L\n0U5hbNc2WWFdatKjRSbXtJ6NxnrBprqGTt6MGTobYgU1oPD9brBdxU3o5OYqnf4S\nw6LGILbwcScS+lQLeSlZ9bUPdzNt8HTljyw+sJJxSkhmT8tex4tRW9FHGFD77hiS\n51JelZQbZ1EUrKlTk692XFhmyDWaU8n7xCBjpHsvja2HAuF2sa3WHvvUyuC8kVzN\nO1fRVwsHAgMBAAECggEAHtIT90J68k78iuCye3+H7klUpNsH7jzg/A8WeoyedykS\n6zl7ww5u5EBq7YuPnFYl2uGDskt6jGjTy3CwjoRR4UOGaPVW/imeV8acXNpXgQP5\nwkW1M4IQqYh+QnOaHU+uHLZwkW0IkLwvwZZbrJvoXMX0J4XZcQv8PRPdlHfwwUpL\nrlz1iTz89Gk6XlPemrMfhZi1F895g5qP8wX7M/QfUVvRjGEY/oYJ7k18OSX23brY\nIWrgoqIfw0jKN5vtsQ5VM6zJf0DN03sdeliu/fEcc+PVE6AJ5ixvRRwi7Plcijbl\nU+TBtuvw4kPlOZ1uujWfUmOYT3n0bBTvq7wc6bUIiQKBgQDHM9mn9iS4hmHKuCbe\n0FPJA/+do0KY3nc9Nk3k087jkNUOioBeai8DMJ46MSuwEcVFonGDEPoFyrDsS3Js\ndPo9h/HT2XZRqlJjBGoLSVsh/WKhGYuh5+4WAOCnyj5UeTxrBosjkAsEYFX/X4Ru\n+SP2L4p637+4h6xbzDG6AoX3YwKBgQDEuhFWXHpy7SMsqmfVydCIxltWM4COit/P\nv//k59YtDmmnf1Nr2XSq+eDKxRvEKpCx4s7GMWdsW+6jW659zOm4w+x11PVOECZB\nLcBcWp/tHxRxIZ5yuZNLoTmlr7iMh0nwh6R6dMXMwM5/E6wmZ9E+Mst5Mf9OCdYM\n4k9j6v0JDQKBgQCV4T9dDuhmJkYiHxiwARNpZabIVvRezNPurJNDHtLFik2kGTWo\n1D/3KHeE1UZHvbcuQ6Egun9EKFOiFspLLGC0NzsO6MoLfBltAv8+6ry1AE9bYzsa\nYMVUrOhbluH68RUyecPqyBBiBJHwCVA9pxsVuoN5HCzGjN50W1j22bsufQKBgQCG\njFgFP/TDm6q+BsJDtub4VOntOAZJ93OBrGiBD4stf7kFRREyJyUjNwnmxQ7riM0z\nzNLtPKbmtq2tbqwWAEsuAlo8cO1heawgUgFJaPYOgH5DreGnx4KVbGx4BIntGy6X\n4r28vxb1pjzVLwhDsCetKaJ+fpKFtjZ+013HEdYEFQKBgAcrkrZvg7cjphtUa1Bz\n4vgyiYQ5hfYC0FMUKLwzK8L7WIRP6Y5k99i6V5lhSXndEBu5M4D47A/PrG1jzybB\nJeKwWFlXn+sTT2Sfs63tfDfsKVAXry+OL+IvS0Q5WKSUgdz8IjZU0SHTkNeN+90k\nOzaANONSg1Kp4FodJ0sFqkZ4\n-----END PRIVATE KEY-----" - } -} From 6b27a65759987ab3c7838ecc45e9f96fee2a69bb Mon Sep 17 00:00:00 2001 From: vicentepinto98 Date: Thu, 22 Feb 2024 16:39:02 +0000 Subject: [PATCH 08/20] Skip scripts for go1.18 --- .github/workflows/ci.yaml | 9 +++++++-- Makefile | 4 ++-- scripts/test-go.sh | 7 ++++++- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index adb8b27c9..b0ccb3a44 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -25,6 +25,11 @@ jobs: run: | make lint scripts/check-sync-tidy.sh - + - name: Test for go 1.18 + if: ${{ matrix.go-version == '1.18' }} + run: | + make test skip-non-generated-files=false skip-scripts=true - name: Test - run: make test + if: ${{ matrix.go-version != '1.18' }} + run: | + make test diff --git a/Makefile b/Makefile index 4798552f7..e395ec0dc 100644 --- a/Makefile +++ b/Makefile @@ -23,7 +23,7 @@ lint: sync-tidy # TEST test-go: @echo "Running Go tests" - @$(SCRIPTS_BASE)/test-go.sh ${skip-non-generated-files} + @$(SCRIPTS_BASE)/test-go.sh ${skip-non-generated-files} ${skip-scripts} test: - @$(MAKE) --no-print-directory test-go skip-non-generated-files=${skip-non-generated-files} + @$(MAKE) --no-print-directory test-go skip-non-generated-files=${skip-non-generated-files} skip-scripts=${skip-scripts} diff --git a/scripts/test-go.sh b/scripts/test-go.sh index f096438c0..2f91b3785 100755 --- a/scripts/test-go.sh +++ b/scripts/test-go.sh @@ -9,6 +9,11 @@ if [ ! "${SKIP_NON_GENERATED_FILES}" = true ]; then SKIP_NON_GENERATED_FILES=false fi +SKIP_SCRIPTS="${2}" +if [ ! "${SKIP_SCRIPTS}" = true ]; then + SKIP_SCRIPTS=false +fi + ROOT_DIR=$(git rev-parse --show-toplevel) GOTEST_ARGS="-timeout=5m -cover -count=1" CORE_PATH="${ROOT_DIR}/core" @@ -27,7 +32,7 @@ if [ "${SKIP_NON_GENERATED_FILES}" = false ]; then cd ${CORE_PATH} go test ./... ${GOTEST_ARGS} fi -if [ "${SKIP_NON_GENERATED_FILES}" = false ]; then +if [ "${SKIP_SCRIPTS}" = false ]; then echo ">> Testing scripts" cd ${SCRIPTS_PATH} go test ./... ${GOTEST_ARGS} From a8e6fa7bed47148c55b8213917e59dd2d73c57eb Mon Sep 17 00:00:00 2001 From: vicentepinto98 Date: Thu, 22 Feb 2024 16:48:34 +0000 Subject: [PATCH 09/20] Test and lint scripts only for go 1.21 --- .github/workflows/ci.yaml | 10 +++++++--- Makefile | 14 ++++++++++++-- scripts/lint-golangci-lint.sh | 7 ------- scripts/test-go.sh | 11 ----------- 4 files changed, 19 insertions(+), 23 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index b0ccb3a44..b90d03ba2 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -25,11 +25,15 @@ jobs: run: | make lint scripts/check-sync-tidy.sh - - name: Test for go 1.18 - if: ${{ matrix.go-version == '1.18' }} + - name: Lint scripts + if: ${{ matrix.go-version == '1.21' }} run: | - make test skip-non-generated-files=false skip-scripts=true + make lint-scripts - name: Test if: ${{ matrix.go-version != '1.18' }} run: | make test + - name: Test scripts + if: ${{ matrix.go-version == '1.21' }} + run: | + make test-scripts diff --git a/Makefile b/Makefile index e395ec0dc..d22cbf5fd 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,7 @@ ROOT_DIR ?= $(shell git rev-parse --show-toplevel) SCRIPTS_BASE ?= $(ROOT_DIR)/scripts +GOLANG_CI_YAML_PATH ?= ${ROOT_DIR}/golang-ci.yaml +GOLANG_CI_ARGS ?= --allow-parallel-runners --timeout=5m --config=${GOLANG_CI_YAML_PATH} # SETUP AND TOOL INITIALIZATION TASKS project-help: @@ -13,6 +15,10 @@ lint-golangci-lint: @echo "Linting with golangci-lint" @$(SCRIPTS_BASE)/lint-golangci-lint.sh ${skip-non-generated-files} +lint-scripts: + @echo "Linting scripts" + @cd ${ROOT_DIR}/scripts && golangci-lint run ${GOLANG_CI_ARGS} + sync-tidy: @echo "Syncing and tidying dependencies" @$(SCRIPTS_BASE)/sync-tidy.sh @@ -23,7 +29,11 @@ lint: sync-tidy # TEST test-go: @echo "Running Go tests" - @$(SCRIPTS_BASE)/test-go.sh ${skip-non-generated-files} ${skip-scripts} + @$(SCRIPTS_BASE)/test-go.sh ${skip-non-generated-files} + +test-scripts: + @echo "Running Go tests for scripts" + @go test $(ROOT_DIR)/scripts/... ${GOTEST_ARGS} test: - @$(MAKE) --no-print-directory test-go skip-non-generated-files=${skip-non-generated-files} skip-scripts=${skip-scripts} + @$(MAKE) --no-print-directory test-go skip-non-generated-files=${skip-non-generated-files} diff --git a/scripts/lint-golangci-lint.sh b/scripts/lint-golangci-lint.sh index 15a8de611..28cdd476c 100755 --- a/scripts/lint-golangci-lint.sh +++ b/scripts/lint-golangci-lint.sh @@ -11,7 +11,6 @@ fi ROOT_DIR=$(git rev-parse --show-toplevel) CORE_PATH="${ROOT_DIR}/core" -SCRIPTS_PATH="${ROOT_DIR}/scripts" SERVICES_PATH="${ROOT_DIR}/services" EXAMPLES_PATH="${ROOT_DIR}/examples" GOLANG_CI_YAML_PATH="${ROOT_DIR}/golang-ci.yaml" @@ -30,12 +29,6 @@ if [ "${SKIP_NON_GENERATED_FILES}" = false ]; then golangci-lint run ${GOLANG_CI_ARGS} fi -if [ "${SKIP_NON_GENERATED_FILES}" = false ]; then - echo ">> Linting scripts" - cd ${SCRIPTS_PATH} - golangci-lint run ${GOLANG_CI_ARGS} -fi - for service_dir in ${SERVICES_PATH}/*; do service=$(basename ${service_dir}) echo ">> Linting service ${service}" diff --git a/scripts/test-go.sh b/scripts/test-go.sh index 2f91b3785..869dcdbaf 100755 --- a/scripts/test-go.sh +++ b/scripts/test-go.sh @@ -9,15 +9,9 @@ if [ ! "${SKIP_NON_GENERATED_FILES}" = true ]; then SKIP_NON_GENERATED_FILES=false fi -SKIP_SCRIPTS="${2}" -if [ ! "${SKIP_SCRIPTS}" = true ]; then - SKIP_SCRIPTS=false -fi - ROOT_DIR=$(git rev-parse --show-toplevel) GOTEST_ARGS="-timeout=5m -cover -count=1" CORE_PATH="${ROOT_DIR}/core" -SCRIPTS_PATH="${ROOT_DIR}/scripts" SERVICES_PATH="${ROOT_DIR}/services" if type -p go >/dev/null; then @@ -32,11 +26,6 @@ if [ "${SKIP_NON_GENERATED_FILES}" = false ]; then cd ${CORE_PATH} go test ./... ${GOTEST_ARGS} fi -if [ "${SKIP_SCRIPTS}" = false ]; then - echo ">> Testing scripts" - cd ${SCRIPTS_PATH} - go test ./... ${GOTEST_ARGS} -fi for service_dir in ${SERVICES_PATH}/*; do service=$(basename ${service_dir}) From 4e79bd14fdbffb52bfe634abaf5f34d9c77bffee Mon Sep 17 00:00:00 2001 From: vicentepinto98 Date: Thu, 22 Feb 2024 16:51:09 +0000 Subject: [PATCH 10/20] Remove go work sum --- go.work.sum | 2 -- 1 file changed, 2 deletions(-) delete mode 100644 go.work.sum diff --git a/go.work.sum b/go.work.sum deleted file mode 100644 index f2cf57865..000000000 --- a/go.work.sum +++ /dev/null @@ -1,2 +0,0 @@ -golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU= -golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= From 7cd7a292d4fb49bc8c5e24e9054d784fa43b8a60 Mon Sep 17 00:00:00 2001 From: vicentepinto98 Date: Thu, 22 Feb 2024 16:54:09 +0000 Subject: [PATCH 11/20] Updated go.sum --- scripts/go.sum | 3 +++ 1 file changed, 3 insertions(+) diff --git a/scripts/go.sum b/scripts/go.sum index 4b6b0d1bf..e1460086e 100644 --- a/scripts/go.sum +++ b/scripts/go.sum @@ -64,6 +64,7 @@ golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0 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.19.0 h1:ENy+Az/9Y1vSrlrvBSyna3PITt4tiZLf7sgCjZBX7Wo= +golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU= 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.12.0 h1:rmsUpXtvNzj340zd98LZ4KntptpfRHwpFOHG188oHXc= @@ -76,6 +77,7 @@ 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.21.0 h1:AQyQV4dYCvJ7vGmJyKki9+PBdyvhkSd8EIx/qb0AYv4= +golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44= 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= @@ -94,6 +96,7 @@ 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.17.0 h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y= +golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= 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= From 964bd6c7ea0ef0c6c340a3c68a2d8fc1596343a1 Mon Sep 17 00:00:00 2001 From: vicentepinto98 Date: Thu, 22 Feb 2024 17:05:25 +0000 Subject: [PATCH 12/20] Add make commands --- Makefile | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Makefile b/Makefile index d22cbf5fd..67091d12a 100644 --- a/Makefile +++ b/Makefile @@ -37,3 +37,10 @@ test-scripts: test: @$(MAKE) --no-print-directory test-go skip-non-generated-files=${skip-non-generated-files} + +# AUTOMATIC TAG +sdk-tag: + @go run $(SCRIPTS_BASE)/automatic_tag.go ${update-type} ${ssh-private-key-file-path} + +sdk-tag-core: + @go run $(SCRIPTS_BASE)/automatic_tag.go ${update-type} ${ssh-private-key-file-path} --core-only From ea75dfc5d763f4d8d3ca08db9600b5ec8da19b45 Mon Sep 17 00:00:00 2001 From: vicentepinto98 Date: Fri, 23 Feb 2024 09:56:19 +0000 Subject: [PATCH 13/20] Add password argument --- Makefile | 4 ++-- scripts/automatic_tag.go | 16 +++++++++------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/Makefile b/Makefile index 67091d12a..78b0d2b06 100644 --- a/Makefile +++ b/Makefile @@ -40,7 +40,7 @@ test: # AUTOMATIC TAG sdk-tag: - @go run $(SCRIPTS_BASE)/automatic_tag.go ${update-type} ${ssh-private-key-file-path} + @go run $(SCRIPTS_BASE)/automatic_tag.go ${update-type} ${ssh-private-key-file-path} ${password} sdk-tag-core: - @go run $(SCRIPTS_BASE)/automatic_tag.go ${update-type} ${ssh-private-key-file-path} --core-only + @go run $(SCRIPTS_BASE)/automatic_tag.go ${update-type} ${ssh-private-key-file-path} ${password} --core-only diff --git a/scripts/automatic_tag.go b/scripts/automatic_tag.go index 74add2617..6d4cd6ce9 100644 --- a/scripts/automatic_tag.go +++ b/scripts/automatic_tag.go @@ -18,7 +18,7 @@ const ( sdkRepo = "git@github.com:stackitcloud/stackit-sdk-go.git" patch = "patch" minor = "minor" - usage = "go run automatic_tag.go [minor|patch] ssh-private-key-file-path --core-only" + usage = "go run automatic_tag.go [minor|patch] ssh-private-key-file-path password --core-only" ) var ( @@ -27,7 +27,7 @@ var ( func main() { // Parse arguments - if len(os.Args) != 3 && len(os.Args) != 4 { + if len(os.Args) != 4 && len(os.Args) != 5 { fmt.Printf("wrong number of arguments. Usage: %s\n", usage) os.Exit(1) } @@ -52,24 +52,26 @@ func main() { os.Exit(1) } + sshKeyPassword := os.Args[3] + // Parse flag var coreOnly bool - if len(os.Args) == 4 { - if os.Args[3] != "--core-only" { + if len(os.Args) == 5 { + if os.Args[4] != "--core-only" { fmt.Printf("Wrong arguments. Usage: %s\n", usage) os.Exit(1) } coreOnly = true } - err = automaticTagUpdate(updateType, sshPrivateKeyFilePath, coreOnly) + err = automaticTagUpdate(updateType, sshPrivateKeyFilePath, sshKeyPassword, coreOnly) if err != nil { fmt.Printf("Error updating tags: %s\n", err.Error()) os.Exit(1) } } -func automaticTagUpdate(updateType, sshPrivateKeyFilePath string, coreOnly bool) error { +func automaticTagUpdate(updateType, sshPrivateKeyFilePath, password string, coreOnly bool) error { tempDir, err := os.MkdirTemp("", "") if err != nil { return fmt.Errorf("create temporary directory: %w", err) @@ -82,7 +84,7 @@ func automaticTagUpdate(updateType, sshPrivateKeyFilePath string, coreOnly bool) } }() - publicKeys, err := ssh.NewPublicKeysFromFile("git", sshPrivateKeyFilePath, "") + publicKeys, err := ssh.NewPublicKeysFromFile("git", sshPrivateKeyFilePath, password) if err != nil { return fmt.Errorf("get public keys from private key file: %w", err) } From f183f788f00c32873c78e290f794869b4b857c25 Mon Sep 17 00:00:00 2001 From: vicentepinto98 Date: Fri, 23 Feb 2024 09:59:12 +0000 Subject: [PATCH 14/20] Sanity check --- scripts/automatic_tag.go | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/scripts/automatic_tag.go b/scripts/automatic_tag.go index 6d4cd6ce9..709fd6721 100644 --- a/scripts/automatic_tag.go +++ b/scripts/automatic_tag.go @@ -15,14 +15,15 @@ import ( ) const ( - sdkRepo = "git@github.com:stackitcloud/stackit-sdk-go.git" - patch = "patch" - minor = "minor" - usage = "go run automatic_tag.go [minor|patch] ssh-private-key-file-path password --core-only" + sdkRepo = "git@github.com:stackitcloud/stackit-sdk-go.git" + patch = "patch" + minor = "minor" + coreOnlyFlag = "--core-only" ) var ( updateTypes = []string{minor, patch} + usage = fmt.Sprintf("go run automatic_tag.go [minor|patch] ssh-private-key-file-path password %s", coreOnlyFlag) ) func main() { @@ -53,11 +54,15 @@ func main() { } sshKeyPassword := os.Args[3] + if sshKeyPassword == coreOnlyFlag { + fmt.Printf("Wrong arguments. Usage: %s\n", usage) + os.Exit(1) + } // Parse flag var coreOnly bool if len(os.Args) == 5 { - if os.Args[4] != "--core-only" { + if os.Args[4] != coreOnlyFlag { fmt.Printf("Wrong arguments. Usage: %s\n", usage) os.Exit(1) } @@ -201,7 +206,7 @@ func computeUpdatedTag(service, version, updateType string, coreOnly bool) (stri updatedVersion := strings.Join(splitVersion, ".") if coreOnly { if service != "core" { - return "", fmt.Errorf("--core-only was provided but store latest tag from another service: %s", service) + return "", fmt.Errorf("%s was provided but store latest tag from another service: %s", coreOnlyFlag, service) } return fmt.Sprintf("core/%s", updatedVersion), nil } From e73749060e032ce6d88848d7ed9614c18564d49c Mon Sep 17 00:00:00 2001 From: vicentepinto98 Date: Fri, 23 Feb 2024 15:33:40 +0000 Subject: [PATCH 15/20] Changes after review --- Makefile | 16 +++- scripts/automatic_tag.go | 134 ++++++++++++++++++++-------------- scripts/automatic_tag_test.go | 90 +++++++++++++++-------- 3 files changed, 155 insertions(+), 85 deletions(-) diff --git a/Makefile b/Makefile index 78b0d2b06..db8f45bc0 100644 --- a/Makefile +++ b/Makefile @@ -39,8 +39,18 @@ test: @$(MAKE) --no-print-directory test-go skip-non-generated-files=${skip-non-generated-files} # AUTOMATIC TAG -sdk-tag: - @go run $(SCRIPTS_BASE)/automatic_tag.go ${update-type} ${ssh-private-key-file-path} ${password} +sdk-tag-services: + @if [ "${password}" = "" ]; then \ + go run $(SCRIPTS_BASE)/automatic_tag.go --update-type ${update-type} --ssh-private-key-file-path ${ssh-private-key-file-path}; \ + else \ + go run $(SCRIPTS_BASE)/automatic_tag.go --update-type ${update-type} --ssh-private-key-file-path ${ssh-private-key-file-path} --password ${password}; \ + fi + sdk-tag-core: - @go run $(SCRIPTS_BASE)/automatic_tag.go ${update-type} ${ssh-private-key-file-path} ${password} --core-only + @if [ "${password}" = "" ]; then \ + go run $(SCRIPTS_BASE)/automatic_tag.go --update-type ${update-type} --ssh-private-key-file-path ${ssh-private-key-file-path} --target core; \ + else \ + go run $(SCRIPTS_BASE)/automatic_tag.go --update-type ${update-type} --ssh-private-key-file-path ${ssh-private-key-file-path} --target core --password ${password}; \ + fi + diff --git a/scripts/automatic_tag.go b/scripts/automatic_tag.go index 709fd6721..2e3e18db2 100644 --- a/scripts/automatic_tag.go +++ b/scripts/automatic_tag.go @@ -2,6 +2,7 @@ package main import ( "errors" + "flag" "fmt" "os" "strconv" @@ -15,68 +16,80 @@ import ( ) const ( - sdkRepo = "git@github.com:stackitcloud/stackit-sdk-go.git" - patch = "patch" - minor = "minor" - coreOnlyFlag = "--core-only" + sdkRepo = "git@github.com:vicentepinto98/gh.git" + patch = "patch" + minor = "minor" + allServices = "all-services" + core = "core" + + updateTypeFlag = "update-type" + sshPrivateKeyFilePathFlag = "ssh-private-key-file-path" + passwordFlag = "password" + targetFlag = "target" ) var ( updateTypes = []string{minor, patch} - usage = fmt.Sprintf("go run automatic_tag.go [minor|patch] ssh-private-key-file-path password %s", coreOnlyFlag) + targets = []string{allServices, core} + usage = "go run automatic_tag.go --update-type [minor|patch] --ssh-private-key-file-path path/to/private-key --password password --target [all-services|core]" ) func main() { - // Parse arguments - if len(os.Args) != 4 && len(os.Args) != 5 { - fmt.Printf("wrong number of arguments. Usage: %s\n", usage) + if err := run(); err != nil { + fmt.Fprintf(os.Stderr, "Error: %s\n", err) os.Exit(1) } +} + +func run() error { + var updateType string + var sshPrivateKeyFilePath string + var password string + var target string + + flag.StringVar(&updateType, updateTypeFlag, "", fmt.Sprintf("Update type, must be one of: %s (required)", strings.Join(updateTypes, ","))) + flag.StringVar(&sshPrivateKeyFilePath, sshPrivateKeyFilePathFlag, "", "Path to the ssh private key (required)") + flag.StringVar(&password, passwordFlag, "", "Password of the ssh private key (optional)") + flag.StringVar(&target, targetFlag, allServices, fmt.Sprintf("Create tags for this target, must be one of %s (optional, default is %s)", strings.Join(targets, ","), allServices)) - updateType := os.Args[1] - valid := false + flag.Parse() + + validUpdateType := false for _, t := range updateTypes { if updateType == t { - valid = true + validUpdateType = true break } } - if !valid { - fmt.Printf("the provided argument for update type `%s` is not valid, the valid values are: [%s]\n", updateType, strings.Join(updateTypes, ",")) - os.Exit(1) + if !validUpdateType { + return fmt.Errorf("the provided update type `%s` is not valid, the valid values are: [%s]", updateType, strings.Join(updateTypes, ",")) } - sshPrivateKeyFilePath := os.Args[2] - _, err := os.Stat(sshPrivateKeyFilePath) - if err != nil { - fmt.Printf("The provided private key file path %s is not valid: %s\nUsage: %s\n", sshPrivateKeyFilePath, err, usage) - os.Exit(1) + validTarget := false + for _, t := range targets { + if target == t { + validTarget = true + break + } } - - sshKeyPassword := os.Args[3] - if sshKeyPassword == coreOnlyFlag { - fmt.Printf("Wrong arguments. Usage: %s\n", usage) - os.Exit(1) + if !validTarget { + return fmt.Errorf("the provided target `%s` is not valid, the valid values are: [%s]", target, strings.Join(targets, ",")) } - // Parse flag - var coreOnly bool - if len(os.Args) == 5 { - if os.Args[4] != coreOnlyFlag { - fmt.Printf("Wrong arguments. Usage: %s\n", usage) - os.Exit(1) - } - coreOnly = true + _, err := os.Stat(sshPrivateKeyFilePath) + if err != nil { + return fmt.Errorf("the provided private key file path %s is not valid: %s\nUsage: %s", sshPrivateKeyFilePath, err, usage) } - err = automaticTagUpdate(updateType, sshPrivateKeyFilePath, sshKeyPassword, coreOnly) + err = automaticTagUpdate(updateType, sshPrivateKeyFilePath, password, target) if err != nil { - fmt.Printf("Error updating tags: %s\n", err.Error()) - os.Exit(1) + return fmt.Errorf("updating tags: %s", err.Error()) } + return nil } -func automaticTagUpdate(updateType, sshPrivateKeyFilePath, password string, coreOnly bool) error { +// automaticTagUpdate goes through all of the exising tags, gets the latest for the targer, creates a new one according to the updateType and pushes them +func automaticTagUpdate(updateType, sshPrivateKeyFilePath, password, target string) error { tempDir, err := os.MkdirTemp("", "") if err != nil { return fmt.Errorf("create temporary directory: %w", err) @@ -84,8 +97,8 @@ func automaticTagUpdate(updateType, sshPrivateKeyFilePath, password string, core defer func() { tempErr := os.RemoveAll(tempDir) - if tempErr != nil && err == nil { - err = fmt.Errorf("temporary directory %s could not be removed: %w", tempDir, tempErr) + if tempErr != nil { + fmt.Printf("Warning: temporary directory %s could not be removed: %s", tempDir, tempErr.Error()) } }() @@ -110,7 +123,10 @@ func automaticTagUpdate(updateType, sshPrivateKeyFilePath, password string, core latestTags := map[string]string{} err = tagrefs.ForEach(func(t *plumbing.Reference) error { - latestTags = storeLatestTag(t, latestTags, coreOnly) + latestTags, err = storeLatestTag(t, latestTags, target) + if err != nil { + return fmt.Errorf("store latest tag: %w", err) + } return nil }) if err != nil { @@ -118,7 +134,7 @@ func automaticTagUpdate(updateType, sshPrivateKeyFilePath, password string, core } for service, version := range latestTags { - newTag, err := computeUpdatedTag(service, version, updateType, coreOnly) + newTag, err := computeUpdatedTag(service, version, updateType, target) if err != nil { fmt.Printf("Error for %s with version %s, this tag will be skipped. Error: %s\n", service, version, err.Error()) continue @@ -139,44 +155,52 @@ func automaticTagUpdate(updateType, sshPrivateKeyFilePath, password string, core return nil } -func storeLatestTag(t *plumbing.Reference, latestTags map[string]string, coreOnly bool) map[string]string { +// storeLatestTag receives a tag in the form of a plumbing.Reference and a map with the latest tag per service +// It checks if the tag is part of the current target (if it is belonging to a service or to core), +// checks if it is newer than the current latest tag stored in the map and if it is, updates latestTags and returns it +func storeLatestTag(t *plumbing.Reference, latestTags map[string]string, target string) (map[string]string, error) { tagName, _ := strings.CutPrefix(t.Name().String(), "refs/tags/") splitTag := strings.Split(tagName, "/") - if coreOnly { + switch target { + case core: if len(splitTag) != 2 || splitTag[0] != "core" { - return latestTags + return latestTags, nil } version := splitTag[1] if semver.Prerelease(version) != "" { - return latestTags + return latestTags, nil } // invalid (or empty) semantic version are considered less than a valid one if semver.Compare(latestTags["core"], version) == -1 { latestTags["core"] = version } - } else { + case allServices: if len(splitTag) != 3 || splitTag[0] != "services" { - return latestTags + return latestTags, nil } service := splitTag[1] version := splitTag[2] if semver.Prerelease(version) != "" { - return latestTags + return latestTags, nil } // invalid (or empty) semantic version are considered less than a valid one if semver.Compare(latestTags[service], version) == -1 { latestTags[service] = version } + default: + return nil, fmt.Errorf("target not supported in storeLatestTag, fix the script") } - return latestTags + return latestTags, nil } -func computeUpdatedTag(service, version, updateType string, coreOnly bool) (string, error) { +// computeUpdatedTag returns the a new tag with the updated version for a specific service according to the update type and target +// example: for service argus with version v0.1.1, target all-services and updateType minor, it returns services/argus/v0.2.0 +func computeUpdatedTag(service, version, updateType, target string) (string, error) { canonicalVersion := semver.Canonical(version) splitVersion := strings.Split(canonicalVersion, ".") if len(splitVersion) != 3 { @@ -204,14 +228,18 @@ func computeUpdatedTag(service, version, updateType string, coreOnly bool) (stri } updatedVersion := strings.Join(splitVersion, ".") - if coreOnly { + + switch target { + case core: if service != "core" { - return "", fmt.Errorf("%s was provided but store latest tag from another service: %s", coreOnlyFlag, service) + return "", fmt.Errorf("%s target was provided but store latest tag from another service: %s", target, service) } return fmt.Sprintf("core/%s", updatedVersion), nil + case allServices: + return fmt.Sprintf("services/%s/%s", service, updatedVersion), nil + default: + return "", fmt.Errorf("target not supported in version increment, fix the script") } - - return fmt.Sprintf("services/%s/%s", service, updatedVersion), nil } func createTag(r *git.Repository, tag string) error { diff --git a/scripts/automatic_tag_test.go b/scripts/automatic_tag_test.go index d4c064c5c..8d0bcf4ea 100644 --- a/scripts/automatic_tag_test.go +++ b/scripts/automatic_tag_test.go @@ -12,8 +12,9 @@ func TestStoreLatestTag(t *testing.T) { desc string tag *plumbing.Reference latestTags map[string]string - coreOnly bool + target string expectedLatestTags map[string]string + isValid bool }{ { desc: "valid service latest version", @@ -22,11 +23,12 @@ func TestStoreLatestTag(t *testing.T) { "foo": "v0.1.0", "bar": "v0.1.0", }, - coreOnly: false, + target: "all-services", expectedLatestTags: map[string]string{ "foo": "v0.2.0", "bar": "v0.1.0", }, + isValid: true, }, { desc: "valid service no update", @@ -35,11 +37,12 @@ func TestStoreLatestTag(t *testing.T) { "foo": "v0.1.0", "bar": "v0.1.0", }, - coreOnly: false, + target: "all-services", expectedLatestTags: map[string]string{ "foo": "v0.1.0", "bar": "v0.1.0", }, + isValid: true, }, { desc: "valid core latest version", @@ -49,27 +52,13 @@ func TestStoreLatestTag(t *testing.T) { "bar": "v0.1.0", "core": "v0.1.0", }, - coreOnly: true, - expectedLatestTags: map[string]string{ - "foo": "v0.1.0", - "bar": "v0.1.0", - "core": "v0.2.0", - }, - }, - { - desc: "valid core latest version", - tag: plumbing.NewReferenceFromStrings("refs/tags/core/v0.2.0", ""), - latestTags: map[string]string{ - "foo": "v0.1.0", - "bar": "v0.1.0", - "core": "v0.1.0", - }, - coreOnly: true, + target: "core", expectedLatestTags: map[string]string{ "foo": "v0.1.0", "bar": "v0.1.0", "core": "v0.2.0", }, + isValid: true, }, { desc: "invalid service tag", @@ -78,11 +67,12 @@ func TestStoreLatestTag(t *testing.T) { "foo": "v0.1.0", "bar": "v0.1.0", }, - coreOnly: false, + target: "all-services", expectedLatestTags: map[string]string{ "foo": "v0.1.0", "bar": "v0.1.0", }, + isValid: true, }, { desc: "valid service tag but coreOnly", @@ -91,11 +81,12 @@ func TestStoreLatestTag(t *testing.T) { "foo": "v0.1.0", "bar": "v0.1.0", }, - coreOnly: true, + target: "core", expectedLatestTags: map[string]string{ "foo": "v0.1.0", "bar": "v0.1.0", }, + isValid: true, }, { desc: "dont update to pre-release", @@ -104,16 +95,37 @@ func TestStoreLatestTag(t *testing.T) { "foo": "v0.1.0", "bar": "v0.1.0", }, - coreOnly: true, + target: "core", expectedLatestTags: map[string]string{ "foo": "v0.1.0", "bar": "v0.1.0", }, + isValid: true, + }, + { + desc: "unsupported target", + tag: plumbing.NewReferenceFromStrings("refs/tags/services/foo/v0.2.0", ""), + latestTags: map[string]string{ + "foo": "v0.1.0", + "bar": "v0.1.0", + }, + target: "unsupported", + expectedLatestTags: map[string]string{}, + isValid: false, }, } { t.Run(test.desc, func(t *testing.T) { - updatedLatestTags := storeLatestTag(test.tag, test.latestTags, test.coreOnly) - if !reflect.DeepEqual(test.expectedLatestTags, updatedLatestTags) { + updatedLatestTags, err := storeLatestTag(test.tag, test.latestTags, test.target) + + if err != nil && test.isValid { + t.Fatalf("Test returned error on valid test case: %v", err) + } + + if err == nil && !test.isValid { + t.Fatalf("Test didn't return error on invalid test case") + } + + if test.isValid && !reflect.DeepEqual(test.expectedLatestTags, updatedLatestTags) { t.Fatalf("Updated tags are wrong, expected %v, got %v", test.expectedLatestTags, updatedLatestTags) } }) @@ -126,7 +138,7 @@ func TestComputeUpdatedTag(t *testing.T) { service string version string updateType string - coreOnly bool + target string expectedTag string isValid bool }{ @@ -135,6 +147,16 @@ func TestComputeUpdatedTag(t *testing.T) { service: "foo", version: "v0.1.0", updateType: "minor", + target: "all-services", + expectedTag: "services/foo/v0.2.0", + isValid: true, + }, + { + desc: "valid service minor update with previous patch version not zero", + service: "foo", + version: "v0.1.1", + updateType: "minor", + target: "all-services", expectedTag: "services/foo/v0.2.0", isValid: true, }, @@ -143,6 +165,7 @@ func TestComputeUpdatedTag(t *testing.T) { service: "foo", version: "v0.1.0", updateType: "patch", + target: "all-services", expectedTag: "services/foo/v0.1.1", isValid: true, }, @@ -151,7 +174,7 @@ func TestComputeUpdatedTag(t *testing.T) { service: "core", version: "v0.1.0", updateType: "minor", - coreOnly: true, + target: "core", expectedTag: "core/v0.2.0", isValid: true, }, @@ -160,7 +183,7 @@ func TestComputeUpdatedTag(t *testing.T) { service: "core", version: "v0.1.0", updateType: "patch", - coreOnly: true, + target: "core", expectedTag: "core/v0.1.1", isValid: true, }, @@ -169,6 +192,7 @@ func TestComputeUpdatedTag(t *testing.T) { service: "foo", version: "v0.1.0", updateType: "major", + target: "all-services", isValid: false, }, { @@ -176,12 +200,20 @@ func TestComputeUpdatedTag(t *testing.T) { service: "foo", version: "v0.1.0", updateType: "patch", - coreOnly: true, + target: "core", + isValid: false, + }, + { + desc: "unsupported target - this should never happen", + service: "foo", + version: "v0.1.0", + updateType: "patch", + target: "unsupported", isValid: false, }, } { t.Run(test.desc, func(t *testing.T) { - updatedTag, err := computeUpdatedTag(test.service, test.version, test.updateType, test.coreOnly) + updatedTag, err := computeUpdatedTag(test.service, test.version, test.updateType, test.target) if err != nil && test.isValid { t.Fatalf("Test returned error on valid test case: %v", err) From 3164cbb106c4c40daf1e520bd680128d1f581560 Mon Sep 17 00:00:00 2001 From: vicentepinto98 Date: Fri, 23 Feb 2024 15:36:47 +0000 Subject: [PATCH 16/20] Fix lint --- scripts/automatic_tag.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/automatic_tag.go b/scripts/automatic_tag.go index 2e3e18db2..e580f5cd3 100644 --- a/scripts/automatic_tag.go +++ b/scripts/automatic_tag.go @@ -78,7 +78,7 @@ func run() error { _, err := os.Stat(sshPrivateKeyFilePath) if err != nil { - return fmt.Errorf("the provided private key file path %s is not valid: %s\nUsage: %s", sshPrivateKeyFilePath, err, usage) + return fmt.Errorf("the provided private key file path %s is not valid: %w\nUsage: %s", sshPrivateKeyFilePath, err, usage) } err = automaticTagUpdate(updateType, sshPrivateKeyFilePath, password, target) @@ -88,7 +88,7 @@ func run() error { return nil } -// automaticTagUpdate goes through all of the exising tags, gets the latest for the targer, creates a new one according to the updateType and pushes them +// automaticTagUpdate goes through all of the existing tags, gets the latest for the targer, creates a new one according to the updateType and pushes them func automaticTagUpdate(updateType, sshPrivateKeyFilePath, password, target string) error { tempDir, err := os.MkdirTemp("", "") if err != nil { From 75dc886bce5114e9745a15a19d415a14210207b0 Mon Sep 17 00:00:00 2001 From: vicentepinto98 Date: Fri, 23 Feb 2024 15:39:35 +0000 Subject: [PATCH 17/20] Replace url --- scripts/automatic_tag.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/automatic_tag.go b/scripts/automatic_tag.go index e580f5cd3..b6f03247c 100644 --- a/scripts/automatic_tag.go +++ b/scripts/automatic_tag.go @@ -16,7 +16,7 @@ import ( ) const ( - sdkRepo = "git@github.com:vicentepinto98/gh.git" + sdkRepo = "git@github.com:stackitcloud/stackit-sdk-go.git" patch = "patch" minor = "minor" allServices = "all-services" From 6e3992819ce070b79d57d1847f41b3c4c7f01e39 Mon Sep 17 00:00:00 2001 From: vicentepinto98 Date: Fri, 23 Feb 2024 15:46:02 +0000 Subject: [PATCH 18/20] Remove leftover condition --- .github/workflows/ci.yaml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index b90d03ba2..0fbacb340 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -30,9 +30,7 @@ jobs: run: | make lint-scripts - name: Test - if: ${{ matrix.go-version != '1.18' }} - run: | - make test + run: make test - name: Test scripts if: ${{ matrix.go-version == '1.21' }} run: | From 28f70044726b15da93e6290b769574ac72b08175 Mon Sep 17 00:00:00 2001 From: Vicente Pinto Date: Mon, 26 Feb 2024 08:59:44 +0000 Subject: [PATCH 19/20] Update scripts/automatic_tag.go MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: João Palet --- scripts/automatic_tag.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/automatic_tag.go b/scripts/automatic_tag.go index b6f03247c..5628433e7 100644 --- a/scripts/automatic_tag.go +++ b/scripts/automatic_tag.go @@ -88,7 +88,7 @@ func run() error { return nil } -// automaticTagUpdate goes through all of the existing tags, gets the latest for the targer, creates a new one according to the updateType and pushes them +// automaticTagUpdate goes through all of the existing tags, gets the latest for the target, creates a new one according to the updateType and pushes them func automaticTagUpdate(updateType, sshPrivateKeyFilePath, password, target string) error { tempDir, err := os.MkdirTemp("", "") if err != nil { From 750cc470c9fe2363410abd66393ca7da6d3ddade Mon Sep 17 00:00:00 2001 From: vicentepinto98 Date: Mon, 26 Feb 2024 09:17:00 +0000 Subject: [PATCH 20/20] Moved logic out of computeLatestVersion --- scripts/automatic_tag.go | 39 ++++++++------- scripts/automatic_tag_test.go | 92 +++++++++-------------------------- 2 files changed, 45 insertions(+), 86 deletions(-) diff --git a/scripts/automatic_tag.go b/scripts/automatic_tag.go index 5628433e7..47e844129 100644 --- a/scripts/automatic_tag.go +++ b/scripts/automatic_tag.go @@ -133,10 +133,24 @@ func automaticTagUpdate(updateType, sshPrivateKeyFilePath, password, target stri return fmt.Errorf("iterate over existing tags: %w", err) } - for service, version := range latestTags { - newTag, err := computeUpdatedTag(service, version, updateType, target) + for module, version := range latestTags { + updatedVersion, err := computeUpdatedVersion(version, updateType) if err != nil { - fmt.Printf("Error for %s with version %s, this tag will be skipped. Error: %s\n", service, version, err.Error()) + fmt.Printf("Error computing updated version for %s with version %s, this tag will be skipped: %s\n", module, version, err.Error()) + continue + } + + var newTag string + switch target { + case core: + if module != "core" { + return fmt.Errorf("%s target was provided but there is a stored latest tag from another service: %s", target, module) + } + newTag = fmt.Sprintf("core/%s", updatedVersion) + case allServices: + newTag = fmt.Sprintf("services/%s/%s", module, updatedVersion) + default: + fmt.Printf("Error computing updated version for %s with version %s, this tag will be skipped: target %s not supported in version increment, fix the script\n", module, version, target) continue } @@ -198,9 +212,9 @@ func storeLatestTag(t *plumbing.Reference, latestTags map[string]string, target return latestTags, nil } -// computeUpdatedTag returns the a new tag with the updated version for a specific service according to the update type and target -// example: for service argus with version v0.1.1, target all-services and updateType minor, it returns services/argus/v0.2.0 -func computeUpdatedTag(service, version, updateType, target string) (string, error) { +// computeUpdatedVersion returns the updated version according to the update type +// example: for version v0.1.1 and updateType minor, it returns v0.2.0 +func computeUpdatedVersion(version, updateType string) (string, error) { canonicalVersion := semver.Canonical(version) splitVersion := strings.Split(canonicalVersion, ".") if len(splitVersion) != 3 { @@ -228,18 +242,7 @@ func computeUpdatedTag(service, version, updateType, target string) (string, err } updatedVersion := strings.Join(splitVersion, ".") - - switch target { - case core: - if service != "core" { - return "", fmt.Errorf("%s target was provided but store latest tag from another service: %s", target, service) - } - return fmt.Sprintf("core/%s", updatedVersion), nil - case allServices: - return fmt.Sprintf("services/%s/%s", service, updatedVersion), nil - default: - return "", fmt.Errorf("target not supported in version increment, fix the script") - } + return updatedVersion, nil } func createTag(r *git.Repository, tag string) error { diff --git a/scripts/automatic_tag_test.go b/scripts/automatic_tag_test.go index 8d0bcf4ea..b876db06f 100644 --- a/scripts/automatic_tag_test.go +++ b/scripts/automatic_tag_test.go @@ -132,88 +132,44 @@ func TestStoreLatestTag(t *testing.T) { } } -func TestComputeUpdatedTag(t *testing.T) { +func TestComputeUpdatedVersion(t *testing.T) { for _, test := range []struct { - desc string - service string - version string - updateType string - target string - expectedTag string - isValid bool + desc string + version string + updateType string + expectedVersion string + isValid bool }{ { - desc: "valid service minor update", - service: "foo", - version: "v0.1.0", - updateType: "minor", - target: "all-services", - expectedTag: "services/foo/v0.2.0", - isValid: true, + desc: "valid minor update", + version: "v0.1.0", + updateType: "minor", + expectedVersion: "v0.2.0", + isValid: true, }, { - desc: "valid service minor update with previous patch version not zero", - service: "foo", - version: "v0.1.1", - updateType: "minor", - target: "all-services", - expectedTag: "services/foo/v0.2.0", - isValid: true, + desc: "valid minor update with previous patch version not zero", + version: "v0.1.1", + updateType: "minor", + expectedVersion: "v0.2.0", + isValid: true, }, { - desc: "valid service patch update", - service: "foo", - version: "v0.1.0", - updateType: "patch", - target: "all-services", - expectedTag: "services/foo/v0.1.1", - isValid: true, - }, - { - desc: "valid core minor update", - service: "core", - version: "v0.1.0", - updateType: "minor", - target: "core", - expectedTag: "core/v0.2.0", - isValid: true, - }, - { - desc: "valid core patch update", - service: "core", - version: "v0.1.0", - updateType: "patch", - target: "core", - expectedTag: "core/v0.1.1", - isValid: true, + desc: "valid patch update", + version: "v0.1.0", + updateType: "patch", + expectedVersion: "v0.1.1", + isValid: true, }, { desc: "invalid update type", - service: "foo", version: "v0.1.0", updateType: "major", - target: "all-services", - isValid: false, - }, - { - desc: "invalid core update with wrong name - this should never happen", - service: "foo", - version: "v0.1.0", - updateType: "patch", - target: "core", - isValid: false, - }, - { - desc: "unsupported target - this should never happen", - service: "foo", - version: "v0.1.0", - updateType: "patch", - target: "unsupported", isValid: false, }, } { t.Run(test.desc, func(t *testing.T) { - updatedTag, err := computeUpdatedTag(test.service, test.version, test.updateType, test.target) + updatedVersion, err := computeUpdatedVersion(test.version, test.updateType) if err != nil && test.isValid { t.Fatalf("Test returned error on valid test case: %v", err) @@ -223,8 +179,8 @@ func TestComputeUpdatedTag(t *testing.T) { t.Fatalf("Test didn't return error on invalid test case") } - if test.isValid && test.expectedTag != updatedTag { - t.Fatalf("updated tag is wrong: expected %s, got %s", test.expectedTag, updatedTag) + if test.isValid && test.expectedVersion != updatedVersion { + t.Fatalf("updated tag is wrong: expected %s, got %s", test.expectedVersion, updatedVersion) } }) }