Skip to content

Commit

Permalink
Merge pull request #18 from frantjc/use-github-api
Browse files Browse the repository at this point in the history
Use GitHub api
  • Loading branch information
frantjc authored Apr 2, 2023
2 parents 2b13ce3 + 4381f91 commit 964b65f
Show file tree
Hide file tree
Showing 23 changed files with 547 additions and 256 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
- name: Set path
run: echo $RUNNER_TEMP >> $GITHUB_PATH
- name: Run forge use remote
run: forge use frantjc/forge/testdata/actions/docker@main
run: forge use frantjc/forge/testdata/actions/docker@${{ github.sha }}
- name: Run forge use local
run: forge use ./testdata/actions/node
- name: Run forge use dockerfile
Expand Down
2 changes: 1 addition & 1 deletion command/prune.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func NewPrune() *cobra.Command {
SilenceErrors: true,
SilenceUsage: true,
RunE: func(cmd *cobra.Command, args []string) error {
return os.RemoveAll(hostfs.ActionsCache)
return os.RemoveAll(hostfs.CacheHome)
},
}

Expand Down
5 changes: 4 additions & 1 deletion command/use.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ func NewUse() *cobra.Command {
if err != nil {
globalContext = githubactions.NewGlobalContextFromEnv()
}
globalContext.StepsContext[id] = &githubactions.StepContext{}

if verbosity, _ := strconv.Atoi(cmd.Flag("verbose").Value.String()); verbosity > 0 {
globalContext.SecretsContext[githubactions.SecretActionsStepDebug] = githubactions.SecretDebugValue
Expand All @@ -64,7 +65,9 @@ func NewUse() *cobra.Command {

if outputs {
defer func() {
_ = json.NewEncoder(cmd.OutOrStdout()).Encode(globalContext.StepsContext[id].Outputs)
if outputs := globalContext.StepsContext[id].Outputs; len(outputs) > 0 {
_ = json.NewEncoder(cmd.OutOrStdout()).Encode(outputs)
}
}()
}

Expand Down
77 changes: 0 additions & 77 deletions envconv/dot_env.go

This file was deleted.

21 changes: 12 additions & 9 deletions forgeactions/env_files.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"strings"

"github.com/frantjc/forge"
"github.com/frantjc/forge/envconv"
"github.com/frantjc/forge/githubactions"
"golang.org/x/exp/maps"
)
Expand All @@ -18,7 +17,10 @@ func SetGlobalContextFromEnvFiles(ctx context.Context, globalContext *githubacti
}

func (m *Mapping) SetGlobalContextFromEnvFiles(ctx context.Context, globalContext *githubactions.GlobalContext, step string, container forge.Container) error {
_ = forge.LoggerFrom(ctx)
var (
_ = forge.LoggerFrom(ctx)
errs []error
)
globalContext = m.ConfigureGlobalContext(globalContext)

rc, err := container.CopyFrom(ctx, m.GitHubPath)
Expand All @@ -39,25 +41,26 @@ func (m *Mapping) SetGlobalContextFromEnvFiles(ctx context.Context, globalContex
//nolint:gocritic
switch header.Typeflag {
case tar.TypeReg:

switch {
case strings.HasSuffix(m.GitHubOutputPath, header.Name):
outputs, err := envconv.MapFromReader(io.LimitReader(r, header.Size))
outputs, err := githubactions.ParseEnvFile(r)
if err != nil {
return err
errs = append(errs, err)
continue
}

if _, ok := globalContext.StepsContext[step]; !ok {
if stepContext, ok := globalContext.StepsContext[step]; !ok || stepContext.Outputs == nil {
globalContext.StepsContext[step] = &githubactions.StepContext{
Outputs: outputs,
}
} else {
maps.Copy(globalContext.StepsContext[step].Outputs, outputs)
}
case strings.HasSuffix(m.GitHubStatePath, header.Name):
outputs, err := envconv.MapFromReader(io.LimitReader(r, header.Size))
outputs, err := githubactions.ParseEnvFile(r)
if err != nil {
return err
errs = append(errs, err)
continue
}

for k, v := range outputs {
Expand All @@ -67,5 +70,5 @@ func (m *Mapping) SetGlobalContextFromEnvFiles(ctx context.Context, globalContex
}
}

return rc.Close()
return errors.Join(append(errs, rc.Close())...)
}
18 changes: 9 additions & 9 deletions forgeactions/mapping.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package forgeactions

type Mapping struct {
ActionPath string `json:"action_path,omitempty"`
Workspace string `json:"workspace,omitempty"`
RunnerToolCache string `json:"runner_tool_cache,omitempty"`
RunnerTemp string `json:"runner_temp,omitempty"`
GitHubPath string `json:"git_hub_path,omitempty"`
GitHubPathPath string `json:"git_hub_path_path,omitempty"`
GitHubEnvPath string `json:"git_hub_env_path,omitempty"`
GitHubOutputPath string `json:"git_hub_output_path,omitempty"`
GitHubStatePath string `json:"git_hub_state_path,omitempty"`
ActionPath string
Workspace string
RunnerToolCache string
RunnerTemp string
GitHubPath string
GitHubPathPath string
GitHubEnvPath string
GitHubOutputPath string
GitHubStatePath string
}
2 changes: 2 additions & 0 deletions forgeactions/workflow_command_streams.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ func (w *WorkflowCommandWriter) Callback(wc *githubactions.WorkflowCommand) []by
w.GlobalContext.StepsContext[w.ID] = &githubactions.StepContext{
Outputs: map[string]string{},
}
} else if w.GlobalContext.StepsContext[w.ID].Outputs == nil {
w.GlobalContext.StepsContext[w.ID].Outputs = make(map[string]string)
}

w.GlobalContext.StepsContext[w.ID].Outputs[wc.GetName()] = wc.Value
Expand Down
2 changes: 1 addition & 1 deletion forgeconcourse/mapping.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package forgeconcourse

type Mapping struct {
RootPath string `json:"root_path,omitempty"`
RootPath string
}
78 changes: 0 additions & 78 deletions githubactions/checkout.go

This file was deleted.

9 changes: 0 additions & 9 deletions githubactions/checkout_opts.go

This file was deleted.

Loading

0 comments on commit 964b65f

Please sign in to comment.