Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 1 addition & 30 deletions .env.dist
Original file line number Diff line number Diff line change
@@ -1,45 +1,16 @@
export PROJECT_PATH=$(realpath .)
## Note: The terminus test site must have some quicksilver scripts enabled
## in order for tests to pass.
## Needed for unit test fixutures
export TERMINUS_PROJECT_ROOT=${PROJECT_PATH}

## This is the site that will be used for testing
export TERMINUS_SITE="ci-terminus-composer"

## This is the site that will be used for testing wordpress commands
export TERMINUS_SITE="terminus-test-site"
export TERMINUS_SITE_WP="terminus-test-site-wordpress"

## This is the site that will be used for testing wordpress network
export TERMINUS_SITE_WP_NETWORK="terminus-test-site-wp-network"

## This is the site that will be used for cloning a test environment on which to run tests
export TERMINUS_ENV="dev"

## this is the org that will be used. The site(s) above need to be in this org
export TERMINUS_ORG="Agency"

## This is the user that will be used for testing Should be attached the token below
export TERMINUS_USER="[email protected]"

## To Autoload your token from your local machine, change the TERMINUS_TOKEN to the following command:
## export TERMINUS_TOKEN=$(cat $HOME/.terminus/cache/tokens/[email protected] | jq -r .token)
export TERMINUS_TOKEN="{TERMINUS TOKEN}"

## this is the folder that terminus will use to store its data during the tests
export TERMINUS_BASE_DIR="/tmp/terminus-data"

## this is the folder that terminus will use to store its plugins during the tests
export TERMINUS_PLUGINS2_DIR="${TERMINUS_BASE_DIR}/plugins"

## this is the folder that terminus will use to store its plugins during the tests
export TERMINUS_PLUGINS_DIR="${TERMINUS_BASE_DIR}/plugins-3.x"

## Used for testing plugins
export TERMINUS_DEPENDENCIES_BASE_DIR="${TERMINUS_BASE_DIR}/dependencies-1"

## this will prevent the tests from creating a test environment for the run
export TERMINUS_TESTING_RUNTIME_ENV=

## this will prevent tests from reinstalling the development packages once a phar is built
export TERMINUS_ON_PHAR_COMPLETE_REINSTALL_COMPOSER_WITH_DEV=1
4 changes: 2 additions & 2 deletions .github/workflows/3x.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ jobs:
name: Checkout & build Phar
steps:
- name: Checkout
uses: actions/checkout@v4
uses: actions/checkout@v3
- name: Save repo content as artifact
uses: actions/upload-artifact@v4
with:
name: full-workspace
path: ${{ github.workspace }}
- name: Full Composer Install
run: composer install --dev
run: composer install
- name: Validate Code
run: composer code:lint
- name: Phar Build
Expand Down
137 changes: 0 additions & 137 deletions RoboFile.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<?php

use CzProject\GitPhp\Git;
use CzProject\GitPhp\GitException;
use Pantheon\Terminus\Config\ConfigAwareTrait;
use Pantheon\Terminus\Helpers\CommandCoverageReport;
use Pantheon\Terminus\Terminus;
Expand Down Expand Up @@ -208,124 +206,6 @@ public function setTerminus(Terminus $terminus): void
$this->terminus = $terminus;
}

