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

Added prompt for php version for cs:wizard command #1594

Merged
merged 13 commits into from
Oct 9, 2023
9 changes: 8 additions & 1 deletion src/Command/CodeStudio/CodeStudioCiCdVariables.php
shubham-bansal96 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
/**
* @return array<mixed>
*/
public static function getDefaults(?string $cloudApplicationUuid = NULL, ?string $cloudKey = NULL, ?string $cloudSecret = NULL, ?string $projectAccessTokenName = NULL, ?string $projectAccessToken = NULL): array {
public static function getDefaults(?string $cloudApplicationUuid = NULL, ?string $cloudKey = NULL, ?string $cloudSecret = NULL, ?string $projectAccessTokenName = NULL, ?string $projectAccessToken = NULL, ?string $phpVersion = NULL): array {
return [

Check warning on line 20 in src/Command/CodeStudio/CodeStudioCiCdVariables.php

View workflow job for this annotation

GitHub Actions / Mutation Testing

Escaped Mutant for Mutator "ArrayItemRemoval": --- Original +++ New @@ @@ */ public static function getDefaults(?string $cloudApplicationUuid = NULL, ?string $cloudKey = NULL, ?string $cloudSecret = NULL, ?string $projectAccessTokenName = NULL, ?string $projectAccessToken = NULL, ?string $phpVersion = NULL) : array { - return [['key' => 'ACQUIA_APPLICATION_UUID', 'masked' => TRUE, 'protected' => FALSE, 'value' => $cloudApplicationUuid, 'variable_type' => 'env_var'], ['key' => 'ACQUIA_CLOUD_API_TOKEN_KEY', 'masked' => TRUE, 'protected' => FALSE, 'value' => $cloudKey, 'variable_type' => 'env_var'], ['key' => 'ACQUIA_CLOUD_API_TOKEN_SECRET', 'masked' => TRUE, 'protected' => FALSE, 'value' => $cloudSecret, 'variable_type' => 'env_var'], ['key' => 'ACQUIA_GLAB_TOKEN_NAME', 'masked' => TRUE, 'protected' => FALSE, 'value' => $projectAccessTokenName, 'variable_type' => 'env_var'], ['key' => 'ACQUIA_GLAB_TOKEN_SECRET', 'masked' => TRUE, 'protected' => FALSE, 'value' => $projectAccessToken, 'variable_type' => 'env_var'], ['key' => 'PHP_VERSION', 'masked' => FALSE, 'protected' => FALSE, 'value' => $phpVersion, 'variable_type' => 'env_var']]; + return [['key' => 'ACQUIA_CLOUD_API_TOKEN_KEY', 'masked' => TRUE, 'protected' => FALSE, 'value' => $cloudKey, 'variable_type' => 'env_var'], ['key' => 'ACQUIA_CLOUD_API_TOKEN_SECRET', 'masked' => TRUE, 'protected' => FALSE, 'value' => $cloudSecret, 'variable_type' => 'env_var'], ['key' => 'ACQUIA_GLAB_TOKEN_NAME', 'masked' => TRUE, 'protected' => FALSE, 'value' => $projectAccessTokenName, 'variable_type' => 'env_var'], ['key' => 'ACQUIA_GLAB_TOKEN_SECRET', 'masked' => TRUE, 'protected' => FALSE, 'value' => $projectAccessToken, 'variable_type' => 'env_var'], ['key' => 'PHP_VERSION', 'masked' => FALSE, 'protected' => FALSE, 'value' => $phpVersion, 'variable_type' => 'env_var']]; } }
[
'key' => 'ACQUIA_APPLICATION_UUID',
'masked' => TRUE,
Expand Down Expand Up @@ -53,6 +53,13 @@
'value' => $projectAccessToken,
'variable_type' => 'env_var',
],
[
'key' => 'PHP_VERSION',
'masked' => FALSE,

Check warning on line 58 in src/Command/CodeStudio/CodeStudioCiCdVariables.php

View workflow job for this annotation

GitHub Actions / Mutation Testing

Escaped Mutant for Mutator "FalseValue": --- Original +++ New @@ @@ */ public static function getDefaults(?string $cloudApplicationUuid = NULL, ?string $cloudKey = NULL, ?string $cloudSecret = NULL, ?string $projectAccessTokenName = NULL, ?string $projectAccessToken = NULL, ?string $phpVersion = NULL) : array { - return [['key' => 'ACQUIA_APPLICATION_UUID', 'masked' => TRUE, 'protected' => FALSE, 'value' => $cloudApplicationUuid, 'variable_type' => 'env_var'], ['key' => 'ACQUIA_CLOUD_API_TOKEN_KEY', 'masked' => TRUE, 'protected' => FALSE, 'value' => $cloudKey, 'variable_type' => 'env_var'], ['key' => 'ACQUIA_CLOUD_API_TOKEN_SECRET', 'masked' => TRUE, 'protected' => FALSE, 'value' => $cloudSecret, 'variable_type' => 'env_var'], ['key' => 'ACQUIA_GLAB_TOKEN_NAME', 'masked' => TRUE, 'protected' => FALSE, 'value' => $projectAccessTokenName, 'variable_type' => 'env_var'], ['key' => 'ACQUIA_GLAB_TOKEN_SECRET', 'masked' => TRUE, 'protected' => FALSE, 'value' => $projectAccessToken, 'variable_type' => 'env_var'], ['key' => 'PHP_VERSION', 'masked' => FALSE, 'protected' => FALSE, 'value' => $phpVersion, 'variable_type' => 'env_var']]; + return [['key' => 'ACQUIA_APPLICATION_UUID', 'masked' => TRUE, 'protected' => FALSE, 'value' => $cloudApplicationUuid, 'variable_type' => 'env_var'], ['key' => 'ACQUIA_CLOUD_API_TOKEN_KEY', 'masked' => TRUE, 'protected' => FALSE, 'value' => $cloudKey, 'variable_type' => 'env_var'], ['key' => 'ACQUIA_CLOUD_API_TOKEN_SECRET', 'masked' => TRUE, 'protected' => FALSE, 'value' => $cloudSecret, 'variable_type' => 'env_var'], ['key' => 'ACQUIA_GLAB_TOKEN_NAME', 'masked' => TRUE, 'protected' => FALSE, 'value' => $projectAccessTokenName, 'variable_type' => 'env_var'], ['key' => 'ACQUIA_GLAB_TOKEN_SECRET', 'masked' => TRUE, 'protected' => FALSE, 'value' => $projectAccessToken, 'variable_type' => 'env_var'], ['key' => 'PHP_VERSION', 'masked' => true, 'protected' => FALSE, 'value' => $phpVersion, 'variable_type' => 'env_var']]; } }
'protected' => FALSE,

Check warning on line 59 in src/Command/CodeStudio/CodeStudioCiCdVariables.php

View workflow job for this annotation

GitHub Actions / Mutation Testing

Escaped Mutant for Mutator "FalseValue": --- Original +++ New @@ @@ */ public static function getDefaults(?string $cloudApplicationUuid = NULL, ?string $cloudKey = NULL, ?string $cloudSecret = NULL, ?string $projectAccessTokenName = NULL, ?string $projectAccessToken = NULL, ?string $phpVersion = NULL) : array { - return [['key' => 'ACQUIA_APPLICATION_UUID', 'masked' => TRUE, 'protected' => FALSE, 'value' => $cloudApplicationUuid, 'variable_type' => 'env_var'], ['key' => 'ACQUIA_CLOUD_API_TOKEN_KEY', 'masked' => TRUE, 'protected' => FALSE, 'value' => $cloudKey, 'variable_type' => 'env_var'], ['key' => 'ACQUIA_CLOUD_API_TOKEN_SECRET', 'masked' => TRUE, 'protected' => FALSE, 'value' => $cloudSecret, 'variable_type' => 'env_var'], ['key' => 'ACQUIA_GLAB_TOKEN_NAME', 'masked' => TRUE, 'protected' => FALSE, 'value' => $projectAccessTokenName, 'variable_type' => 'env_var'], ['key' => 'ACQUIA_GLAB_TOKEN_SECRET', 'masked' => TRUE, 'protected' => FALSE, 'value' => $projectAccessToken, 'variable_type' => 'env_var'], ['key' => 'PHP_VERSION', 'masked' => FALSE, 'protected' => FALSE, 'value' => $phpVersion, 'variable_type' => 'env_var']]; + return [['key' => 'ACQUIA_APPLICATION_UUID', 'masked' => TRUE, 'protected' => FALSE, 'value' => $cloudApplicationUuid, 'variable_type' => 'env_var'], ['key' => 'ACQUIA_CLOUD_API_TOKEN_KEY', 'masked' => TRUE, 'protected' => FALSE, 'value' => $cloudKey, 'variable_type' => 'env_var'], ['key' => 'ACQUIA_CLOUD_API_TOKEN_SECRET', 'masked' => TRUE, 'protected' => FALSE, 'value' => $cloudSecret, 'variable_type' => 'env_var'], ['key' => 'ACQUIA_GLAB_TOKEN_NAME', 'masked' => TRUE, 'protected' => FALSE, 'value' => $projectAccessTokenName, 'variable_type' => 'env_var'], ['key' => 'ACQUIA_GLAB_TOKEN_SECRET', 'masked' => TRUE, 'protected' => FALSE, 'value' => $projectAccessToken, 'variable_type' => 'env_var'], ['key' => 'PHP_VERSION', 'masked' => FALSE, 'protected' => true, 'value' => $phpVersion, 'variable_type' => 'env_var']]; } }
'value' => $phpVersion,
'variable_type' => 'env_var',
],
];
}

