Compare commits

..

1 Commits

Author SHA1 Message Date
552ee5bbd9 Fix branch checking logic
All checks were successful
continuous-integration/drone/pr Build is passing
See https://github.com/go-git/go-git/issues/518 for why this is needed.
2022-08-11 14:14:31 +02:00
17 changed files with 47 additions and 170 deletions

View File

@ -3,17 +3,17 @@ kind: pipeline
name: coopcloud.tech/abra
steps:
- name: make check
image: golang:1.19
image: golang:1.18
commands:
- make check
- name: make build
image: golang:1.19
image: golang:1.18
commands:
- make build
- name: make test
image: golang:1.19
image: golang:1.18
commands:
- make test
@ -45,7 +45,7 @@ steps:
event: tag
- name: release
image: golang:1.19
image: golang:1.18
environment:
GITEA_TOKEN:
from_secret: goreleaser_gitea_token

View File

@ -39,10 +39,8 @@ changelog:
sort: desc
filters:
exclude:
- "^Merge"
- "^Revert"
- "^WIP:"
- "^style:"
- "^test:"
- "^tests:"
- "^chore:"
- "^Revert"

View File

@ -1,11 +1,10 @@
# authors
> If you're looking at this and you hack on `abra` and you're not listed here,
> please do add yourself! This is a community project, let's show some :heart:
> If you're looking at this and you hack on Abra and you're not listed here,
> please do add yourself! This is a community project, let's show
- 3wordchant
- decentral1se
- frando
- kawaiipunk
- knoflook
- roxxers

View File

