diff --git a/atlasaction/bitbucket.go b/atlasaction/bitbucket.go index e48001f3..5ef3f39b 100644 --- a/atlasaction/bitbucket.go +++ b/atlasaction/bitbucket.go @@ -8,6 +8,7 @@ import ( "fmt" "io" "net/url" + "os" "path/filepath" "strconv" "strings" @@ -77,18 +78,18 @@ func (a *bbPipe) SetOutput(name, value string) { // So the next step can read the outputs using the source command. // e.g: // ```shell - // source $BITBUCKET_PIPE_STORAGE_DIR/outputs.sh + // source .atlas-action/outputs.sh // ``` - // https://support.atlassian.com/bitbucket-cloud/docs/advanced-techniques-for-writing-pipes/#Sharing-information-between-pipes - dir := a.getenv("BITBUCKET_PIPE_STORAGE_DIR") - if out := a.getenv("OUTPUT_DIR"); out != "" { + dir := filepath.Join(a.getenv("BITBUCKET_CLONE_DIR"), ".atlas-action") + if out := a.getenv("ATLAS_OUTPUT_DIR"); out != "" { // The user can set the output directory using - // the OUTPUT_DIR environment variable. + // the ATLAS_OUTPUT_DIR environment variable. // This is useful when the user wants to share the output // with steps run outside the pipe. dir = out } - if dir == "" { + if err := os.MkdirAll(dir, 0700); err != nil { + a.Errorf("failed to create output directory %s: %v", dir, err) return } cmd := a.getenv("ATLAS_ACTION_COMMAND") diff --git a/atlasaction/bitbucket_test.go b/atlasaction/bitbucket_test.go index de69a5a1..8af9e5b1 100644 --- a/atlasaction/bitbucket_test.go +++ b/atlasaction/bitbucket_test.go @@ -12,7 +12,7 @@ import ( func TestBitbucketPipe(t *testing.T) { var ( actions = "actions" - outputs = filepath.Join(actions, "outputs.sh") + outputs = filepath.Join("outputs.sh") ) testscript.Run(t, testscript.Params{ Dir: filepath.Join("testdata", "bitbucket"), @@ -23,6 +23,7 @@ func TestBitbucketPipe(t *testing.T) { } e.Setenv("BITBUCKET_PIPELINE_UUID", "fbfb4205-c666-42ed-983a-d27f47f2aad2") e.Setenv("BITBUCKET_PIPE_STORAGE_DIR", dir) + e.Setenv("BITBUCKET_CLONE_DIR", e.WorkDir) c, err := atlasexec.NewClient(e.WorkDir, "atlas") if err != nil { return err diff --git a/atlasaction/testdata/bitbucket/schema-push.txtar b/atlasaction/testdata/bitbucket/schema-push.txtar index 0bbfa069..29115ce2 100644 --- a/atlasaction/testdata/bitbucket/schema-push.txtar +++ b/atlasaction/testdata/bitbucket/schema-push.txtar @@ -11,6 +11,7 @@ atlas-action schema/push env ATLAS_INPUT_TAG=98765 atlas-action schema/push +exec cat .atlas-action/outputs.sh output outputs.sh -- outputs.sh -- export ATLAS_OUTPUT_SCHEMA_PUSH_LINK="https://test.atlas.ariga/schemas/12345"