-
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.
feat: accept containers to execute actions (#180)
* refactor: remove no-op `workflows` from module * refactor: use base container for config * feat: accept containers to execute actions * docs: update README.md * refactor: update actions/runtime with new gale DX * docs: add changie notes
- Loading branch information
Showing
13 changed files
with
266 additions
and
189 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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
kind: Added | ||
body: Introduced a new `--container` option to specify the container type for runners. | ||
time: 2023-11-08T12:15:19.019065+01:00 | ||
custom: | ||
Author: aweris | ||
PR: "180" |
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,6 @@ | ||
kind: Breaking | ||
body: Removed the `workflows` subcommand from the module. `list` and `run` commands are now available directly under module root. | ||
time: 2023-11-08T12:05:44.825203+01:00 | ||
custom: | ||
Author: aweris | ||
PR: "180" |
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,7 @@ | ||
kind: Changed | ||
body: Renamed the command line option `--runner-image` to `--image`. This change affects | ||
all commands where `--runner-image` was previously used. | ||
time: 2023-11-08T12:14:39.28384+01:00 | ||
custom: | ||
Author: aweris | ||
PR: "180" |
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
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,8 +1,128 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"strings" | ||
) | ||
|
||
// Gale is a Dagger module for running Github Actions workflows. | ||
type Gale struct{} | ||
|
||
func (g *Gale) Workflows() *Workflows { | ||
return new(Workflows) | ||
// List returns a list of workflows and their jobs with the given options. | ||
func (g *Gale) List( | ||
// context to use for the operation | ||
ctx context.Context, | ||
// The directory containing the repository source. If source is provided, rest of the options are ignored. | ||
source Optional[*Directory], | ||
// The name of the repository. Format: owner/name. | ||
repo Optional[string], | ||
// Tag name to check out. Only one of branch or tag can be used. Precedence is as follows: tag, branch. | ||
tag Optional[string], | ||
// Branch name to check out. Only one of branch or tag can be used. Precedence is as follows: tag, branch. | ||
branch Optional[string], | ||
// Path to the workflows' directory. (default: .github/workflows) | ||
workflowsDir Optional[string], | ||
) (string, error) { | ||
workflows := getWorkflowsDir(source, repo, tag, branch, workflowsDir) | ||
|
||
sb := strings.Builder{} | ||
|
||
err := walkWorkflowDir(ctx, workflowsDir, workflows, | ||
func(ctx context.Context, path string, file *File) error { | ||
// dagger do not support maps yet, so we're defining anonymous struct to unmarshal the yaml file to avoid | ||
// hit this limitation. | ||
var workflow struct { | ||
Name string `yaml:"name"` | ||
Jobs map[string]interface{} `yaml:"jobs"` | ||
} | ||
|
||
if err := unmarshalContentsToYAML(ctx, file, &workflow); err != nil { | ||
return err | ||
} | ||
|
||
sb.WriteString("Workflow: ") | ||
if workflow.Name != "" { | ||
sb.WriteString(fmt.Sprintf("%s (path: %s)\n", workflow.Name, path)) | ||
} else { | ||
sb.WriteString(fmt.Sprintf("%s\n", path)) | ||
} | ||
|
||
sb.WriteString("Jobs:\n") | ||
|
||
for job := range workflow.Jobs { | ||
sb.WriteString(fmt.Sprintf(" - %s\n", job)) | ||
} | ||
|
||
sb.WriteString("\n") // extra empty line | ||
|
||
return nil | ||
}, | ||
) | ||
|
||
if err != nil { | ||
return "", err | ||
} | ||
|
||
return sb.String(), nil | ||
} | ||
|
||
// Run runs the workflow with the given options. | ||
func (g *Gale) Run( | ||
// The directory containing the repository source. If source is provided, rest of the options are ignored. | ||
source Optional[*Directory], | ||
// The name of the repository. Format: owner/name. | ||
repo Optional[string], | ||
// Tag name to check out. Only one of branch or tag can be used. Precedence is as follows: tag, branch. | ||
tag Optional[string], | ||
// Branch name to check out. Only one of branch or tag can be used. Precedence is as follows: tag, branch. | ||
branch Optional[string], | ||
// Path to the workflows directory. (default: .github/workflows) | ||
workflowsDir Optional[string], | ||
// External workflow file to run. | ||
workflowFile Optional[*File], | ||
// Name of the workflow to run. | ||
workflow Optional[string], | ||
// Name of the job to run. If empty, all jobs will be run. | ||
job Optional[string], | ||
// Name of the event that triggered the workflow. e.g. push | ||
event Optional[string], | ||
// File with the complete webhook event payload. | ||
eventFile Optional[*File], | ||
// Image to use for the runner. If --image and --container provided together, --image takes precedence. | ||
image Optional[string], | ||
// Container to use for the runner. If --image and --container provided together, --image takes precedence. | ||
container Optional[*Container], | ||
// Enables debug mode. | ||
runnerDebug Optional[bool], | ||
// GitHub token to use for authentication. | ||
token Optional[*Secret], | ||
) *WorkflowRun { | ||
var base *Container | ||
|
||
if image, ok := image.Get(); ok { | ||
base = dag.Container().From(image) | ||
} else if container, ok := container.Get(); ok { | ||
base = container | ||
} else { | ||
base = dag.Container().From("ghcr.io/catthehacker/ubuntu:act-latest") | ||
} | ||
|
||
return &WorkflowRun{ | ||
Config: WorkflowRunConfig{ | ||
Base: base, | ||
Source: source.GetOr(nil), | ||
Repo: repo.GetOr(""), | ||
Branch: branch.GetOr(""), | ||
Tag: tag.GetOr(""), | ||
WorkflowsDir: workflowsDir.GetOr(".github/workflows"), | ||
WorkflowFile: workflowFile.GetOr(nil), | ||
Workflow: workflow.GetOr(""), | ||
Job: job.GetOr(""), | ||
Event: event.GetOr("push"), | ||
EventFile: eventFile.GetOr(nil), | ||
RunnerDebug: runnerDebug.GetOr(false), | ||
Token: token.GetOr(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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ import ( | |
"context" | ||
"encoding/json" | ||
"fmt" | ||
|
||
"gopkg.in/yaml.v3" | ||
) | ||
|
||
|
Oops, something went wrong.