Skip to content

Commit

Permalink
Use new phpexec package for running php/compoesr
Browse files Browse the repository at this point in the history
  • Loading branch information
nussjustin-hmmh authored and shyim committed Feb 19, 2024
1 parent dac0819 commit d96066e
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 21 deletions.
7 changes: 4 additions & 3 deletions cmd/project/ci.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (

"dario.cat/mergo"
"github.com/FriendsOfShopware/shopware-cli/extension"
"github.com/FriendsOfShopware/shopware-cli/internal/phpexec"
"github.com/FriendsOfShopware/shopware-cli/logging"
"github.com/FriendsOfShopware/shopware-cli/shop"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -55,7 +56,7 @@ var projectCI = &cobra.Command{

logging.FromContext(cmd.Context()).Infof("Installing dependencies using Composer")

composer := exec.CommandContext(cmd.Context(), "composer", "install", "--no-dev", "--no-interaction", "--no-progress", "--optimize-autoloader", "--classmap-authoritative")
composer := phpexec.ComposerCommand(cmd.Context(), "install", "--no-dev", "--no-interaction", "--no-progress", "--optimize-autoloader", "--classmap-authoritative")
composer.Dir = args[0]
composer.Stdin = os.Stdin
composer.Stdout = os.Stdout
Expand Down Expand Up @@ -107,7 +108,7 @@ var projectCI = &cobra.Command{

logging.FromContext(cmd.Context()).Infof("Warmup container cache")

if err := runTransparentCommand(exec.CommandContext(cmd.Context(), "php", path.Join(args[0], "bin", "ci"), "--version")); err != nil { //nolint: gosec
if err := runTransparentCommand(phpexec.PHPCommand(cmd.Context(), path.Join(args[0], "bin", "ci"), "--version")); err != nil { //nolint: gosec
return fmt.Errorf("failed to warmup container cache (php bin/ci --version): %w", err)
}

Expand All @@ -122,7 +123,7 @@ var projectCI = &cobra.Command{
}
}

if err := runTransparentCommand(exec.CommandContext(cmd.Context(), "php", path.Join(args[0], "bin", "ci"), "asset:install")); err != nil { //nolint: gosec
if err := runTransparentCommand(phpexec.PHPCommand(cmd.Context(), path.Join(args[0], "bin", "ci"), "asset:install")); err != nil { //nolint: gosec
return fmt.Errorf("failed to install assets (php bin/ci asset:install): %w", err)
}
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/project/project_admin_build.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package project

import (
"github.com/FriendsOfShopware/shopware-cli/internal/phpexec"
"github.com/FriendsOfShopware/shopware-cli/shop"
"os/exec"

"github.com/FriendsOfShopware/shopware-cli/extension"
"github.com/FriendsOfShopware/shopware-cli/logging"
Expand Down Expand Up @@ -49,7 +49,7 @@ var projectAdminBuildCmd = &cobra.Command{
return nil
}

return runTransparentCommand(commandWithRoot(exec.CommandContext(cmd.Context(), "php", "bin/console", "assets:install"), projectRoot))
return runTransparentCommand(commandWithRoot(phpexec.ConsoleCommand(cmd.Context(), "assets:install"), projectRoot))
},
}

Expand Down
12 changes: 7 additions & 5 deletions cmd/project/project_admin_watch.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package project

import (
"github.com/FriendsOfShopware/shopware-cli/extension"
"github.com/FriendsOfShopware/shopware-cli/shop"
"github.com/spf13/cobra"
"os"
"os/exec"
"path"

"github.com/FriendsOfShopware/shopware-cli/extension"
"github.com/FriendsOfShopware/shopware-cli/internal/phpexec"
"github.com/FriendsOfShopware/shopware-cli/shop"
"github.com/spf13/cobra"
)

var projectAdminWatchCmd = &cobra.Command{
Expand Down Expand Up @@ -35,7 +37,7 @@ var projectAdminWatchCmd = &cobra.Command{
return err
}

if err := runTransparentCommand(commandWithRoot(exec.CommandContext(cmd.Context(), "php", "bin/console", "feature:dump"), projectRoot)); err != nil {
if err := runTransparentCommand(commandWithRoot(phpexec.ConsoleCommand(cmd.Context(), "feature:dump"), projectRoot)); err != nil {
return err
}

Expand All @@ -59,7 +61,7 @@ var projectAdminWatchCmd = &cobra.Command{
}
}

if err := runTransparentCommand(commandWithRoot(exec.CommandContext(cmd.Context(), "php", "bin/console", "-eprod", "framework:schema", "-s", "entity-schema", path.Join(mockDirectory, "entity-schema.json")), projectRoot)); err != nil {
if err := runTransparentCommand(commandWithRoot(phpexec.ConsoleCommand(cmd.Context(), "-eprod", "framework:schema", "-s", "entity-schema", path.Join(mockDirectory, "entity-schema.json")), projectRoot)); err != nil {
return err
}

Expand Down
4 changes: 2 additions & 2 deletions cmd/project/project_storefront_build.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package project

import (
"github.com/FriendsOfShopware/shopware-cli/internal/phpexec"
"github.com/FriendsOfShopware/shopware-cli/shop"
"os/exec"

"github.com/FriendsOfShopware/shopware-cli/extension"
"github.com/FriendsOfShopware/shopware-cli/logging"
Expand Down Expand Up @@ -49,7 +49,7 @@ var projectStorefrontBuildCmd = &cobra.Command{
return nil
}

return runTransparentCommand(commandWithRoot(exec.CommandContext(cmd.Context(), "php", "bin/console", "theme:compile"), projectRoot))
return runTransparentCommand(commandWithRoot(phpexec.ConsoleCommand(cmd.Context(), "theme:compile"), projectRoot))
},
}

Expand Down
14 changes: 8 additions & 6 deletions cmd/project/project_storefront_watch.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package project

import (
"github.com/FriendsOfShopware/shopware-cli/extension"
"github.com/FriendsOfShopware/shopware-cli/shop"
"github.com/spf13/cobra"
"os"
"os/exec"
"strings"

"github.com/FriendsOfShopware/shopware-cli/extension"
"github.com/FriendsOfShopware/shopware-cli/internal/phpexec"
"github.com/FriendsOfShopware/shopware-cli/shop"
"github.com/spf13/cobra"
)

var projectStorefrontWatchCmd = &cobra.Command{
Expand Down Expand Up @@ -35,7 +37,7 @@ var projectStorefrontWatchCmd = &cobra.Command{
return err
}

if err := runTransparentCommand(commandWithRoot(exec.CommandContext(cmd.Context(), "php", "bin/console", "feature:dump"), projectRoot)); err != nil {
if err := runTransparentCommand(commandWithRoot(phpexec.ConsoleCommand(cmd.Context(), "feature:dump"), projectRoot)); err != nil {
return err
}

Expand All @@ -45,11 +47,11 @@ var projectStorefrontWatchCmd = &cobra.Command{
activeOnly = "-v"
}

if err := runTransparentCommand(commandWithRoot(exec.CommandContext(cmd.Context(), "php", "bin/console", "theme:compile", activeOnly), projectRoot)); err != nil {
if err := runTransparentCommand(commandWithRoot(phpexec.ConsoleCommand(cmd.Context(), "theme:compile", activeOnly), projectRoot)); err != nil {
return err
}

if err := runTransparentCommand(commandWithRoot(exec.CommandContext(cmd.Context(), "php", "bin/console", "theme:dump"), projectRoot)); err != nil {
if err := runTransparentCommand(commandWithRoot(phpexec.ConsoleCommand(cmd.Context(), "theme:dump"), projectRoot)); err != nil {
return err
}

Expand Down
6 changes: 3 additions & 3 deletions cmd/project/project_worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import (
"context"
"fmt"
"os"
"os/exec"
"os/signal"
"strconv"
"strings"
"sync"
"syscall"

"github.com/FriendsOfShopware/shopware-cli/internal/phpexec"
"github.com/FriendsOfShopware/shopware-cli/shop"

"github.com/spf13/cobra"
Expand Down Expand Up @@ -54,7 +54,7 @@ var projectWorkerCmd = &cobra.Command{
cancelCtx, cancel := context.WithCancel(cobraCmd.Context())
cancelOnTermination(cancelCtx, cancel)

consumeArgs := []string{"bin/console", "messenger:consume", fmt.Sprintf("--memory-limit=%s", memoryLimit), fmt.Sprintf("--time-limit=%s", timeLimit)}
consumeArgs := []string{"messenger:consume", fmt.Sprintf("--memory-limit=%s", memoryLimit), fmt.Sprintf("--time-limit=%s", timeLimit)}

if queuesToConsume == "" {
if is, _ := shop.IsShopwareVersion(projectRoot, ">=6.5"); is {
Expand All @@ -73,7 +73,7 @@ var projectWorkerCmd = &cobra.Command{
wg.Add(1)
go func(ctx context.Context) {
for {
cmd := exec.CommandContext(cancelCtx, "php", consumeArgs...)
cmd := phpexec.ConsoleCommand(cancelCtx, consumeArgs...)
cmd.Dir = projectRoot
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
Expand Down

0 comments on commit d96066e

Please sign in to comment.