Skip to content

Instantly share code, notes, and snippets.

@kminehart
Last active July 20, 2022 20:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kminehart/332442c764d6343bfafba1fda16db6be to your computer and use it in GitHub Desktop.
Save kminehart/332442c764d6343bfafba1fda16db6be to your computer and use it in GitHub Desktop.
package main
import (
"pipeline"
"pipeline/yarn"
)
const (
ImageGolang = "golang:1.18"
ImageNode = "node:18"
)
// These arguments can either be required by a step or provided by another step
var (
ArgumentNodeModules = pipeline.NewDirectoryArgument("node-modules")
ArgumentAssets = pipeline.NewDirectoryArgument("assets")
)
// These are simple, re-used steps that are very common,
// and are therefore available in the pipeline package.
var (
StepInstallGoModules = pipeline.GoModDownload(ImageGolang).Requires(pipeline.ArgumentSourceFS)
StepBuildServer = pipeline.GoBuild(ImageGolang, "./cmd/server", ArgumentServerBin)
StepUploadAssets = pipeline.GCSUpload(ArgumentAssets, "gcs://path-to-assets")
// StepBuildFrontend is a custom step created from a custom action.
StepBuildFrontend = pipeline.NewStep(buildFrontend).WithImage(ImageNode).Provides(ArgumentAssets)
)
// This is an example action that demonstrates making more complex steps that may not be fully available in the "pipeline" library.
// Instead, those steps will have to create their own actions.
func buildFrontend(ctx context.Context, opts pipeline.ActionOpts) error {
if err := yarn.Run(ctx, "build"); err != nil {
return err
}
return opts.State.SetDirectory(ArgumentAssets, "dist")
}
// PipelineBuildGo builds the Go
func PipelineBuildGo(event *pipeline.Event) pipeline.PipelineHandler {
return func(p *pipeline.Pipeline) {
p.When(event)
p.Run(StepInstallGoModules, StepTestBackend)
p.Parallel(...)
}
}
func main() {
p := pipeline.NewMulti()
defer p.Done()
// Build & test the frontend and backend in PRs
p.Run(
p.New("pr-build-go", PipelineBuildGo(pipeline.EventPR{})),
p.New("pr-build-frontend", PipelineBuildFrontend(pipeline.EventPR{})),
)
// Build & test the frontend and backend in commits to main
p.Parallel(
// Omitted for brevity..
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment