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

[WIP] Use envman as a Go lib #103

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
24 changes: 21 additions & 3 deletions export/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ package export
import (
"fmt"
"io"
"log"
"os"
"path/filepath"

envman "github.com/bitrise-io/envman/cli"
"github.com/bitrise-io/go-utils/v2/command"
"github.com/bitrise-io/go-utils/v2/log"
"github.com/bitrise-io/go-utils/v2/pathutil"
"github.com/bitrise-io/go-utils/ziputil"
)
Expand All @@ -21,11 +22,12 @@ const (
// Exporter ...
type Exporter struct {
cmdFactory command.Factory
logger log.Logger
}

// NewExporter ...
func NewExporter(cmdFactory command.Factory) Exporter {
return Exporter{cmdFactory: cmdFactory}
func NewExporter(cmdFactory command.Factory, logger log.Logger) Exporter {
return Exporter{cmdFactory, logger}
}

// ExportOutput is used for exposing values for other steps.
Expand All @@ -40,6 +42,22 @@ func (e *Exporter) ExportOutput(key, value string) error {
return nil
}

type OutputOptions struct {
NoExpand bool
Sensitive bool
Append bool // TODO: what's the point? check what `remove()` does
SkipEmpty bool
}

func (e *Exporter) ExportOutput2(key, value string, opts OutputOptions) error {
envstorePath := os.Getenv("ENVMAN_ENVSTORE_PATH")
if envstorePath == "" {
e.logger.Warnf("ENVMAN_ENVSTORE_PATH is not set, so %s won't be saved to the envstore. This should not happen when a step is part of a Bitrise workflow", key)
return nil
}
return envman.AddEnv(envstorePath, key, value, !opts.NoExpand, !opts.Append, opts.SkipEmpty, opts.Sensitive)
}

// ExportOutputNoExpand works like ExportOutput but does not expand environment variables in the value.
// This can be used when the value is unstrusted or is beyond the control of the step.
func (e *Exporter) ExportOutputNoExpand(key, value string) error {
Expand Down