Skip to content

Commit

Permalink
atlasaction: change default output dir for Bitbucket (#278)
Browse files Browse the repository at this point in the history
  • Loading branch information
giautm authored Dec 15, 2024
1 parent a769b0a commit b37d783
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
13 changes: 7 additions & 6 deletions atlasaction/bitbucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"fmt"
"io"
"net/url"
"os"
"path/filepath"
"strconv"
"strings"
Expand Down Expand Up @@ -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")
Expand Down
3 changes: 2 additions & 1 deletion atlasaction/bitbucket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions atlasaction/testdata/bitbucket/schema-push.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit b37d783

Please sign in to comment.