Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: move directory access to repo module #179

Merged
merged 3 commits into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion daggerverse/gale/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/99designs/gqlgen v0.17.31
github.com/Khan/genqlient v0.6.0
golang.org/x/exp v0.0.0-20231006140011-7918f672742d
golang.org/x/sync v0.3.0
golang.org/x/sync v0.4.0
)

require (
Expand Down
4 changes: 2 additions & 2 deletions daggerverse/gale/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ github.com/vektah/gqlparser/v2 v2.5.6 h1:Ou14T0N1s191eRMZ1gARVqohcbe1e8FrcONScsq
github.com/vektah/gqlparser/v2 v2.5.6/go.mod h1:z8xXUff237NntSuH8mLFijZ+1tjV1swDbpDqjJmk6ME=
golang.org/x/exp v0.0.0-20231006140011-7918f672742d h1:jtJma62tbqLibJ5sFQz8bKtEM8rJBtfilJ2qTU199MI=
golang.org/x/exp v0.0.0-20231006140011-7918f672742d/go.mod h1:ldy0pHrwJyGW56pPQzzkH36rKxoZW1tw7ZJpeKx+hdo=
golang.org/x/sync v0.3.0 h1:ftCYgMx6zT/asHUrPw8BLLscYtGznsLAnjq5RH9P66E=
golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y=
golang.org/x/sync v0.4.0 h1:zxkM55ReGkDlKSM+Fu41A+zmbZuaPVbGMzvvdUPznYQ=
golang.org/x/sync v0.4.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
Expand Down
10 changes: 4 additions & 6 deletions daggerverse/gale/workflows.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func (w *Workflows) List(
tag Optional[string],
// Branch name to check out. Only one of branch or tag can be used. Precedence is as follows: tag, branch.
branch Optional[string],
// Path to the workflows directory. (default: .github/workflows)
// Path to the workflows' directory. (default: .github/workflows)
workflowsDir Optional[string],
) (string, error) {
// convert workflows list options to repo source options
Expand All @@ -30,11 +30,9 @@ func (w *Workflows) List(
Branch: branch.GetOr(""),
}

// get the repository source working directory from the options
dir := dag.Repo().
Info(opts).
Source().
Directory(workflowsDir.GetOr(".github/workflows"))
// get the repository source working directory from the options -- default value handled by the repo module, so we
// don't need to handle it here.
dir := dag.Repo().Info(opts).WorkflowsDir(RepoInfoWorkflowsDirOpts{WorkflowsDir: workflowsDir.GetOr("")})

// list all entries in the workflows directory
entries, err := dir.Entries(ctx)
Expand Down
22 changes: 16 additions & 6 deletions daggerverse/repo/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (

type Repo struct{}

// RepoInfo represents a repository information.
type RepoInfo struct {
// Info represents a repository information.
type Info struct {
Owner string // Owner of the repository.
Name string // Name of the repository.
NameWithOwner string // NameWithOwner combined version of owner and name. Format: owner/name.
Expand All @@ -34,7 +34,7 @@ func (_ *Repo) Info(
tag Optional[string],
// Branch name to check out. Only one of branch or tag can be used. Precedence is as follows: tag, branch.
branch Optional[string],
) (*RepoInfo, error) {
) (*Info, error) {
// get the repository source from the options
dir, err := getRepoSource(source, repo, tag, branch)
if err != nil {
Expand Down Expand Up @@ -75,7 +75,7 @@ func (_ *Repo) Info(

_, isLocal := source.Get()

return &RepoInfo{
return &Info{
Owner: owner,
Name: repoName,
NameWithOwner: fmt.Sprintf("%s/%s", owner, repoName),
Expand All @@ -90,13 +90,23 @@ func (_ *Repo) Info(
}, nil
}

// WorkflowsDir returns the workflows directory for the repository. If workflowsDir is provided, it's used as the
// returns the workflows directory for the repository, otherwise the default workflows directory .github/workflows is
// returned.
func (ri *Info) WorkflowsDir(
// Path to the workflows' directory. (default: .github/workflows)
workflowsDir Optional[string],
) *Directory {
return ri.Source.Directory(workflowsDir.GetOr(".github/workflows"))
}

// Workdir returns the runner workdir for the repository.
func (ri *RepoInfo) Workdir() string {
func (ri *Info) Workdir() string {
return fmt.Sprintf("/home/runner/work/%s/%s", ri.Name, ri.Name)
}

// Configure configures the container with the repository information.
func (ri *RepoInfo) Configure(_ context.Context, c *Container) (*Container, error) {
func (ri *Info) Configure(_ context.Context, c *Container) (*Container, error) {
workdir := ri.Workdir()
return c.WithMountedDirectory(workdir, ri.Source).
WithWorkdir(workdir).
Expand Down
Loading