fix: abra app new checks out latest version #412

Merged
decentral1se merged 1 commits from new-deploy-checkout into main 2024-06-21 13:54:10 +00:00
4 changed files with 42 additions and 5 deletions

View File

@ -10,7 +10,6 @@ import (
"coopcloud.tech/abra/pkg/config"
"coopcloud.tech/abra/pkg/formatter"
"coopcloud.tech/abra/pkg/jsontable"
"coopcloud.tech/abra/pkg/recipe"
recipePkg "coopcloud.tech/abra/pkg/recipe"
"coopcloud.tech/abra/pkg/secret"
"github.com/AlecAivazis/survey/v2"
@ -78,9 +77,29 @@ var appNewCommand = cli.Command{
}
}
if c.Args().Get(1) == "" {
if err := recipePkg.EnsureLatest(recipe.Name); err != nil {
var version string
recipeVersions, err := recipePkg.GetRecipeVersions(recipe.Name, internal.Offline)
if err != nil {
logrus.Fatal(err)
}
// NOTE(d1): determine whether recipe versions exist or not and check
decentral1se marked this conversation as resolved Outdated
Outdated
Review

Can you add a comment (above) this if statement explaing this case and the block inside? It not quite clear to me by just reading the code

Can you add a comment (above) this if statement explaing this case and the block inside? It not quite clear to me by just reading the code
// out the latest version or current HEAD
if len(recipeVersions) > 0 {
latest := recipeVersions[len(recipeVersions)-1]
for tag := range latest {
version = tag
}
if err := recipePkg.EnsureVersion(recipe.Name, version); err != nil {
logrus.Fatal(err)
}
} else {
if err := recipePkg.EnsureLatest(recipe.Name); err != nil {
logrus.Fatal(err)
}
}
} else {
if err := recipePkg.EnsureVersion(recipe.Name, c.Args().Get(1)); err != nil {
logrus.Fatal(err)
@ -212,7 +231,7 @@ func createSecrets(cl *dockerClient.Client, secretsConfig map[string]secret.Secr
}
// ensureDomainFlag checks if the domain flag was used. if not, asks the user for it/
func ensureDomainFlag(recipe recipe.Recipe, server string) error {
func ensureDomainFlag(recipe recipePkg.Recipe, server string) error {
if internal.Domain == "" && !internal.NoInput {
prompt := &survey.Input{
Message: "Specify app domain",

View File

@ -945,6 +945,7 @@ func GetRecipeVersions(recipeName string, offline bool) (RecipeVersions, error)
if err != nil {
return versions, err
}
sortRecipeVersions(versions)
logrus.Debugf("collected %s for %s", versions, recipeName)

View File

@ -37,6 +37,15 @@ teardown(){
}
@test "create new app" {
_fetch_recipe
decentral1se marked this conversation as resolved Outdated

Better approach in coop-cloud/abra#414! Will merge this as-is and rebase this new PR on top of the changes in that PR. Looks like things are coming together for not having constantly broken integration tests...

Better approach in https://git.coopcloud.tech/coop-cloud/abra/pulls/414! Will merge this as-is and rebase this new PR on top of the changes in that PR. Looks like things are coming together for not having constantly broken integration tests...
_latest_tag
run git -C "$ABRA_DIR/recipes/$TEST_RECIPE" checkout $LATEST_TAG
assert_success
_latest_hash
_reset_recipe
run $ABRA app new "$TEST_RECIPE" \
--no-input \
--server "$TEST_SERVER" \
@ -44,8 +53,8 @@ teardown(){
assert_success
assert_exists "$ABRA_DIR/servers/$TEST_SERVER/$TEST_APP_DOMAIN.env"
run git -C "$ABRA_DIR/recipes/$TEST_RECIPE" status
assert_output --partial "up to date"
run git -C "$ABRA_DIR/recipes/$TEST_RECIPE" log -1
assert_output --partial "$LATEST_HASH"
}
@test "create new app with version" {

View File

@ -35,3 +35,11 @@ _set_git_author() {
run git -C "$ABRA_DIR/recipes/$TEST_RECIPE" config --local user.name test
assert_success
}
_latest_tag() {
export LATEST_TAG=$(git -C "$ABRA_DIR/recipes/$TEST_RECIPE" describe --abbrev=0)
}
_latest_hash() {
export LATEST_HASH=$(git -C "$ABRA_DIR/recipes/$TEST_RECIPE" log -1 --pretty=format:%h)
}