-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: fixed working-directory in tests
- Loading branch information
Showing
17 changed files
with
112 additions
and
178 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package atlasaction | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"fmt" | ||
"os" | ||
|
||
"ariga.io/atlas-action/atlasaction/cloud" | ||
"github.com/alecthomas/kong" | ||
) | ||
|
||
func Main(version, commit string) int { | ||
atlasPath := "atlas" | ||
if p := os.Getenv("ATLAS_PATH"); p != "" { | ||
// The environment can provide the path to the atlas-cli binary. | ||
// | ||
// This is useful when running the action in a Docker container, | ||
// and the user can mount the atlas-cli binary in the container and set the | ||
// ATLAS_PATH environment variable to the path of the binary. | ||
atlasPath = p | ||
} | ||
act, err := New( | ||
WithAtlasPath(atlasPath), | ||
WithCloudClient(cloud.New), | ||
WithVersion(version), | ||
) | ||
if err != nil { | ||
fmt.Fprintf(os.Stderr, "failed to run action in the current environment: %s\n", err) | ||
os.Exit(1) | ||
} | ||
cli := kong.Parse( | ||
&RunActionCmd{}, | ||
kong.BindTo(context.Background(), (*context.Context)(nil)), | ||
kong.Vars{ | ||
"version": fmt.Sprintf("atlas-action version %s-%s\n", version, commit), | ||
}, | ||
) | ||
if err := cli.Run(act); err != nil { | ||
if uerr := errors.Unwrap(err); uerr != nil { | ||
err = uerr | ||
} | ||
act.Fatalf(err.Error()) | ||
} | ||
return 0 | ||
} | ||
|
||
// RunActionCmd is a command to run one of the Atlas GitHub Actions. | ||
type RunActionCmd struct { | ||
Action string `help:"Command to run" required:"" env:"ATLAS_ACTION"` | ||
Version kong.VersionFlag `name:"version" help:"Print version information and quit"` | ||
} | ||
|
||
func (r *RunActionCmd) Run(ctx context.Context, a *Actions) error { | ||
_ = os.Setenv("ATLAS_ACTION_COMMAND", r.Action) | ||
defer func() { | ||
_ = os.Unsetenv("ATLAS_ACTION_COMMAND") | ||
}() | ||
return a.Run(ctx, r.Action) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.