Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Composer create does not pass "--no-interaction" flag for "post-create-project-cmd" (Craft CMS) #6246

Closed
4 tasks done
mandrasch opened this issue May 25, 2024 · 4 comments
Closed
4 tasks done

Comments

@mandrasch
Copy link
Collaborator

mandrasch commented May 25, 2024

Preliminary checklist

Output of ddev debug test

Expand `ddev debug test` diagnostic information https://gist.github.com/mandrasch/9c5093ae8407a877f0b3859ab7b3842d

Expected Behavior

Craft CMS has the following (https://github.com/craftcms/craft/blob/5.x/composer.json) post-create-project-cmd:

 "scripts": {
    "post-create-project-cmd": [
      "@php -r \"file_exists('.env') || copy('.env.example.dev', '.env');\"",
      "@php -r \"unlink('composer.json');\"",
      "@php -r \"rename('composer.json.default', 'composer.json');\"",
      "@composer dump-autoload -o",
      "@php craft setup/welcome"
    ]
  }

I want to run an install without interaction, therefore I want to use the following

ddev composer create -y --no-scripts --no-interaction craftcms/craft

with DDEV v.1.21.3 (since post-create-cmd is executed now)

Actual Behavior

Executing ddev composer create -y --no-scripts --no-interaction craftcms/craft get's stuck at this screen with a prompt:

image

Console output:

Executing composer command: [composer run-script post-create-project-cmd]
 
> @php -r "file_exists('.env') || copy('.env.example.dev', '.env');"
> @php -r "unlink('composer.json');"
> @php -r "rename('composer.json.default', 'composer.json');"
Generating optimized autoload files
Generated optimized autoload files containing 5444 classes
> @php craft setup/welcome

   ______ .______          ___       _______ .___________.
  /      ||   _  \        /   \     |   ____||           |
 |  ,----'|  |_)  |      /  ^  \    |  |__   `---|  |----`
 |  |     |      /      /  /_\  \   |   __|      |  |
 |  `----.|  |\  \----./  _____  \  |  |         |  |
  \______|| _| `._____/__/     \__\ |__|         |__|
 
     A       N   E   W       I   N   S   T   A   L   L
               ______ .___  ___.      _______.
              /      ||   \/   |     /       |
             |  ,----'|  \  /  |    |   (----`
             |  |     |  |\/|  |     \   \
             |  `----.|  |  |  | .----)   |
              \______||__|  |__| |_______/


Generating an application ID ... done (CraftCMS--e8279XXXX)
Generating a security key ... done (UgSm61wTXXXX)

Welcome to Craft CMS!

Are you ready to begin the setup? (yes|no) [no]:

Steps To Reproduce

  1. Execute:
mkdir craft5-ddev && \ 
  cd craft5-ddev && \
  ddev config \
    --project-type=craftcms \
    --docroot=web \
    --create-docroot \
    --php-version="8.2" \
    --database="mysql:8.0" \
    --nodejs-version="20" && \
  ddev start -y && \
  ddev composer create -y --no-scripts --no-interaction craftcms/craft && \
  ddev craft install/craft \
    --username=admin \
    --password=password123 \
    [email protected] \
    --site-name=Testsite \
    --language=en \
    --site-url='$DDEV_PRIMARY_URL' && \
  echo 'Nice, ready to launch!' && \
  ddev launch
  1. Check the normal composer installation, works with --no-interaction:
ddev ssh
composer create-project craftcms/craft --no-interaction my-craft-project

Anything else?

    protected function checkTty(): void
    {
        // Don't treat this as interactive if it doesn't appear to be a TTY shell
        if ($this->interactive && !Process::isTtySupported()) {
            $this->interactive = false;
        }
    }

So maybe this needs to be changed here in DDEV when --no-interaction is passed? 🤔 (just a guess)
https://github.com/ddev/ddev/blob/70fc4cd7b8b84600c18f0435f2ca82f1dba8b730/cmd/ddev/cmd/composer-create.go#L284C36-L284C41

		stdout, stderr, _ = app.Exec(&ddevapp.ExecOpts{
   		Service: "web",
   		Dir:     app.GetComposerRoot(true, false),
   		RawCmd:  composerCmd,
   		Tty:     isatty.IsTerminal(os.Stdin.Fd()),
   	})

Or this https://github.com/ddev/ddev/blob/70fc4cd7b8b84600c18f0435f2ca82f1dba8b730/cmd/ddev/cmd/composer-create.go#L237C4-L244C1

for _, osarg := range osargs {
   			for _, supportedArg := range supportedArgs {
   				if strings.HasPrefix(osarg, supportedArg) {
   					composerCmd = append(composerCmd, osarg)
   				}
   			}
   		}

needs to be appended to the second command to

// Try to run post-create-project-cmd.
composerCmd = []string{

as well (second guess).

@mandrasch mandrasch changed the title Composer create does not pass "--no-interaction" flag for "post-create-project-cmd" Composer create does not pass "--no-interaction" flag for "post-create-project-cmd" (Craft CMS) May 25, 2024
@mandrasch
Copy link
Collaborator Author

mandrasch commented May 25, 2024

Tried a quick fix via Gitpod (https://ddev.readthedocs.io/en/stable/developers/building-contributing/#open-in-gitpod) for cmd/ddev/cmd/composer-create.go

	if !preserveFlags && composerManifest != nil && composerManifest.HasPostCreateProjectCmdScript() {
	
                               // Try to run post-create-project-cmd.
		composerCmd = []string{
			"composer",
			"run-script",
		}

		// Apply args supported for run-script
		supportedArgs := []string{
			"--dev",
			"--no-dev",
			"-q",
			"--quiet",
			"--ansi",
			"--no-ansi",
			"-n",
			"--no-interaction",
			"--profile",
			"--no-plugins",
			"--no-scripts",
			"-d",
			"--working-dir",
			"--no-cache",
			"-v",
			"-vv",
			"-vvv",
			"--verbose",
		}

		for _, osarg := range osargs {
			for _, supportedArg := range supportedArgs {
				if strings.HasPrefix(osarg, supportedArg) {
					composerCmd = append(composerCmd, osarg)
				}
			}
		}

		composerCmd = append(composerCmd, "post-create-project-cmd")

but got

Executing composer command: [composer run-script --no-scripts --no-interaction post-create-project-cmd]

In RunScriptCommand.php line 124:
                                                                   
  Script "post-create-project-cmd" is not defined in this package
  
  run-script [--timeout TIMEOUT] [--dev] [--no-dev] [-l|--list] [--] [<script> [<args>...]]

for

cd /workspace/
mkdir craft5-ddev && \ 
  cd craft5-ddev && \
  ddev config \
    --project-type=craftcms \
    --docroot=web \
    --create-docroot \
    --php-version="8.2" \
    --database="mysql:8.0" \
    --nodejs-version="20" && \
  ddev start -y && \
  ddev composer create -y --no-scripts --no-interaction craftcms/craft

🤔

@stasadev
Copy link
Member

@tyler36
Copy link
Collaborator

tyler36 commented Jun 14, 2024

@mandrasch This looks like the same class of problem I had with CakePHP (#6300) .
I confirmed @stasadev's #6303 fixes it there and I'm betting it will for this too.

@mandrasch
Copy link
Collaborator Author

mandrasch commented Jun 14, 2024

@tyler36 thanks for information! 👍

I just realized that the problem also seemed to be that --no-scripts wasn't working properly.

The official craft docs (https://craftcms.com/docs/5.x/install.html#quick-start) do not mention --no-interaction and I wasn't aware before what --no-scripts does 🤓

ddev composer create -y --no-scripts "craftcms/craft"

--no-scripts: Skips execution of scripts defined in composer.json.

I briefly tested the new awesome PR by Stas and both variants seem to work properly now without waiting for prompts 🎉

ddev composer create -y --no-scripts "craftcms/craft"
ddev composer create -y --no-interaction "craftcms/craft"

@rfay rfay closed this as completed in ac535e4 Jun 26, 2024
rfay added a commit to ddev-test/ddev that referenced this issue Jun 27, 2024
* docs: Warn about Codespaces (ddev#6321) [skip ci]

Co-authored-by: Matthias Andrasch <[email protected]>

* docs: Improve ddev debug test by offering suggestions early [skip ci] (ddev#6323)

* feat: add support for MariaDB 11.4 LTS, fixes ddev#6061 (ddev#6243)

Co-authored-by: Stanislav Zhuk <[email protected]>

* docs: pacify textlint on mysql/https (ddev#6336) [skip ci]

* docs: revisit WSL Docker Desktop setup instructions (ddev#6330)

* fix: autodownload yarn from corepack, and set cache-folder, fixes ddev#6332 (ddev#6333)

* docs: windows-wsl2-dd needs apt install for ngrok (ddev#6341) [skip ci]

* build: check docker-compose 2.28.1 (ddev#6340) [skip ci]

* fix: use real path to global config location, fixes ddev#6328 (ddev#6329)

* test: stop running nightly tests [skip ci] (ddev#6347)

* test: Improve reliability of TestProcessHooks (intermittent failures), fixes ddev#6313 (ddev#6314)

* fix: Drupal 10 and Drupal 11 settings have migrated, set state_cache (ddev#6346) [skip ci]

Co-authored-by: Stanislav Zhuk <[email protected]>

* build: use IPv4 inside a container, mariadb-client 11.4 for the webserver (ddev#6334) [skip ci]

* fix: pass all valid options to nested commands in `ddev composer create`, fixes ddev#6300, fixes ddev#6246, for ddev#5058 (ddev#6303)

Co-authored-by: Randy Fay <[email protected]>
Co-authored-by: Ralf Koller <[email protected]>

* docs: fix up textlint complaints

* Turn off defaultTerms

* Use exclude properly with textlint for VS Code

* update for additional textlint complaints

* remove redundant empty exclude section

* Try to get textlint/reviewdog to report

---------

Co-authored-by: Matthias Andrasch <[email protected]>
Co-authored-by: hussainweb <[email protected]>
Co-authored-by: Stanislav Zhuk <[email protected]>
Co-authored-by: Ralf Koller <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants