Skip to content

Commit e5e10ea

Browse files
author
Tanmay Sardesai
authored
Merge pull request #169 from Clever/INFRANG-7064
Infrang 7064
2 parents 159009e + f7a5977 commit e5e10ea

File tree

8 files changed

+134
-38
lines changed

8 files changed

+134
-38
lines changed

VERSION

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
v1.0.8
2-
updated goci to catch errors for no go.mod file
1+
v1.1.0
2+
goci can now publish utilities to the catalog
33

44
Previously:
5+
- updated goci to catch errors for no go.mod file
56
- bugfix: dont lazy load the oidc token
67
- Updating goci warning message, including recent version release date
78
- Supporting lazy loading of environment variables

cmd/goci/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ goci accepts very limited arguments which merely change the mode it runs in. The
1111
1. `goci detect` detects any changed applications according to their launch configuration. This can be used to pass a name of apps to another script.
1212
2. `goci artifact-build-publish-deploy` builds, publishes and deploys any application artifacts.
1313
3. `goci validate` validates an applications go version, while also checking for compatible branch naming conventions for catapult.
14+
4. `goci publish-utility` publishes catalog-info.yaml to the service catalog.
1415

1516

1617
## Multi-app Support

cmd/goci/main.go

Lines changed: 55 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,16 @@ import (
1414
"golang.org/x/mod/modfile"
1515

1616
"github.com/Clever/catapult/gen-go/models"
17+
"github.com/Clever/ci-scripts/internal/backstage"
1718
"github.com/Clever/ci-scripts/internal/catapult"
1819
"github.com/Clever/ci-scripts/internal/docker"
1920
"github.com/Clever/ci-scripts/internal/environment"
2021
"github.com/Clever/ci-scripts/internal/lambda"
2122
"github.com/Clever/ci-scripts/internal/repo"
23+
ciIntegrationsModels "github.com/Clever/circle-ci-integrations/gen-go/models"
2224
)
2325

24-
const usage = "usage: goci <validate|detect|artifact-build-publish-deploy>"
26+
const usage = "usage: goci <validate|detect|artifact-build-publish-deploy|publish-utility>"
2527

2628
// This app assumes the code has been checked out and that the
2729
// repository is the working directory.
@@ -53,17 +55,25 @@ func main() {
5355
}
5456

