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}",
dagger.GhaWithPipelineOpts{
OnPush: true,
},
).
Config()
}
no available example in current language
no available example in current language
Example (OnPullRequest)
no available example in current language
// Call integration tests on pull requests
func (m *Examples) Gha_OnPullRequest() *dagger.Directory {
return dag.
Gha().
WithPipeline(
"test pull requests",
"test --all --source=.",
dagger.GhaWithPipelineOpts{
OnPullRequestOpened: true,
OnPullRequestSynchronize: true,
},
).
Config()
}
no available example in current language
no available example in current language
Example (OnPush)
no available example in current language
// Build and publish a container on push
func (m *Examples) Gha_OnPush() *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{
OnPushBranches: []string{"main"},
Secrets: []string{
"REGISTRY_USER", "REGISTRY_PASSWORD",
},
}).
Config()
}
no available example in current language
no available example in current language
Example (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{
Secrets: []string{"DOCS_SERVER_PASSWORD"},
}).
Config()
}
no available example in current language
no available example in current language
Example (Concurrency)
no available example in current language
// Limit per-PR concurrency for expensive test pipelines
func (m *Examples) Gha_Concurrency() *dagger.Directory {
return dag.
Gha().
WithPipeline(
"Giant test suite",
"test --all",
dagger.GhaWithPipelineOpts{
PullRequestConcurrency: "preempt",
},
).
Config()
}
no available example in current language
no available example in current language
Example (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 language
no available example in current language
Installation
dagger install github.com/gerhard/gha@9f051afa2b895b5a4281d8bafb07f7a5d50d1efd
Entrypoint
Return Type
Gha !
Arguments
Name | Type | 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 | 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 ! ] | 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 |
fileExtension | String | File extension to use for generated workflow files |
repository | Directory | Existing repository root, to merge existing content |
timeoutMinutes | Integer | Default timeout for CI jobs, in minutes |
Example
dagger -m github.com/gerhard/gha@9f051afa2b895b5a4281d8bafb07f7a5d50d1efd call \
func (m *myModule) example() *Gha {
return dag.
Gha()
}
@function
def example() -> dag.Gha:
return (
dag.gha()
)
@func()
example(): Gha {
return dag
.gha()
}
Types
Gha 🔗
settings() 🔗
Settings for this Github Actions project
Return Type
Settings !
Example
dagger -m github.com/gerhard/gha@9f051afa2b895b5a4281d8bafb07f7a5d50d1efd call \
settings
func (m *myModule) example() *GhaSettings {
return dag.
Gha().
Settings()
}
@function
def example() -> dag.GhaSettings:
return (
dag.gha()
.settings()
)
@func()
example(): GhaSettings {
return dag
.gha()
.settings()
}
validate() 🔗
Validate a Github Actions configuration (best effort)
Return Type
Gha !
Arguments
Name | Type | Default Value | Description |
---|---|---|---|
repo | Directory ! | - | No description provided |
Example
dagger -m github.com/gerhard/gha@9f051afa2b895b5a4281d8bafb07f7a5d50d1efd call \
validate --repo DIR_PATH
func (m *myModule) example(repo *Directory) *Gha {
return dag.
Gha().
Validate(repo)
}
@function
def example(repo: dagger.Directory) -> dag.Gha:
return (
dag.gha()
.validate(repo)
)
@func()
example(repo: Directory): Gha {
return dag
.gha()
.validate(repo)
}
config() 🔗
Export the configuration to a .github directory
Return Type
Directory !
Example
dagger -m github.com/gerhard/gha@9f051afa2b895b5a4281d8bafb07f7a5d50d1efd call \
config
func (m *myModule) example() *Directory {
return dag.
Gha().
Config()
}
@function
def example() -> dagger.Directory:
return (
dag.gha()
.config()
)
@func()
example(): Directory {
return dag
.gha()
.config()
}
withPipeline() 🔗
Add a pipeline
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 Example: ["ubuntu-latest"] |
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 | - | (DEPRECATED) allow this pipeline to be manually "dispatched" |
noDispatch | Boolean | - | Disable manual "dispatch" of this pipeline |
lfs | Boolean | - | Enable lfs on git checkout |
debug | Boolean | - | Run the pipeline in debug mode |
daggerVersion | String | - | Dagger version to run this pipeline |
timeoutMinutes | Integer | - | The maximum number of minutes to run the pipeline before killing the process |
permissions | [Enum ! ] | - | Permissions to grant the pipeline |
onIssueComment | Boolean | - | Run the pipeline on any issue comment activity |
onIssueCommentCreated | Boolean | - | No description provided |
onIssueCommentEdited | Boolean | - | No description provided |
onIssueCommentDeleted | Boolean | - | No description provided |
onPullRequest | Boolean | - | Run the pipeline on any pull request activity |
pullRequestConcurrency | String | "allow" | Configure this pipeline's concurrency for each PR. This is triggered when the pipeline is scheduled concurrently on the same PR. - allow: all instances are allowed to run concurrently - queue: new instances are queued, and run sequentially - preempt: new instances run immediately, older ones are canceled Possible values: "allow", "preempt", "queue" |
onPullRequestBranches | [String ! ] | - | No description provided |
onPullRequestPaths | [String ! ] | - | No description provided |
onPullRequestAssigned | Boolean | - | No description provided |
onPullRequestUnassigned | Boolean | - | No description provided |
onPullRequestLabeled | Boolean | - | No description provided |
onPullRequestUnlabeled | Boolean | - | No description provided |
onPullRequestOpened | Boolean | - | No description provided |
onPullRequestEdited | Boolean | - | No description provided |
onPullRequestClosed | Boolean | - | No description provided |
onPullRequestReopened | Boolean | - | No description provided |
onPullRequestSynchronize | Boolean | - | No description provided |
onPullRequestConvertedToDraft | Boolean | - | No description provided |
onPullRequestLocked | Boolean | - | No description provided |
onPullRequestUnlocked | Boolean | - | No description provided |
onPullRequestEnqueued | Boolean | - | No description provided |
onPullRequestDequeued | Boolean | - | No description provided |
onPullRequestMilestoned | Boolean | - | No description provided |
onPullRequestDemilestoned | Boolean | - | No description provided |
onPullRequestReadyForReview | Boolean | - | No description provided |
onPullRequestReviewRequested | Boolean | - | No description provided |
onPullRequestReviewRequestRemoved | Boolean | - | No description provided |
onPullRequestAutoMergeEnabled | Boolean | - | No description provided |
onPullRequestAutoMergeDisabled | Boolean | - | No description provided |
onPush | Boolean | - | Run the pipeline on any git push |
onPushTags | [String ! ] | - | Run the pipeline on git push to the specified tags |
onPushBranches | [String ! ] | - | Run the pipeline on git push to the specified branches |
onSchedule | [String ! ] | - | Run the pipeline at a schedule time |
Example
dagger -m github.com/gerhard/gha@9f051afa2b895b5a4281d8bafb07f7a5d50d1efd call \
with-pipeline --name string --command string
func (m *myModule) example(name string, command string) *Gha {
return dag.
Gha().
WithPipeline(name, command)
}
@function
def example(name: str, command: str) -> dag.Gha:
return (
dag.gha()
.with_pipeline(name, command)
)
@func()
example(name: string, command: string): Gha {
return dag
.gha()
.withPipeline(name, command)
}
Settings 🔗
publicToken() 🔗
Return Type
String !
Example
Function GhaSettings.publicToken is not accessible from the gha module
Function GhaSettings.publicToken is not accessible from the gha module
Function GhaSettings.publicToken is not accessible from the gha module
Function GhaSettings.publicToken is not accessible from the gha module
daggerVersion() 🔗
Return Type
String !
Example
Function GhaSettings.daggerVersion is not accessible from the gha module
Function GhaSettings.daggerVersion is not accessible from the gha module
Function GhaSettings.daggerVersion is not accessible from the gha module
Function GhaSettings.daggerVersion is not accessible from the gha module
noTraces() 🔗
Return Type
Boolean !
Example
Function GhaSettings.noTraces is not accessible from the gha module
Function GhaSettings.noTraces is not accessible from the gha module
Function GhaSettings.noTraces is not accessible from the gha module
Function GhaSettings.noTraces is not accessible from the gha module
stopEngine() 🔗
Return Type
Boolean !
Example
Function GhaSettings.stopEngine is not accessible from the gha module
Function GhaSettings.stopEngine is not accessible from the gha module
Function GhaSettings.stopEngine is not accessible from the gha module
Function GhaSettings.stopEngine is not accessible from the gha module
asJson() 🔗
Return Type
Boolean !
Example
Function GhaSettings.asJson is not accessible from the gha module
Function GhaSettings.asJson is not accessible from the gha module
Function GhaSettings.asJson is not accessible from the gha module
Function GhaSettings.asJson is not accessible from the gha module
runner() 🔗
Return Type
[String ! ] !
Example
Function GhaSettings.runner is not accessible from the gha module
Function GhaSettings.runner is not accessible from the gha module
Function GhaSettings.runner is not accessible from the gha module
Function GhaSettings.runner is not accessible from the gha module
pullRequestConcurrency() 🔗
Return Type
String !
Example
Function GhaSettings.pullRequestConcurrency is not accessible from the gha module
Function GhaSettings.pullRequestConcurrency is not accessible from the gha module
Function GhaSettings.pullRequestConcurrency is not accessible from the gha module
Function GhaSettings.pullRequestConcurrency is not accessible from the gha module
debug() 🔗
Return Type
Boolean !
Example
Function GhaSettings.debug is not accessible from the gha module
Function GhaSettings.debug is not accessible from the gha module
Function GhaSettings.debug is not accessible from the gha module
Function GhaSettings.debug is not accessible from the gha module
fileExtension() 🔗
Return Type
String !
Example
Function GhaSettings.fileExtension is not accessible from the gha module
Function GhaSettings.fileExtension is not accessible from the gha module
Function GhaSettings.fileExtension is not accessible from the gha module
Function GhaSettings.fileExtension is not accessible from the gha module
repository() 🔗
Return Type
Directory !
Example
Function GhaSettings.repository is not accessible from the gha module
Function GhaSettings.repository is not accessible from the gha module
Function GhaSettings.repository is not accessible from the gha module
Function GhaSettings.repository is not accessible from the gha module
timeoutMinutes() 🔗
Return Type
Integer !
Example
Function GhaSettings.timeoutMinutes is not accessible from the gha module
Function GhaSettings.timeoutMinutes is not accessible from the gha module
Function GhaSettings.timeoutMinutes is not accessible from the gha module
Function GhaSettings.timeoutMinutes is not accessible from the gha module
permissions() 🔗
Return Type
[Enum ! ] !
Example
Function GhaSettings.permissions is not accessible from the gha module
Function GhaSettings.permissions is not accessible from the gha module
Function GhaSettings.permissions is not accessible from the gha module
Function GhaSettings.permissions is not accessible from the gha module