Expand Down
15 changes: 12 additions & 3 deletions src/Command/CodeStudio/CodeStudioWizardCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,15 @@
// But, we specifically need an API Token key-pair of Code Studio.
// So we reauthenticate to be sure we're using the provided credentials.
$this->reAuthenticate($cloudKey, $cloudSecret, $this->cloudCredentials->getBaseUri(), $this->cloudCredentials->getAccountsUri());

$phpVersions = [
'PHP_version_8.1' => "8.1",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yuck. Did you pick these array keys because PHPCS was complaining or something?

'PHP_version_8.2' => "8.2",
];
$project = $this->io->choice('Select a PHP version', array_values($phpVersions), $phpVersions['PHP_version_8.1']);
$project = array_search($project, $phpVersions, TRUE);
$phpVersion = $phpVersions[$project];

$appUuid = $this->determineCloudApplication();

// Get Cloud account.
Expand Down Expand Up @@ -92,7 +101,7 @@
$projectAccessTokenName = 'acquia-codestudio';
$projectAccessToken = $this->createProjectAccessToken($project, $projectAccessTokenName);
$this->updateGitLabProject($project);
$this->setGitLabCiCdVariables($project, $appUuid, $cloudKey, $cloudSecret, $projectAccessTokenName, $projectAccessToken);
$this->setGitLabCiCdVariables($project, $appUuid, $cloudKey, $cloudSecret, $projectAccessTokenName, $projectAccessToken, $phpVersion);

