Skip to content

Commit

Permalink
ci: add gha publish command to ci module
Browse files Browse the repository at this point in the history
  • Loading branch information
aweris committed Nov 21, 2023
1 parent e0e54a7 commit d5ce083
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions ci/gha.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package main

import (
"context"
"path/filepath"
"time"
)

const (
Expand Down Expand Up @@ -80,3 +82,37 @@ func (g *Gha) Generate(ctx context.Context) (*Directory, error) {

return gha, nil
}

// Publish publishes the Github Actions modules from gha catalog to daggerverse.dev
func (g *Gha) Publish(ctx context.Context) error {
var (
gha = dag.Host().Directory(root()).Directory(ghaPath)
cf = gha.File(catalogFile)
)

var catalog Catalog

err := unmarshalContentsToYAML(ctx, cf, &catalog)
if err != nil {
return err
}

for _, action := range catalog.Actions {
daggerVersion := action.DaggerVersion
if daggerVersion == "" {
daggerVersion = catalog.Global.DaggerVersion
}

_, err = dagger(Opt(daggerVersion)).
WithMountedDirectory("/src", dag.Host().Directory(root())).
WithWorkdir("/src").
WithEnvVariable("CACHE_BUSTER", time.Now().Format(time.RFC3339Nano)).
WithExec([]string{"mod", "publish", "-f", "-m", filepath.Join(ghaPath, action.Repo)}, ContainerWithExecOpts{ExperimentalPrivilegedNesting: true}).
Sync(ctx)
if err != nil {
return err
}
}

return nil
}

0 comments on commit d5ce083

Please sign in to comment.