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

Pull gitlab / github installer code into new methods #533

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/TestGitHubActions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ jobs:
echo "php_version: 8.1" >> pantheon.yml
echo "drush_version: 10" >> pantheon.yml
echo "database:" >> pantheon.yml
echo " version: 10.4" >> pantheon.yml
echo " version: 10.11" >> pantheon.yml
echo "enforce_https: full+subdomains" >> pantheon.yml
echo "build_step: false" >> pantheon.yml

Expand Down
6 changes: 2 additions & 4 deletions .github/workflows/TestTugboat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,9 @@ jobs:
ddev config --auto
ddev config --php-version "8.1"
ddev config --nodejs-version "18"
ddev config --database=mariadb:10.4
ddev get ddev/ddev-redis --version v1.2.0
ddev get ddev/ddev-elasticsearch --version v0.3.2
ddev start
ddev restart
ddev composer config extra.drupal-scaffold.gitignore true
ddev composer config --json extra.drupal-scaffold.allowed-packages \[\"lullabot/drainpipe\"]
ddev composer config --no-plugins allow-plugins.composer/installers true
Expand Down Expand Up @@ -122,8 +121,7 @@ jobs:
ddev config --auto
ddev config --php-version "8.1"
ddev config --nodejs-version "16"
ddev config --database=mariadb:10.4
ddev start
ddev restart
ddev composer config extra.drupal-scaffold.gitignore true
ddev composer config --json extra.drupal-scaffold.allowed-packages \[\"lullabot/drainpipe\"]
ddev composer config --no-plugins allow-plugins.composer/installers true
Expand Down
2 changes: 1 addition & 1 deletion .tugboat/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ services:
fullPage: false

mariadb:
image: tugboatqa/mariadb:10.4
image: tugboatqa/mariadb:10.11

redis:
image: tugboatqa/redis:6-bullseye
Expand Down
2 changes: 1 addition & 1 deletion scaffold/pantheon/pantheon.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ api_version: 1
web_docroot: true
php_version: 8.0
database:
version: 10.4
version: 10.11
Copy link
Member

Choose a reason for hiding this comment

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

How do we feel about this change going out to all sites? Does this upgrade to several versions work okay on Pantheon deployments?

Copy link
Member

@davereid davereid Apr 25, 2024

Choose a reason for hiding this comment

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

I don't see 10.11 listed on https://docs.pantheon.io/pantheon-yml#specify-a-version-of-mariadb so does this need to be 10.6?

Copy link
Member

Choose a reason for hiding this comment

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

yeah good point, let's change this to 10.6 - currently we only have Pantheon integration for GitLab, but we'd like to have it for GitHub 👍

drush_version: 11
build_step: false
129 changes: 76 additions & 53 deletions src/ScaffoldInstallerPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -220,11 +220,24 @@ private function installDdevCommand(): void
private function installCICommands(): void
{
$scaffoldPath = $this->config->get('vendor-dir') . '/lullabot/drainpipe/scaffold';
$this->installGitlabCI($scaffoldPath);
$this->installGitHubActions($scaffoldPath);
}

/**
* Install GitLab CI configuration if defined in composer.json
*
* @param string $scaffoldPath The path to the scaffold files to copy from.
*/
private function installGitlabCI(string $scaffoldPath): void {
$fs = new Filesystem();
// GitLab
$fs->removeDirectory('./.drainpipe/gitlab');
if (isset($this->extra['drainpipe']['gitlab']) && is_array($this->extra['drainpipe']['gitlab'])) {
if (file_exists('./.ddev/config.yaml')) {

if (!isset($this->extra['drainpipe']['gitlab']) || !is_array($this->extra['drainpipe']['gitlab'])) {
return;
}

if (file_exists('./.ddev/config.yaml')) {
$fs->ensureDirectoryExists('.gitlab/drainpipe');
$fs->copy("$scaffoldPath/gitlab/DDEV.gitlab-ci.yml", ".gitlab/drainpipe/DDEV.gitlab-ci.yml");
$this->io->write("🪠 [Drainpipe] .gitlab/drainpipe/DDEV.gitlab-ci.yml installed");
Expand All @@ -238,66 +251,76 @@ private function installCICommands(): void
$file = "gitlab/$gitlab.gitlab-ci.yml";
if (file_exists("$scaffoldPath/$file")) {
$fs->ensureDirectoryExists('./.drainpipe/gitlab');
$fs->copy("$scaffoldPath/$file", ".drainpipe/$file");
$this->io->write("🪠 [Drainpipe] .drainpipe/$file installed");
$fs->copy("$scaffoldPath/$file", ".drainpipe/$file");
$this->io->write("🪠 [Drainpipe] .drainpipe/$file installed");
}
else {
$this->io->warning("🪠 [Drainpipe] $scaffoldPath/$file does not exist");
}

if ($gitlab === 'Pantheon') {
// @TODO this isn't really specific to GitLab
// .drainpipeignore
if (!file_exists('.drainpipeignore')) {
$fs->copy("$scaffoldPath/pantheon/.drainpipeignore", '.drainpipeignore');
}
else {
$this->io->warning("🪠 [Drainpipe] $scaffoldPath/$file does not exist");
}

if ($gitlab === 'Pantheon') {
// @TODO this isn't really specific to GitLab
// .drainpipeignore
if (!file_exists('.drainpipeignore')) {
$fs->copy("$scaffoldPath/pantheon/.drainpipeignore", '.drainpipeignore');
}
else {
$contents = file_get_contents('./.drainpipeignore');
if (strpos($contents, '/web/sites/default/files') === false) {
$this->io->warning(
sprintf(
'.gitignore does not contain drainpipe ignores. Compare .drainpipeignore in the root of your repository with %s and update as needed.',
"$scaffoldPath/pantheon/.drainpipeignore"
)
);
}
}
// pantheon.yml
if (!file_exists('./pantheon.yml')) {
$fs->copy("$scaffoldPath/pantheon/pantheon.yml", './pantheon.yml');
}
// settings.pantheon.php
if (!file_exists('./web/sites/default/settings.pantheon.php')) {
$fs->copy("$scaffoldPath/pantheon/settings.pantheon.php", './web/sites/default/settings.pantheon.php');
$contents = file_get_contents('./.drainpipeignore');
if (strpos($contents, '/web/sites/default/files') === false) {
$this->io->warning(
sprintf(
'.gitignore does not contain drainpipe ignores. Compare .drainpipeignore in the root of your repository with %s and update as needed.',
"$scaffoldPath/pantheon/.drainpipeignore"
)
);
}
}
// pantheon.yml
if (!file_exists('./pantheon.yml')) {
$fs->copy("$scaffoldPath/pantheon/pantheon.yml", './pantheon.yml');
}
// settings.pantheon.php
if (!file_exists('./web/sites/default/settings.pantheon.php')) {
$fs->copy("$scaffoldPath/pantheon/settings.pantheon.php", './web/sites/default/settings.pantheon.php');
}
}
if (!file_exists('./.gitlab-ci.yml')) {
$fs->copy("$scaffoldPath/gitlab/gitlab-ci.example.yml", './.gitlab-ci.yml');
}
}
// GitHub
if (!file_exists('./.gitlab-ci.yml')) {
$fs->copy("$scaffoldPath/gitlab/gitlab-ci.example.yml", './.gitlab-ci.yml');
}
}

/**
* Install GitLab CI configuration if defined in composer.json
*
* @param string $scaffoldPath The path to the scaffold files to copy from.
*/
private function installGitHubActions(string $scaffoldPath): void {
$fs = new Filesystem();
$fs->removeDirectory('./.github/actions/drainpipe');
if (isset($this->extra['drainpipe']['github']) && is_array($this->extra['drainpipe']['github'])) {
$fs->ensureDirectoryExists('./.github/actions');
$fs->copy("$scaffoldPath/github/actions/common", './.github/actions/drainpipe');
foreach ($this->extra['drainpipe']['github'] as $github) {
if ($github === 'PantheonReviewApps') {
$fs->ensureDirectoryExists('./.github/actions/drainpipe/pantheon');
$fs->ensureDirectoryExists('./.github/workflows');
$fs->copy("$scaffoldPath/github/actions/pantheon", './.github/actions/drainpipe/pantheon');
if (file_exists('./.ddev/config.yaml')) {
$fs->copy("$scaffoldPath/github/workflows/PantheonReviewAppsDDEV.yml", './.github/workflows/PantheonReviewApps.yml');
}
else {
$fs->copy("$scaffoldPath/github/workflows/PantheonReviewApps.yml", './.github/workflows/PantheonReviewApps.yml');
}

if (!isset($this->extra['drainpipe']['github']) || is_array($this->extra['drainpipe']['github'])) {
return;
}

$fs->ensureDirectoryExists('./.github/actions');
$fs->copy("$scaffoldPath/github/actions/common", './.github/actions/drainpipe');
foreach ($this->extra['drainpipe']['github'] as $github) {
if ($github === 'PantheonReviewApps') {
$fs->ensureDirectoryExists('./.github/actions/drainpipe/pantheon');
$fs->ensureDirectoryExists('./.github/workflows');
$fs->copy("$scaffoldPath/github/actions/pantheon", './.github/actions/drainpipe/pantheon');
if (file_exists('./.ddev/config.yaml')) {
$fs->copy("$scaffoldPath/github/workflows/PantheonReviewAppsDDEV.yml", './.github/workflows/PantheonReviewApps.yml');
}
else if ($github === 'ComposerLockDiff') {
$fs->ensureDirectoryExists('./.github/workflows');
$fs->copy("$scaffoldPath/github/workflows/ComposerLockDiff.yml", './.github/workflows/ComposerLockDiff.yml');
else {
$fs->copy("$scaffoldPath/github/workflows/PantheonReviewApps.yml", './.github/workflows/PantheonReviewApps.yml');
}
}
else if ($github === 'ComposerLockDiff') {
$fs->ensureDirectoryExists('./.github/workflows');
$fs->copy("$scaffoldPath/github/workflows/ComposerLockDiff.yml", './.github/workflows/ComposerLockDiff.yml');
}
}

// Tugboat
Expand Down