Add a new Dagger workflow to package and publish the neovim configuration to a generic registry in Code Flow.
81 lines
1.8 KiB
Go
81 lines
1.8 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
|
|
"dagger.io/dagger"
|
|
)
|
|
|
|
const (
|
|
envCodeFlowUsername string = "CODEFLOW_USERNAME"
|
|
envCodeFlowToken string = "CODEFLOW_TOKEN"
|
|
)
|
|
|
|
func main() {
|
|
if err := build(context.Background()); err != nil {
|
|
fmt.Printf("ERROR: %v", err)
|
|
os.Exit(1)
|
|
}
|
|
}
|
|
|
|
func build(ctx context.Context) error {
|
|
fmt.Println("Building with Dagger.")
|
|
|
|
client, err := dagger.Connect(ctx, dagger.WithLogOutput(os.Stdout))
|
|
if err != nil {
|
|
return fmt.Errorf("unable to create the dagger client; %w", err)
|
|
}
|
|
defer client.Close()
|
|
|
|
rootDir, err := filepath.Abs(".")
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
image := "alpine:3.17"
|
|
|
|
containerWorkspace := "/workspace"
|
|
|
|
username := os.Getenv(envCodeFlowUsername)
|
|
if username == "" {
|
|
return fmt.Errorf("%s is not set", envCodeFlowUsername)
|
|
}
|
|
|
|
token := os.Getenv(envCodeFlowToken)
|
|
if token == "" {
|
|
return fmt.Errorf("%s is not set", envCodeFlowToken)
|
|
}
|
|
|
|
publisher := client.Container().
|
|
From(image).
|
|
WithMountedDirectory(containerWorkspace, client.Host().Directory(rootDir)).
|
|
WithWorkdir(containerWorkspace).
|
|
WithEnvVariable("XDG_CONFIG_HOME", "null").
|
|
WithEnvVariable("CODEFLOW_USERNAME", username).
|
|
WithEnvVariable("CODEFLOW_TOKEN", token)
|
|
|
|
publisher = setDependencies(publisher)
|
|
publisher = publish(publisher, containerWorkspace)
|
|
|
|
_, err = publisher.Stdout(ctx)
|
|
if err != nil {
|
|
return fmt.Errorf("unable to export package from container; %w", err)
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func setDependencies(container *dagger.Container) *dagger.Container {
|
|
return container.WithExec([]string{
|
|
"apk", "add", "--no-cache", "bash", "curl", "git", "make",
|
|
})
|
|
}
|
|
|
|
func publish(container *dagger.Container, workspace string) *dagger.Container {
|
|
return container.
|
|
WithExec([]string{"git", "config", "--global", "--add", "safe.directory", workspace}).
|
|
WithExec([]string{"make", "publish"})
|
|
}
|