5557
func run(mode string) error {
56-
apps, err := repo.DiscoverApplications("./launch")
57-
if err != nil {
58-
return err
59-
}
58+
var apps map[string]*models.LaunchConfig
59+
var appIDs []string
60+
var err error
6061

61-
appIDs := []string{}
62-
for app := range apps {
63-
appIDs = append(appIDs, app)
62+
// Only discover applications for specific modes
63+
if mode == "validate" || mode == "detect" || mode == "artifact-build-publish-deploy" {
64+
apps, err = repo.DiscoverApplications("./launch")
65+
if err != nil {
66+
return err
67+
}
68+
appIDs = []string{}
69+
for app := range apps {
70+
appIDs = append(appIDs, app)
71+
}
6472
}
6573

6674
switch mode {
75+
case "publish-utility":
76+
return publishUtility()
6777
case "validate":
6878
err := validateRun()
6979
if err != nil {
@@ -261,3 +271,40 @@ func allAppsBuilt(discoveredApps map[string]*models.LaunchConfig, builtApps []*c
261271
}
262272
return fmt.Errorf("applications %s not built", strings.Join(missing, ", "))
263273
}
274+
275+
func publishUtility() error {
276+
validateRun()
277+
catalogInfoPath := "./catalog-info.yaml"
278+
if _, err := os.Stat(catalogInfoPath); os.IsNotExist(err) {
279+
return fmt.Errorf("catalog-info.yaml file not found in the current directory")
280+
}
281+
catalogInfo, err := backstage.GetEntityFromYaml(catalogInfoPath)
282+
if err != nil {
283+
return fmt.Errorf("failed to read catalog-info.yaml file: %v", err)
284+
}
285+
286+
// Check to see if type is defined on Spec
287+
if catalogInfo.Spec == nil {
288+
return fmt.Errorf("catalog-info.yaml file does not contain a valid spec")
289+
}
290+
if _, ok := catalogInfo.Spec["type"]; !ok {
291+
return fmt.Errorf("catalog-info.yaml file does not contain a valid type in spec")
292+
}
293+
typeVal, ok := catalogInfo.Spec["type"].(string)
294+
if !ok {
295+
return fmt.Errorf("catalog-info.yaml file does not contain a valid type in spec")
296+
}
297+
298+
cp := catapult.New()
299+
300+
err = cp.SyncCatalogEntity(context.Background(), &ciIntegrationsModels.SyncCatalogEntityInput{
301+
Entity: catalogInfo.GetName(),
302+
Type: typeVal,
303+
})
304+
if err != nil {
305+
return fmt.Errorf("failed to sync catalog entity with catapult: %v", err)
306+
}
307+
fmt.Printf("Successfully synced catalog entity %s \n", catalogInfo.GetName())
308+
return nil
309+
310+
}

go.mod

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
module github.com/Clever/ci-scripts
22

3-
go 1.24
3+
go 1.24.0
44

55
require (
66
github.com/Clever/catapult/gen-go/models v1.203.1
7-
github.com/Clever/circle-ci-integrations/gen-go/client v0.0.0-20230317164210-4d554db10fa0
8-
github.com/Clever/circle-ci-integrations/gen-go/models v0.0.0-20230317164210-4d554db10fa0
7+
github.com/Clever/circle-ci-integrations/gen-go/client v0.0.0-20250515140338-c4907a8ff0c0
8+
github.com/Clever/circle-ci-integrations/gen-go/models v0.0.0-20250515140338-c4907a8ff0c0
99
github.com/Clever/wag/logging/wagclientlogger v0.0.0-20230227191614-7aa97ba44ab1
1010
github.com/aws/aws-sdk-go-v2 v1.17.7
1111
github.com/aws/aws-sdk-go-v2/config v1.15.5
@@ -23,7 +23,6 @@ require (
2323
require (
2424
github.com/Clever/discovery-go v1.8.1 // indirect
2525
github.com/Microsoft/go-winio v0.6.1 // indirect
26-
github.com/afex/hystrix-go v0.0.0-20180502004556-fa1af6a1f4f5 // indirect
2726
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 // indirect
2827
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.4.10 // indirect
2928
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.12.4 // indirect
@@ -41,7 +40,6 @@ require (
4140
github.com/docker/distribution v2.8.1+incompatible // indirect
4241
github.com/docker/go-connections v0.4.0 // indirect
4342
github.com/docker/go-units v0.5.0 // indirect
44-
github.com/donovanhide/eventsource v0.0.0-20210830082556-c59027999da0 // indirect
4543
github.com/go-openapi/analysis v0.21.4 // indirect
4644
github.com/go-openapi/errors v0.20.3 // indirect
4745
github.com/go-openapi/jsonpointer v0.19.6 // indirect

go.sum

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,12 @@ github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1/go.mod h1:xomTg6
33
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
44
github.com/Clever/catapult/gen-go/models v1.203.1 h1:AzyUZ16aqvJPgCCz/lfgQWaUvo6ZEPzxnq55TtECS7Y=
55
github.com/Clever/catapult/gen-go/models v1.203.1/go.mod h1:KycooNSZj8fMqRjzFimkzDkcllvrVQ4v30EdZRfS0tU=
6-
github.com/Clever/circle-ci-integrations/gen-go/client v0.0.0-20230317164210-4d554db10fa0 h1:QlgvxlCkH2wvVBPEBCTzVFnFZTlXfkqu0Q+GFaXoBWo=
7-
github.com/Clever/circle-ci-integrations/gen-go/client v0.0.0-20230317164210-4d554db10fa0/go.mod h1:b6cswTCs4/PCtMyAUrOS7iEtUvhAzmFrbvYfdxZ7vHQ=
8-
github.com/Clever/circle-ci-integrations/gen-go/models v0.0.0-20230317164210-4d554db10fa0 h1:J+Nimwh3a/uPETcJprzZ9PFzDVidm1rfSc4XbZQdbNc=
9-
github.com/Clever/circle-ci-integrations/gen-go/models v0.0.0-20230317164210-4d554db10fa0/go.mod h1:h/pDE4qjxOPzM4yUoBu34G6QQoMBdTrCew2ijM3xwzM=
6+
github.com/Clever/circle-ci-integrations/gen-go/client v0.0.0-20250515140338-c4907a8ff0c0 h1:hFKnyXa1O9DdMA270JK+8QLtEljl4p1VxMh3qHFmN6s=
7+
github.com/Clever/circle-ci-integrations/gen-go/client v0.0.0-20250515140338-c4907a8ff0c0/go.mod h1:zfaHIz55lTkvsMS9jIL11l9szB8ThG0RenysMz35/e4=
8+
github.com/Clever/circle-ci-integrations/gen-go/models v0.0.0-20250515140338-c4907a8ff0c0 h1:8Dz3nDusLZlF2Te4FdmLO2/J9WJ1rdCsd+7BuE/UCjw=
9+
github.com/Clever/circle-ci-integrations/gen-go/models v0.0.0-20250515140338-c4907a8ff0c0/go.mod h1:mHbAHSsROUodDWapy/Po6KKrpmXzTl1DKIpRKTY2Yz0=
1010
github.com/Clever/discovery-go v1.8.1 h1:bT2q5IkEZnQviXEvC6iij9KNlJTPyLXPOQQCvvpX2Rg=
1111
github.com/Clever/discovery-go v1.8.1/go.mod h1:2W318WszWlVde/hKBvxM3xrQKcmxWwv+6ysUu8Rfx0I=
12-
github.com/Clever/wag/logging/wagclientlogger v0.0.0-20221024182247-2bf828ef51be/go.mod h1:NPerIFemV/7da/vNGALWkky+mit4ulSa24NSalIXgpo=
1312
github.com/Clever/wag/logging/wagclientlogger v0.0.0-20230227191614-7aa97ba44ab1 h1:oHA1IVZ/TIUPf6NUMGCh5X/jHSVdrmR/kCdCDErDtz8=
1413
github.com/Clever/wag/logging/wagclientlogger v0.0.0-20230227191614-7aa97ba44ab1/go.mod h1:NPerIFemV/7da/vNGALWkky+mit4ulSa24NSalIXgpo=
1514
github.com/Microsoft/go-winio v0.6.1 h1:9/kr64B9VUZrLm5YYwbGtUJnMgqWVOdUAXu6Migciow=
@@ -18,8 +17,6 @@ github.com/Microsoft/hcsshim v0.10.0-rc.7 h1:HBytQPxcv8Oy4244zbQbe6hnOnx544eL5QP
1817
github.com/Microsoft/hcsshim v0.10.0-rc.7/go.mod h1:ILuwjA+kNW+MrN/w5un7n3mTqkwsFu4Bp05/okFUZlE=
1918
github.com/PuerkitoBio/purell v1.1.1/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0=
2019
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE=
21-
github.com/afex/hystrix-go v0.0.0-20180502004556-fa1af6a1f4f5 h1:rFw4nCn9iMW+Vajsk51NtYIcwSTkXr+JGrMd36kTDJw=
22-
github.com/afex/hystrix-go v0.0.0-20180502004556-fa1af6a1f4f5/go.mod h1:SkGFH1ia65gfNATL8TAiHDNxPzPdmEL5uirI2Uyuz6c=
2320
github.com/asaskevich/govalidator v0.0.0-20200907205600-7a23bdc65eef/go.mod h1:WaHUgvxTVq04UNunO+XhnAqY/wQc+bxr74GqbsZ/Jqw=
2421
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 h1:DklsrG3dyBCFEj5IhUbnKptjxatkF07cF2ak3yi77so=
2522
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2/go.mod h1:WaHUgvxTVq04UNunO+XhnAqY/wQc+bxr74GqbsZ/Jqw=
@@ -87,9 +84,6 @@ github.com/docker/go-connections v0.4.0/go.mod h1:Gbd7IOopHjR8Iph03tsViu4nIes5Xh
8784
github.com/docker/go-units v0.4.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
8885
github.com/docker/go-units v0.5.0 h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4=
8986
github.com/docker/go-units v0.5.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
90-
github.com/donovanhide/eventsource v0.0.0-20171031113327-3ed64d21fb0b/go.mod h1:56wL82FO0bfMU5RvfXoIwSOP2ggqqxT+tAfNEIyxuHw=
91-
github.com/donovanhide/eventsource v0.0.0-20210830082556-c59027999da0 h1:C7t6eeMaEQVy6e8CarIhscYQlNmw5e3G36y7l7Y21Ao=
92-
github.com/donovanhide/eventsource v0.0.0-20210830082556-c59027999da0/go.mod h1:56wL82FO0bfMU5RvfXoIwSOP2ggqqxT+tAfNEIyxuHw=
9387
github.com/frankban/quicktest v1.11.3/go.mod h1:wRf/ReqHper53s+kmmSZizM8NamnL3IM0I9ntUbOk+k=
9488
github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk=
9589
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
@@ -118,7 +112,6 @@ github.com/go-openapi/spec v0.20.8 h1:ubHmXNY3FCIOinT8RNrrPfGc9t7I1qhPtdOGoG2AxR
118112
github.com/go-openapi/spec v0.20.8/go.mod h1:2OpW+JddWPrpXSCIX8eOx7lZ5iyuWj3RYR6VaaBKcWA=
119113
github.com/go-openapi/strfmt v0.21.0/go.mod h1:ZRQ409bWMj+SOgXofQAGTIo2Ebu72Gs+WaRADcS5iNg=
120114
github.com/go-openapi/strfmt v0.21.1/go.mod h1:I/XVKeLc5+MM5oPNN7P6urMOpuLXEcNrCX/rPGuWb0k=
121-
github.com/go-openapi/strfmt v0.21.2/go.mod h1:I/XVKeLc5+MM5oPNN7P6urMOpuLXEcNrCX/rPGuWb0k=
122115
github.com/go-openapi/strfmt v0.21.3/go.mod h1:k+RzNO0Da+k3FrrynSNN8F7n/peCmQQqbbXjtDfvmGg=
123116
github.com/go-openapi/strfmt v0.21.7 h1:rspiXgNWgeUzhjo1YU01do6qsahtJNByjLVbPLNHb8k=
124117
github.com/go-openapi/strfmt v0.21.7/go.mod h1:adeGTkxE44sPyLk0JV235VQAO/ZXUr8KAzYjclFs3ew=
@@ -127,7 +120,6 @@ github.com/go-openapi/swag v0.19.15/go.mod h1:QYRuS/SOXUCsnplDa677K7+DxSOj6IPNl/
127120
github.com/go-openapi/swag v0.21.1/go.mod h1:QYRuS/SOXUCsnplDa677K7+DxSOj6IPNl/eQntq43wQ=
128121
github.com/go-openapi/swag v0.22.3 h1:yMBqmnQ0gyZvEb/+KzuWZOXgllrXT4SADYbvDaXHv/g=
129122
github.com/go-openapi/swag v0.22.3/go.mod h1:UzaqsxGiab7freDnrUUra0MwWfN/q7tE4j+VcZ0yl14=
130-
github.com/go-openapi/validate v0.22.0/go.mod h1:rjnrwK57VJ7A8xqfpAOEKRH8yQSGUriMu5/zuPSQ1hg=
131123
github.com/go-openapi/validate v0.22.1 h1:G+c2ub6q47kfX1sOBLwIQwzBVt8qmOAARyo/9Fqs9NU=
132124
github.com/go-openapi/validate v0.22.1/go.mod h1:rjnrwK57VJ7A8xqfpAOEKRH8yQSGUriMu5/zuPSQ1hg=
133125
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
@@ -169,11 +161,8 @@ github.com/google/go-cmp v0.5.8/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeN
169161
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
170162
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
171163
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
172-
github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
173164
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
174165
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
175-
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8=
176-
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
177166
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
178167
github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg=
179168
github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo=
@@ -182,8 +171,6 @@ github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfC
182171
github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqxOKXbg=
183172
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
184173
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
185-
github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo=
186-
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
187174
github.com/karrick/godirwalk v1.8.0/go.mod h1:H5KPZjojv4lE+QYImBI8xVtrBRgYrIVsaRPx4tDPEn4=
188175
github.com/karrick/godirwalk v1.10.3/go.mod h1:RoGL9dQei4vP9ilrpETWE8CLOZ1kiN0LhBygSwrAsHA=
189176
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
@@ -259,10 +246,6 @@ github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6Mwd
259246
github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
260247
github.com/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0=
261248
github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
262-
github.com/smartystreets/assertions v1.2.0 h1:42S6lae5dvLc7BrLu/0ugRtcFVjoJNMC/N3yZFZkDFs=
263-
github.com/smartystreets/assertions v1.2.0/go.mod h1:tcbTF8ujkAEcZ8TElKY+i30BzYlVhC/LOxJk7iOWnoo=
264-
github.com/smartystreets/goconvey v1.7.2 h1:9RBaZCeXEQ3UselpuwUQHltGVXvdwm6cv1hgR6gDIPg=
265-
github.com/smartystreets/goconvey v1.7.2/go.mod h1:Vw0tHAZW6lzCRk3xgdin6fKYcG+G3Pg9vgXWeJpQFMM=
266249
github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ=
267250
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
268251
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
@@ -315,7 +298,6 @@ golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLL
315298
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
316299
golang.org/x/net v0.0.0-20201224014010-6772e930b67b/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
317300
golang.org/x/net v0.0.0-20210421230115-4e50805a0758/go.mod h1:72T/g9IO56b78aLF+1Kcs5dz7/ng1VjMUvfKvpfy+jM=
318-
golang.org/x/net v0.0.0-20210614182718-04defd469f4e/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
319301
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
320302
golang.org/x/net v0.33.0 h1:74SYHlV8BIgHIFC/LrYkOGIwL19eTYXQ5wc6TBuO36I=
321303
golang.org/x/net v0.33.0/go.mod h1:HXLR5J+9DxmrqMwG9qjGCxZ+zKXxBru04zlTvWlWuN4=
@@ -359,7 +341,6 @@ golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
359341
golang.org/x/time v0.3.0 h1:rg5rLMjNzMS1RkNLzCG38eapWhnYLFYXDXj2gOlr8j4=
360342
golang.org/x/time v0.3.0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
361343
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
362-
golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
363344
golang.org/x/tools v0.0.0-20190329151228-23e29df326fe/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
364345
golang.org/x/tools v0.0.0-20190416151739-9c9e1878f421/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
365346
golang.org/x/tools v0.0.0-20190420181800-aa740d480789/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=

internal/backstage/backstage.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package backstage
2+
3+
import (
4+
"fmt"
5+
"os"
6+
7+
"gopkg.in/yaml.v3"
8+
)
9+
10+
// BackstageEntity represents a generic Backstage entity.
11+
type Entity struct {
12+
APIVersion string `json:"apiVersion"` // The API version of the entity (e.g., "backstage.io/v1alpha1").
13+
Kind string `json:"kind"` // The kind of the entity (e.g., "Component", "API").
14+
Metadata Metadata `json:"metadata"` // Metadata about the entity.
15+
Spec map[string]interface{} `json:"spec"` // The specification of the entity (varies by kind).
16+
}
17+
18+
// BackstageMetadata represents the metadata of a Backstage entity.
19+
type Metadata struct {
20+
Name string `json:"name"` // The name of the entity.
21+
Namespace string `json:"namespace,omitempty"` // The namespace of the entity (optional).
22+
Description string `json:"description,omitempty"` // A description of the entity (optional).
23+
Labels map[string]string `json:"labels,omitempty"` // Labels for the entity (optional).
24+
Annotations map[string]string `json:"annotations,omitempty"` // Annotations for the entity (optional).
25+
Tags []string `json:"tags,omitempty"` // Tags for the entity (optional).
26+
}
27+
28+
// GetEntityFromYaml reads a yaml file and returns a BackstageEntity.
29+
func GetEntityFromYaml(filePath string) (*Entity, error) {
30+
data, err := os.ReadFile(filePath)
31+
if err != nil {
32+
return nil, fmt.Errorf("failed to read file %s: %v", filePath, err)
33+
}
34+
var entity Entity
35+
err = yaml.Unmarshal(data, &entity)
36+
if err != nil {
37+
return nil, fmt.Errorf("failed to unmarshal yaml: %v", err)
38+
}
39+
return &entity, nil
40+
}
41+
42+
func (e *Entity) GetName() string {
43+
if e == nil {
44+
return ""
45+
}
46+
return e.Metadata.Name
47+
}

internal/catapult/catapult.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,16 @@ func New() *Catapult {
4444
return &Catapult{client: cli}
4545
}
4646

47+
// SyncCatalogEntity syncs passed in entity to catalog-config by calling circle-ci-integrations
48+
func (c *Catapult) SyncCatalogEntity(ctx context.Context, entity *models.SyncCatalogEntityInput) error {
49+
fmt.Println("Syncing catalog entity", entity.Entity)
50+
err := c.client.SyncCatalogEntity(ctx, entity)
51+
if err != nil {
52+
return fmt.Errorf("failed to sync catalog entity %s with catalogue config: %v", entity.Entity, err)
53+
}
54+
return nil
55+
}
56+
4757
// Publish a list of build artifacts to catapult.
4858
func (c *Catapult) Publish(ctx context.Context, artifacts []*Artifact) error {
4959
grp, grpCtx := errgroup.WithContext(ctx)

testApp/catalog-info.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
apiVersion: backstage.io/v1alpha1
2+
kind: Component
3+
metadata:
4+
name: go-lib-test
5+
description: test
6+
owner: eng-infra
7+
spec:
8+
type: library
9+
lifecycle: development
10+
owner: team-name
11+
system: eng-infra

0 commit comments

Comments
 (0)