/**
* Generates a test commit.
*
* @throws \Pantheon\Terminus\Exceptions\TerminusException
* @throws GitException
*/
public function generateTestCommit()
{
$this->output()->writeln('Getting the Site Repo');
// get the git host and port from terminus
$commandResponse = $this->getTerminus()->execute(
'%s connection:info %s.dev --fields=git_host,git_port --format=json',
[
$this->getProjectPath() . "/terminus.phar",
$this->getSiteName(),
]
);

// check if the command was successful
if ($commandResponse[1] !== 0) {
$this->output()->writeln('Failed to retrieve git host and port');
exit(1);
}

// decode the json response
$gitInfo = json_decode($commandResponse[0], true);
$this->output()->writeln('Retrieved git host and port' . print_r($gitInfo, true));

// check if the git host and port were retrieved
if (!isset($gitInfo['git_host']) || !isset($gitInfo['git_port'])) {
$this->output()->writeln('Failed to retrieve git host and port');
exit(1);
}

// Does the known_hosts file exist?
if (!file_exists(sprintf("%s/.ssh/known_hosts", getenv("HOME")))) {
// if not, create one
touch(sprintf("%s/.ssh/known_hosts", getenv("HOME")));
}

// get the contents of the known_hosts file
$knownHosts = file_get_contents(sprintf("%s/.ssh/known_hosts", getenv("HOME")));
// check if the git host is already in the known_hosts file
if (!str_contains($knownHosts, $gitInfo['git_host'])) {
// if not, add it
$this->output()->writeln('Adding the git host to known hosts file');
$addGitHostToKnownHostsCommand = sprintf(
'ssh-keyscan -p %d %s >> ~/.ssh/known_hosts',
$gitInfo['git_port'],
$gitInfo['git_host']
);
$this->output()->writeln($addGitHostToKnownHostsCommand);
exec($addGitHostToKnownHostsCommand);
}

// checkout the branch related to this test run
$clonedPath = sprintf(
"%s/pantheon-local-copies/%s",
getenv("HOME"),
$this->getSiteName()
);
if (is_dir($clonedPath)) {
// make sure you're working with a clean copy of the repo
exec("rm -rf {$clonedPath}");
}
$this->output()->writeln(sprintf('Cloning the site repository to %s', $clonedPath));
// get the git host and port from terminus
$commandResponse = $this->getTerminus()->execute(
'%s local:clone %s',
[
$this->getProjectPath() . "/terminus.phar",
$this->getSiteName(),
]
);

$response = "";
try {
$git = new Git();
$repo = $git->open($clonedPath);
chdir($clonedPath);
$branches = $repo->getBranches();
if (!in_array($this->getSiteEnv(), $branches)) {
$this->output()->writeln(sprintf('Creating the %s branch', $this->getSiteEnv()));
// Create the branch
$repo->createBranch($this->getSiteEnv());
}
// Check out the branch in question
$repo->checkout($this->getSiteEnv());
// create a text file
$testFilePath = sprintf('%s/test.txt', $clonedPath);
file_put_contents($testFilePath, 'test');
// add the file to the repository
$repo->addFile("test.txt");
// commit the file
$repo->commit('Test commit');
// push the commit
$response = $repo->execute(
'push',
'origin',
$this->getSiteEnv(),
);
} catch (GitException $e) {
$this->output()->writeln(["Git Exception:", $e->getMessage()]);
$this->output()->writeln(print_r($response, true));
exit(1);
} catch (Exception $e) {
$this->output()->writeln($e->getMessage());
$this->output()->writeln(print_r($response, true));
exit(1);
}

// get the last commit
$commit = $repo->getLastCommit();
// output the commit id
$this->output()->writeln($commit->getId());
return $commit->getId();
}

/**
* Returns the absolute path to the project.
*
Expand All @@ -335,21 +215,4 @@ private function getProjectPath(): string
{
return dirname(__FILE__);
}


/**
* @return string
*/
private function getSiteName(): string
{
return getenv('TERMINUS_SITE') ?? 'ci-terminus-composer';
}

/**
* @return string
*/
private function getSiteEnv(): string
{
return getenv('TERMINUS_ENV') ?? 'dev';
}
}
2 changes: 1 addition & 1 deletion bin/terminus
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ if (!getenv('TERMINUS_ALLOW_UNSUPPORTED_NEWER_PHP') && version_compare(PHP_VERSI

// This variable is automatically managed via updateDependenciesversion() in /RoboFile.php,
// which is run after every call to composer update.
$terminusPluginsDependenciesVersion = 'c788000802';
$terminusPluginsDependenciesVersion = 'b17f504e52';

// Cannot use $_SERVER superglobal since that's empty during phpunit testing
// getenv('HOME') isn't set on Windows and generates a Notice.
Expand Down
11 changes: 4 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -110,17 +110,14 @@
"test:behat": [
"SHELL_INTERACTIVE=true TERMINUS_TEST_MODE=1 behat --colors --config tests/config/behat.yml --stop-on-failure --suite=default"
],
"tests:unit": [
"vendor/bin/phpunit --colors=always -c ./phpunit.xml --debug --testsuite unit --do-not-cache-result --verbose --stop-on-failure"
],
"test:short": [
"XDEBUG_MODE=coverage vendor/bin/phpunit --colors=always -c ./phpunit.xml --debug --testsuite functional --group=short --do-not-cache-result --verbose --stop-on-failure"
"XDEBUG_MODE=coverage vendor/bin/phpunit --colors=always -c ./phpunit.xml --debug --group=short --do-not-cache-result --verbose --stop-on-failure"
],
"test:long": [
"XDEBUG_MODE=coverage vendor/bin/phpunit --colors=always -c ./phpunit.xml --debug --testsuite functional --group=long --do-not-cache-result --verbose"
"XDEBUG_MODE=coverage vendor/bin/phpunit --colors=always -c ./phpunit.xml --debug --group=long --do-not-cache-result --verbose"
],
"test:functional": [
"XDEBUG_MODE=coverage vendor/bin/phpunit --colors=always -c ./phpunit.xml --debug --testsuite functional --group=short,long --do-not-cache-result --verbose",
"XDEBUG_MODE=coverage vendor/bin/phpunit --colors=always -c ./phpunit.xml --debug --group=short,long --do-not-cache-result --verbose",
"@coverage"
],
"test:all": [
Expand Down Expand Up @@ -154,7 +151,7 @@
"php-cs-fixer": [
"vendor/bin/php-cs-fixer fix ./src --rules=@PSR12",
"vendor/bin/php-cs-fixer fix ./tests/Functional --rules=@PSR12",
"vendor/bin/php-cs-fixer fix ./tests/Unit --rules=@PSR12"
"vendor/bin/php-cs-fixer fix ./tests/unit_tests --rules=@PSR12"
]
},
"config": {
Expand Down
Loading
Loading