Dagger
Search

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 (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/shykes/gha@v0.9.0

Entrypoint

Return Type
Gha !
Arguments
NameTypeDescription
noTracesBoolean Disable sending traces to Dagger Cloud
publicTokenString 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
daggerVersionString Dagger version to run in the Github Actions pipelines
stopEngineBoolean Explicitly stop the Dagger Engine after completing the pipeline
asJsonBoolean Encode all files as JSON (which is also valid YAML)
runnerString 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@a8671414892009ecdcadc84c8fed9d22984209bc 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 🔗

validate() 🔗

Validate a Github Actions configuration (best effort)

Return Type
Gha !
Arguments
NameTypeDefault ValueDescription
repoDirectory !-No description provided
Example
dagger -m github.com/shykes/gha@a8671414892009ecdcadc84c8fed9d22984209bc 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 !
Arguments
NameTypeDefault ValueDescription
prefixString -Prefix to use for generated workflow filenames
Example
dagger -m github.com/shykes/gha@a8671414892009ecdcadc84c8fed9d22984209bc 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
NameTypeDefault ValueDescription
nameString !-Pipeline name
commandString !-The Dagger command to execute Example 'build --source=.'
moduleString -The Dagger module to load
runnerString -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"]
dispatchBoolean -(DEPRECATED) allow this pipeline to be manually "dispatched"
noDispatchBoolean -Disable manual "dispatch" of this pipeline
lfsBoolean -Enable lfs on git checkout
onIssueCommentBoolean -Run the pipeline on any issue comment activity
onIssueCommentCreatedBoolean -No description provided
onIssueCommentEditedBoolean -No description provided
onIssueCommentDeletedBoolean -No description provided
onPullRequestBoolean -Run the pipeline on any pull request activity
onPullRequestBranches[String ! ] -No description provided
onPullRequestPaths[String ! ] -No description provided
onPullRequestAssignedBoolean -No description provided
onPullRequestUnassignedBoolean -No description provided
onPullRequestLabeledBoolean -No description provided
onPullRequestUnlabeledBoolean -No description provided
onPullRequestOpenedBoolean -No description provided
onPullRequestEditedBoolean -No description provided
onPullRequestClosedBoolean -No description provided
onPullRequestReopenedBoolean -No description provided
onPullRequestSynchronizeBoolean -No description provided
onPullRequestConvertedToDraftBoolean -No description provided
onPullRequestLockedBoolean -No description provided
onPullRequestUnlockedBoolean -No description provided
onPullRequestEnqueuedBoolean -No description provided
onPullRequestDequeuedBoolean -No description provided
onPullRequestMilestonedBoolean -No description provided
onPullRequestDemilestonedBoolean -No description provided
onPullRequestReadyForReviewBoolean -No description provided
onPullRequestReviewRequestedBoolean -No description provided
onPullRequestReviewRequestRemovedBoolean -No description provided
onPullRequestAutoMergeEnabledBoolean -No description provided
onPullRequestAutoMergeDisabledBoolean -No description provided
onPushBoolean -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
Example
dagger -m github.com/shykes/gha@a8671414892009ecdcadc84c8fed9d22984209bc 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)
}