gha
Daggerizing your CI makes your YAML configurations smaller, but they still exist,and they're still a pain to maintain by hand.
This module aims to finish the job, by letting you generate your remaining
YAML configuration from a Dagger pipeline, written in your favorite language.
Example (GithubContext)
no available example in current language// Access github context information magically injected as env variables
func (m *Examples) Gha_GithubContext() *dagger.Directory {
return dag.
Gha().
WithPipeline("lint all branches", "lint --source=${GITHUB_REPOSITORY_URL}#${GITHUB_REF}").
OnPush("lint all branches").
Config()
}no available example in current languageno available example in current languageExample (Secrets)
no available example in current language// Access Github secrets
func (m *Examples) Gha_Secrets() *dagger.Directory {
return dag.
Gha().
WithPipeline(
"deploy docs",
"deploy-docs --source=. --password env:$DOCS_SERVER_PASSWORD",
dagger.GhaWithPipelineOpts{
Dispatch: true,
Secrets: []string{"DOCS_SERVER_PASSWORD"},
}).
Config()
}no available example in current languageno available example in current languageExample (CustomModule)
no available example in current language// Compose a pipeline from an external module, instead of the one embedded in the repo.
func (m *Examples) Gha_CustomModule() *dagger.Directory {
return dag.
Gha().
WithPipeline(
"say hello",
"hello --name=$GITHUB_REPOSITORY_OWNER",
dagger.GhaWithPipelineOpts{
Module: "github.com/shykes/hello",
}).
Config()
}no available example in current languageno available example in current languageInstallation
dagger install github.com/shykes/gha@v0.8.0Entrypoint
Return Type
Gha !Arguments
| Name | Type | Default Value | Description |
|---|---|---|---|
| noTraces | Boolean | - | Disable sending traces to Dagger Cloud |
| publicToken | String | - | Public Dagger Cloud token, for open-source projects. DO NOT PASS YOUR PRIVATE DAGGER CLOUD TOKEN! This is for a special "public" token which can safely be shared publicly. To get one, contact support@dagger.io |
| daggerVersion | String | "latest" | Dagger version to run in the Github Actions pipelines |
| stopEngine | Boolean | - | Explicitly stop the Dagger Engine after completing the pipeline |
| asJson | Boolean | - | Encode all files as JSON (which is also valid YAML) |
| runner | String | "ubuntu-latest" | Configure a default runner for all workflows See https://docs.github.com/en/actions/hosting-your-own-runners/managing-self-hosted-runners/using-self-hosted-runners-in-a-workflow |
Example
dagger -m github.com/shykes/gha@1109df9ce95bd1cd70bf9de5bc1232068b184d79 call \
func (m *MyModule) Example() *dagger.Gha {
return dag.
Gha()
}@function
def example() -> dagger.Gha:
return (
dag.gha()
)@func()
example(): Gha {
return dag
.gha()
}Types
Gha 🔗
check() 🔗
Return Type
Gha !Arguments
| Name | Type | Default Value | Description |
|---|---|---|---|
| repo | Directory ! | - | No description provided |
Example
dagger -m github.com/shykes/gha@1109df9ce95bd1cd70bf9de5bc1232068b184d79 call \
check --repo DIR_PATHfunc (m *MyModule) Example(repo *dagger.Directory) *dagger.Gha {
return dag.
Gha().
Check(repo)
}@function
def example(repo: dagger.Directory) -> dagger.Gha:
return (
dag.gha()
.check(repo)
)@func()
example(repo: Directory): Gha {
return dag
.gha()
.check(repo)
}config() 🔗
Generate a github config directory, usable as an overlay on the repository root
Return Type
Directory !Arguments
| Name | Type | Default Value | Description |
|---|---|---|---|
| prefix | String | - | Prefix to use for generated workflow filenames |
Example
dagger -m github.com/shykes/gha@1109df9ce95bd1cd70bf9de5bc1232068b184d79 call \
configfunc (m *MyModule) Example() *dagger.Directory {
return dag.
Gha().
Config()
}@function
def example() -> dagger.Directory:
return (
dag.gha()
.config()
)@func()
example(): Directory {
return dag
.gha()
.config()
}withPipeline() 🔗
Register a new dagger pipeline, with no triggers Use the pipeline name to attach triggers in follow-up calls
Return Type
Gha !Arguments
| Name | Type | Default Value | Description |
|---|---|---|---|
| name | String ! | - | Pipeline name |
| command | String ! | - | The Dagger command to execute Example 'build --source=.' |
| module | String | - | The Dagger module to load |
| runner | String | - | Dispatch jobs to the given runner |
| secrets | [String ! ] | - | Github secrets to inject into the pipeline environment. For each secret, an env variable with the same name is created. Example: ["PROD_DEPLOY_TOKEN", "PRIVATE_SSH_KEY"] |
| sparseCheckout | [String ! ] | - | Use a sparse git checkout, only including the given paths Example: ["src", "tests", "Dockerfile"] |
| dispatch | Boolean | - | Allow this pipeline to be manually "dispatched" |
Example
dagger -m github.com/shykes/gha@1109df9ce95bd1cd70bf9de5bc1232068b184d79 call \
with-pipeline --name string --command stringfunc (m *MyModule) Example(name string, command string) *dagger.Gha {
return dag.
Gha().
WithPipeline(name, command)
}@function
def example(name: str, command: str) -> dagger.Gha:
return (
dag.gha()
.with_pipeline(name, command)
)@func()
example(name: string, command: string): Gha {
return dag
.gha()
.withPipeline(name, command)
}onIssueComment() 🔗
Add a trigger to execute a Dagger pipeline on an issue comment
Return Type
Gha !Arguments
| Name | Type | Default Value | Description |
|---|---|---|---|
| pipeline | String ! | - | Name of the pipeline to trigger |
| types | [String ! ] | - | Run only for certain types of issue comment events See https://docs.github.com/en/actions/writing-workflows/choosing-when-your-workflow-runs/events-that-trigger-workflows#issue_comment |
Example
dagger -m github.com/shykes/gha@1109df9ce95bd1cd70bf9de5bc1232068b184d79 call \
on-issue-comment --pipeline stringfunc (m *MyModule) Example(pipeline string) *dagger.Gha {
return dag.
Gha().
OnIssueComment(pipeline)
}@function
def example(pipeline: str) -> dagger.Gha:
return (
dag.gha()
.on_issue_comment(pipeline)
)@func()
example(pipeline: string): Gha {
return dag
.gha()
.onIssueComment(pipeline)
}onPullRequest() 🔗
Add a trigger to execute a Dagger pipeline on a pull request
Return Type
Gha !Arguments
| Name | Type | Default Value | Description |
|---|---|---|---|
| pipeline | String ! | - | Name of the pipeline to trigger |
| types | [String ! ] | - | Run only for certain types of pull request events See https://docs.github.com/en/actions/writing-workflows/choosing-when-your-workflow-runs/events-that-trigger-workflows#pull_request |
| branches | [String ! ] | - | Run only for pull requests that target specific branches |
| paths | [String ! ] | - | Run only for pull requests that target specific paths |
Example
no available example in current language// Call integration tests on pull requests
func (m *Examples) GhaOnPullRequest() *dagger.Directory {
return dag.
Gha().
WithPipeline("test pull requests", "test --all --source=.").
OnPullRequest("test pull requests").
Config()
}no available example in current languageno available example in current languageonPush() 🔗
Add a trigger to execute a Dagger pipeline on a git push
Return Type
Gha !Arguments
| Name | Type | Default Value | Description |
|---|---|---|---|
| pipeline | String ! | - | Name of the pipeline to trigger |
| branches | [String ! ] | - | Run only on push to specific branches |
| tags | [String ! ] | - | Run only on push to specific tags |
| paths | [String ! ] | - | Run only on push to specific paths |
Example
no available example in current language// Call the repo's 'build()' dagger function on push to main
func (m *Examples) GhaOnPush() *dagger.Directory {
return dag.
Gha().
WithPipeline(
"build and publish app container from main",
"publish --source=. --registry-user=$REGISTRY_USER --registry-password=$REGISTRY_PASSWORD",
dagger.GhaWithPipelineOpts{
Secrets: []string{
"REGISTRY_USER", "REGISTRY_PASSWORD",
},
}).
OnPush("build and publish app container from main",
dagger.GhaOnPushOpts{
Branches: []string{"main"},
}).
Config()
}no available example in current languageno available example in current language