-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ci: automate action generation (#182)
* dagger: sync ci module * ci: automate action generation
- Loading branch information
Showing
7 changed files
with
141 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
{ | ||
"name": "gale-ci", | ||
"root": "..", | ||
"sdk": "go", | ||
"root": ".." | ||
"dependencies": [ | ||
"../daggerverse/actions/generator" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
) | ||
|
||
const ( | ||
// ghaPath is the relative path to the home directory of the generated Github Actions modules | ||
ghaPath = "daggerverse/gha" | ||
|
||
// catalogFile is the name of the catalog file for the generated Github Actions modules | ||
catalogFile = "catalog.yaml" | ||
) | ||
|
||
type Gha struct{} | ||
|
||
// Catalog represents the catalog of generated Github Actions modules. | ||
type Catalog struct { | ||
Global Global `yaml:"global,omitempty"` | ||
Actions []Action `yaml:"actions,omitempty"` | ||
} | ||
|
||
// Global represents the global configuration for the generated Github Actions modules. | ||
type Global struct { | ||
// Global Runtime Version to use. If not specified, latest version will be used. | ||
RuntimeVersion string `yaml:"actionsRuntimeVersion,omitempty"` | ||
|
||
// Dagger Version to use. If not specified, latest version will be used. | ||
DaggerVersion string `yaml:"daggerVersion,omitempty"` | ||
} | ||
|
||
// Action represents a Github Action configuration to generate. | ||
type Action struct { | ||
// Name of the action repo. Format:<owner>/<repo> | ||
Repo string `yaml:"repo"` | ||
|
||
// Version of the action to run. Format:<version> | ||
Version string `yaml:"version"` | ||
|
||
// Action Runtime Version to use. If not specified, global version will be used. | ||
RuntimeVersion string `yaml:"actionsRuntimeVersion,omitempty"` | ||
|
||
// Dagger Version to use. If not specified, global version will be used. | ||
DaggerVersion string `yaml:"daggerVersion,omitempty"` | ||
} | ||
|
||
// Generate generates the Github Actions modules from gha catalog and returns the directory containing the generated modules. | ||
func (g *Gha) Generate(ctx context.Context) (*Directory, 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 nil, err | ||
} | ||
|
||
for _, action := range catalog.Actions { | ||
var ( | ||
name = action.Repo + "@" + action.Version | ||
runtime = action.RuntimeVersion | ||
dagger = action.DaggerVersion | ||
) | ||
|
||
if runtime == "" { | ||
runtime = catalog.Global.RuntimeVersion | ||
} | ||
|
||
if dagger == "" { | ||
dagger = catalog.Global.DaggerVersion | ||
} | ||
|
||
dir := dag.ActionsGenerator().Generate(name, ActionsGeneratorGenerateOpts{RuntimeVersion: runtime, DaggerVersion: dagger}) | ||
|
||
gha = gha.WithDirectory(".", dir) | ||
} | ||
|
||
return gha, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# global values to be used by all actions | ||
global: | ||
actionsRuntimeVersion: "e0f087ca2b2b6cb2e2cb2360e497c7e19c2b9365" | ||
daggerVersion: "v0.9.3" | ||
|
||
# generated actions. global values can be overridden per action item if needed | ||
actions: | ||
- repo: "actions/hello-world-javascript-action" | ||
version: "main" | ||
- repo: "aquasecurity/trivy-action" | ||
version: "master" | ||
- repo: "trufflesecurity/trufflehog" | ||
version: "main" |