Check warning on line 104 in src/Command/CodeStudio/CodeStudioWizardCommand.php

View workflow job for this annotation

GitHub Actions / Mutation Testing

Escaped Mutant for Mutator "MethodCallRemoval": --- Original +++ New @@ @@ $projectAccessTokenName = 'acquia-codestudio'; $projectAccessToken = $this->createProjectAccessToken($project, $projectAccessTokenName); $this->updateGitLabProject($project); - $this->setGitLabCiCdVariables($project, $appUuid, $cloudKey, $cloudSecret, $projectAccessTokenName, $projectAccessToken, $phpVersion); + $this->createScheduledPipeline($project); $this->io->success(["Successfully configured the Code Studio project!", "This project will now use Acquia's Drupal optimized AutoDevOps to build, test, and deploy your code automatically to Acquia Cloud Platform via CI/CD pipelines.", "You can visit it here:", $project['web_url'], "", "Next, you should use git to push code to your Code Studio project. E.g.,", " git remote add codestudio {$project['http_url_to_repo']}", " git push codestudio"]); $this->io->note(["If the {$account->mail} Cloud account is deleted in the future, this Code Studio project will need to be re-configured."]);
$this->createScheduledPipeline($project);

$this->io->success([
Expand Down Expand Up @@ -161,9 +170,9 @@
return $projectAccessToken['token'];
}

private function setGitLabCiCdVariables(array $project, string $cloudApplicationUuid, string $cloudKey, string $cloudSecret, string $projectAccessTokenName, string $projectAccessToken): void {
private function setGitLabCiCdVariables(array $project, string $cloudApplicationUuid, string $cloudKey, string $cloudSecret, string $projectAccessTokenName, string $projectAccessToken, string $phpVersion): void {
$this->io->writeln("Setting GitLab CI/CD variables for {$project['path_with_namespace']}..");
$gitlabCicdVariables = CodeStudioCiCdVariables::getDefaults($cloudApplicationUuid, $cloudKey, $cloudSecret, $projectAccessTokenName, $projectAccessToken);
$gitlabCicdVariables = CodeStudioCiCdVariables::getDefaults($cloudApplicationUuid, $cloudKey, $cloudSecret, $projectAccessTokenName, $projectAccessToken, $phpVersion);
$gitlabCicdExistingVariables = $this->gitLabClient->projects()
->variables($project['id']);
$gitlabCicdExistingVariablesKeyed = [];
Expand Down
Loading