@ -25,6 +25,21 @@ import (
"github.com/urfave/cli"
)
var localCmd bool
var localCmdFlag = &cli.BoolFlag{
Name: "local, l",
Usage: "Run command locally",
Destination: &localCmd,
}
var remoteUser string
var remoteUserFlag = &cli.StringFlag{
Name: "user, u",
Value: "",
Usage: "User to run command within a service context",
Destination: &remoteUser,
}
var appCmdCommand = cli.Command{
Name: "command",
Aliases: []string{"cmd"},
@ -41,23 +56,21 @@ Example:
abra app cmd example.com app create_user -- me@example.com
`,
ArgsUsage: "<domain> [<service>] <command> [-- <args>]",
ArgsUsage: "<domain> [<service>] <command>",
Flags: []cli.Flag{
internal.DebugFlag,
internal.LocalCmdFlag,
internal.RemoteUserFlag,
localCmdFlag,
remoteUserFlag,
},
BashComplete: autocomplete.AppNameComplete,
Before: internal.SubCommandBefore,
Action: func(c *cli.Context) error {
app := internal.ValidateApp(c)
if internal.LocalCmd && internal.RemoteUser != "" {
internal.ShowSubcommandHelpAndError(c, errors.New("cannot use --local & --user together"))
if localCmd && remoteUser != "" {
internal.ShowSubcommandHelpAndError(c, errors.New("cannot use --local & <user> together"))
}
hasCmdArgs, parsedCmdArgs := parseCmdArgs(c.Args(), internal.LocalCmd)
abraSh := path.Join(config.RECIPES_DIR, app.Recipe, "abra.sh")
if _, err := os.Stat(abraSh); err != nil {
if os.IsNotExist(err) {
@ -66,7 +79,21 @@ Example:
logrus.Fatal(err)
}
if internal.LocalCmd {
var parsedCmdArgs string
var cmdArgsIdx int
var hasCmdArgs bool
for idx, arg := range c.Args() {
if arg == "--" {
cmdArgsIdx = idx
hasCmdArgs = true
}
if hasCmdArgs && idx > cmdArgsIdx {
parsedCmdArgs += fmt.Sprintf("%s ", c.Args().Get(idx))
}
}
if localCmd {
cmdName := c.Args().Get(1)
if err := ensureCommand(abraSh, app.Recipe, cmdName); err != nil {
logrus.Fatal(err)
@ -129,25 +156,6 @@ Example:
},
}
func parseCmdArgs(args []string, isLocal bool) (bool, string) {
var (
parsedCmdArgs string
hasCmdArgs bool
)
if isLocal {
if len(args) > 2 {
return true, fmt.Sprintf("%s ", strings.Join(args[2:], " "))
}
} else {
if len(args) > 3 {
return true, fmt.Sprintf("%s ", strings.Join(args[3:], " "))
}
}
return hasCmdArgs, parsedCmdArgs
}
func ensureCommand(abraSh, recipeName, execCmd string) error {
bytes, err := ioutil.ReadFile(abraSh)
if err != nil {
@ -206,9 +214,9 @@ func runCmdRemote(app config.App, abraSh, serviceName, cmdName, cmdArgs string)
Tty: true,
}
if internal.RemoteUser != "" {
logrus.Debugf("running command with user %s", internal.RemoteUser)
execCreateOpts.User = internal.RemoteUser
if remoteUser != "" {
logrus.Debugf("running command with user %s", remoteUser)
execCreateOpts.User = remoteUser
}
// FIXME: avoid instantiating a new CLI

View File

@ -1,31 +0,0 @@
package app
import (
"strings"
"testing"
)
func TestParseCmdArgs(t *testing.T) {
tests := []struct {
input []string
shouldParse bool
expectedOutput string
}{
// `--` is not parsed when passed in from the command-line e.g. -- foo bar baz
// so we need to eumlate that as missing when testing if bash args are passed in
// see https://git.coopcloud.tech/coop-cloud/organising/issues/336 for more
{[]string{"foo.com", "app", "test"}, false, ""},
{[]string{"foo.com", "app", "test", "foo"}, true, "foo "},
{[]string{"foo.com", "app", "test", "foo", "bar", "baz"}, true, "foo bar baz "},
}
for _, test := range tests {
ok, parsed := parseCmdArgs(test.input, false)
if ok != test.shouldParse {
t.Fatalf("[%s] should not parse", strings.Join(test.input, " "))
}
if parsed != test.expectedOutput {
t.Fatalf("%s does not match %s", parsed, test.expectedOutput)
}
}
}

View File

@ -353,21 +353,6 @@ var AllTagsFlag = &cli.BoolFlag{
Destination: &AllTags,
}
var LocalCmd bool
var LocalCmdFlag = &cli.BoolFlag{
Name: "local, l",
Usage: "Run command locally",
Destination: &LocalCmd,
}
var RemoteUser string
var RemoteUserFlag = &cli.StringFlag{
Name: "user, u",
Value: "",
Usage: "User to run command within a service context",
Destination: &RemoteUser,
}
// SSHFailMsg is a hopefully helpful SSH failure message
var SSHFailMsg = `
Woops, Abra is unable to connect to connect to %s.

View File

@ -65,10 +65,6 @@ func EnsureIPv4(domainName string) (string, error) {
// EnsureDomainsResolveSameIPv4 ensures that domains resolve to the same ipv4 address
func EnsureDomainsResolveSameIPv4(domainName, server string) (string, error) {
if server == "default" || server == "local" {
return "", nil
}
var ipv4 string
domainIPv4, err := EnsureIPv4(domainName)

View File

@ -1,38 +0,0 @@
package test
import (
"log"
"os"
"github.com/sirupsen/logrus"
)
// RmServerAppRecipe deletes the test server / app / recipe.
func RmServerAppRecipe() {
testAppLink := os.ExpandEnv("$HOME/.abra/servers/foo.com")
if err := os.Remove(testAppLink); err != nil {
logrus.Fatal(err)
}
testRecipeLink := os.ExpandEnv("$HOME/.abra/recipes/test")
if err := os.Remove(testRecipeLink); err != nil {
logrus.Fatal(err)
}
}
// MkServerAppRecipe symlinks the test server / app / recipe.
func MkServerAppRecipe() {
RmServerAppRecipe()
testAppDir := os.ExpandEnv("$PWD/../../tests/resources/testapp")
testAppLink := os.ExpandEnv("$HOME/.abra/servers/foo.com")
if err := os.Symlink(testAppDir, testAppLink); err != nil {
log.Fatal(err)
}
testRecipeDir := os.ExpandEnv("$PWD/../../tests/resources/testrecipe")
testRecipeLink := os.ExpandEnv("$HOME/.abra/recipes/test")
if err := os.Symlink(testRecipeDir, testRecipeLink); err != nil {
log.Fatal(err)
}
}

View File

@ -1,6 +1,3 @@
{
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"ignoreDeps": [
"github.com/urfave/cli"
]
"$schema": "https://docs.renovatebot.com/renovate-schema.json"
}

View File

@ -1 +0,0 @@
logs

View File

@ -1,14 +0,0 @@
#!/bin/bash
source ./testfunctions.sh
source ./common.sh
create_server_app_recipe
run_test '$ABRA app cmd foo.com test --local'
run_test '$ABRA app cmd foo.com test --local -- foo'
run_test '$ABRA app cmd foo.com test --local -- foo bar baz'
clean_server_app_recipe

View File

@ -2,16 +2,6 @@
set -e
create_server_app_recipe() {
ln -srf ../resources/testapp ~/.abra/servers/foo.com
ln -srf ../resources/testrecipe ~/.abra/recipes
}
clean_server_app_recipe() {
unlink ~/.abra/servers/foo.com
unlink ~/.abra/recipes/testrecipe
}
function init() {
ABRA="$(pwd)/../../abra"
INSTALLER_URL="https://git.coopcloud.tech/coop-cloud/abra/raw/branch/main/scripts/installer/installer"

View File

@ -16,7 +16,7 @@ run_test () {
echo $logfile
}
testScripts=("app.sh" "autocomplete.sh" "catalogue.sh" "install.sh" "recipe.sh" "records.sh" "server.sh", "cmd.sh")
testScripts=("app.sh" "autocomplete.sh" "catalogue.sh" "install.sh" "recipe.sh" "records.sh" "server.sh")
for i in "${testScripts[@]}"; do
cmd="./$i $res_dir${i/sh/log}"

View File

@ -1 +0,0 @@
TYPE=test

View File

@ -1 +0,0 @@
.

View File

@ -1,5 +0,0 @@
test(){
echo "1: $1"
echo "2: $2"
echo "all: $@"
}

View File

@ -1,5 +0,0 @@
---
version: "3.8"
services:
app: []