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

ENH Support for CMS 6 #81

Merged
merged 1 commit into from
Feb 22, 2024
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
28 changes: 28 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,38 @@ runs:
echo "cat __inputs.yml"
cat __inputs.yml

- name: Fetch branches
id: fetch-branches
shell: bash
run: |
# Gets all branches from GitHub API
# https://docs.github.com/en/rest/branches/branches?apiVersion=2022-11-28#list-branches
RESP_CODE=$(curl -w %{http_code} -s -o __installer_branches.json \
-X GET "https://api.github.com/repos/silverstripe/silverstripe-installer/branches?per_page=100" \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ github.token }}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
)
if [[ $RESP_CODE != "200" ]]; then
echo "Unable to read list of branches - HTTP response code was $RESP_CODE"
exit 1
fi

- name: Run php script
id: php-script
shell: bash
run: |
MATRIX_JSON=$(php ${{ github.action_path }}/action.php)
echo "MATRIX_JSON: $MATRIX_JSON"
echo "matrix=${MATRIX_JSON}" >> "$GITHUB_OUTPUT"

- name: Delete temporary files
shell: bash
if: always()
run: |
if [[ -f __installer_branches.json ]]; then
rm __installer_branches.json
fi
if [[ -f __inputs.yml ]]; then
rm __inputs.yml
fi
44 changes: 44 additions & 0 deletions consts.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@
'8.2',
'8.3',
],
'6' => [
'8.1',
'8.2',
'8.3',
Comment on lines +45 to +47
Copy link
Member

Choose a reason for hiding this comment

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

We'll only support 8.3 to start with - but I guess we can remove this when we bump the PHP dep so no change required for this just yet, just thinking aloud.

],
];

const DB_MYSQL_57 = 'mysql57';
Expand Down Expand Up @@ -162,6 +167,45 @@
'silverstripe-versioned-admin' => '2',
'vendor-plugin' => '2',
],
'6' => [
'MinkFacebookWebDriver' => '3',
'recipe-authoring-tools' => '3',
'recipe-blog' => '3',
'recipe-ccl' => '4',
'recipe-cms' => '6',
'recipe-collaboration' => '3',
'recipe-content-blocks' => '4',
'recipe-core' => '6',
'recipe-form-building' => '3',
'recipe-kitchen-sink' => '6',
'recipe-plugin' => '3',
'recipe-reporting-tools' => '3',
'recipe-services' => '3',
'recipe-testing' => '4',
'silverstripe-installer' => '6',
'silverstripe-admin' => '3',
'silverstripe-asset-admin' => '3',
'silverstripe-assets' => '3',
'silverstripe-behat-extension' => '6',
'silverstripe-campaign-admin' => '3',
'silverstripe-cms' => '6',
'silverstripe-errorpage' => '3',
'silverstripe-event-dispatcher' => '2',
'silverstripe-framework' => '6',
'silverstripe-frameworktest' => '2',
'silverstripe-graphql' => '6',
'silverstripe-login-forms' => '6',
'silverstripe-mimevalidator' => '4',
'silverstripe-registry' => '4',
'silverstripe-reports' => '6',
'silverstripe-serve' => '4',
'silverstripe-session-manager' => '3',
'silverstripe-siteconfig' => '6',
'silverstripe-testsession' => '4',
'silverstripe-versioned' => '3',
'silverstripe-versioned-admin' => '3',
'vendor-plugin' => '3',
],
];

// use hardcoded.php to bulk update update this after creating a .cow.pat.json
Expand Down
35 changes: 32 additions & 3 deletions job_creator.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ class JobCreator
/**
* Get the correct version of silverstripe/installer to include for the given repository and branch
*/
public function getInstallerVersion(): string
public function getInstallerVersion(
// the following is only used for unit testing
string $installerBranchesJson = ''
): string
{
$this->repoName = explode('/', $this->githubRepository)[1];
// repo should not use installer
Expand Down Expand Up @@ -93,18 +96,44 @@ public function getInstallerVersion(): string
// fallback to use the next-minor or latest-minor version of installer
$installerVersions = array_keys(INSTALLER_TO_PHP_VERSIONS);
$installerVersions = array_filter($installerVersions, fn($version) => substr($version, 0, 1) === $cmsMajor);

if (preg_match('#^[1-9]+[0-9]*$#', $branch)) {
// next-minor e.g. 4
return $cmsMajor . '.x-dev';
} else {
// current-minor e.g. 4.11
// remove major versions
$installerVersions = array_diff($installerVersions, ['4', '5', '6']);
$installerVersions = array_diff($installerVersions, ['4', '5', '6', '7', '8', '9']);
// get the minor portions of the verisons e.g. [9, 10, 11]
$minorPortions = array_map(fn($portions) => (int) explode('.', $portions)[1], $installerVersions);
if (count($minorPortions) === 0) {
return $cmsMajor . '.x-dev';
}
sort($minorPortions);
$minorPortion = $minorPortions[count($minorPortions) - 1];
$installerVersion = $cmsMajor . '.' . $minorPortion;

// It's normal for new major versions branches to exist a year or more before the first release
// The corresponding minor version branch will not exist at this time
// Check that the minor version of the installer branches exists, if not, fallback to using the major
if ($installerBranchesJson) {
// this if for unit testing
$json = json_decode($installerBranchesJson);
} else {
// this file is created in action.yml
if (!file_exists('__installer_branches.json')) {
throw new Exception('__installer_branches.json was not found');
}
$json = json_decode(file_get_contents('__installer_branches.json'));
}
$branches = array_column($json, 'name');
// using array_filter() instead of in_array() to ensure we get a strict equality check
// e.g. '6' and '6.0' are not equal
$branchExists = count(array_filter($branches, fn($branch) => $branch === $installerVersion));
if (!$branchExists) {
return $cmsMajor . '.x-dev';
}

if ($isReleaseBranch) {
return 'dev-' . $installerVersion . '-release';
}
Expand Down Expand Up @@ -394,7 +423,7 @@ private function createPhpunitJobs(
'phpunit' => true,
'phpunit_suite' => $suite,
]);
} elseif ($this->getCmsMajor() === '5') {
} else {
// phpunit tests for cms 5 are run on php 8.1, 8.2 or 8.3 and mysql 8.0 or mariadb
$phpToDB = $this->generatePhpToDBMap();
foreach ($phpToDB as $php => $db) {
Expand Down
Loading
Loading