Compare commits

...

14 Commits
1.5.0 ... 1

Author SHA1 Message Date
Steve Boyd acb067fdc2
MNT Use gha-dispatch-ci (#32) 2023-03-23 14:15:48 +13:00
Steve Boyd e5dceb4546
API Update deprecations (#27)
* ENH Update deprecation messages

* API Update deprecations
2022-10-25 17:23:26 +13:00
Steve Boyd c4e8728ff9 Merge branch '1.7' into 1 2022-08-03 14:32:59 +12:00
Guy Sartorelli da89aa5dcc
Merge pull request #24 from creative-commoners/pulls/1.7/standardise-modules
MNT Standardise modules
2022-08-02 15:32:19 +12:00
Steve Boyd 4ec7b15347 MNT Standardise modules 2022-08-01 10:45:07 +12:00
Steve Boyd 2f74096ea4 Merge branch '1.7' into 1 2022-07-26 16:42:52 +12:00
Guy Sartorelli 2175573ca5
Merge pull request #23 from creative-commoners/pulls/1.7/module-standards
MNT Use GitHub Actions CI
2022-07-15 17:01:25 +12:00
Steve Boyd f68a4cc2be MNT Use GitHub Actions CI 2022-07-06 14:02:51 +12:00
Andrew Paxley 301daf2437
FIX Only write composer.json if there are changes (#21)
FIX Only write composer.json if there are changes
2022-05-10 09:40:14 +12:00
Guy Sartorelli 8a77da94d1
Merge pull request #20 from creative-commoners/pulls/1/php81
ENH PHP 8.1 compatibility
2022-04-22 16:16:42 +12:00
Steve Boyd 02f5008b46 ENH PHP 8.1 compatibility 2022-04-13 17:43:58 +12:00
Jordi Boggiano a76509e8a6
FIX Remove unnecessary methods from trait, adds Composer 2.3 compatibility (#19) 2022-04-01 21:25:06 +13:00
Steve Boyd 102c2bc100
Remove build status badge 2021-01-21 16:06:24 +13:00
Steve Boyd 68c7402854
Update build status badge 2021-01-21 16:05:34 +13:00
9 changed files with 100 additions and 59 deletions

11
.github/workflows/ci.yml vendored Normal file
View File

@ -0,0 +1,11 @@
name: CI
on:
push:
pull_request:
workflow_dispatch:
jobs:
ci:
name: CI
uses: silverstripe/gha-ci/.github/workflows/ci.yml@v1

16
.github/workflows/dispatch-ci.yml vendored Normal file
View File

@ -0,0 +1,16 @@
name: Dispatch CI
on:
# At 12:00 PM UTC, only on Friday and Saturday
schedule:
- cron: '0 12 * * 5,6'
jobs:
dispatch-ci:
name: Dispatch CI
# Only run cron on the silverstripe account
if: (github.event_name == 'schedule' && github.repository_owner == 'silverstripe') || (github.event_name != 'schedule')
runs-on: ubuntu-latest
steps:
- name: Dispatch CI
uses: silverstripe/gha-dispatch-ci@v1

17
.github/workflows/keepalive.yml vendored Normal file
View File

@ -0,0 +1,17 @@
name: Keepalive
on:
workflow_dispatch:
# The 4th of every month at 10:50am UTC
schedule:
- cron: '50 10 4 * *'
jobs:
keepalive:
name: Keepalive
# Only run cron on the silverstripe account
if: (github.event_name == 'schedule' && github.repository_owner == 'silverstripe') || (github.event_name != 'schedule')
runs-on: ubuntu-latest
steps:
- name: Keepalive
uses: silverstripe/gha-keepalive@v1

View File

@ -1,4 +1,7 @@
# SilverStripe recipe-plugin # Silverstripe recipe-plugin
[![CI](https://github.com/silverstripe/recipe-plugin/actions/workflows/ci.yml/badge.svg)](https://github.com/silverstripe/recipe-plugin/actions/workflows/ci.yml)
[![Silverstripe supported module](https://img.shields.io/badge/silverstripe-supported-0071C4.svg)](https://www.silverstripe.org/software/addons/silverstripe-commercially-supported-module-list/)
## Introduction ## Introduction

View File

@ -25,7 +25,8 @@
"composer-plugin-api": "^1.1 || ^2" "composer-plugin-api": "^1.1 || ^2"
}, },
"require-dev": { "require-dev": {
"composer/composer": "^1.2 || 2" "composer/composer": "^1.2 || 2",
"squizlabs/php_codesniffer": "^3.5"
}, },
"minimum-stability": "dev" "minimum-stability": "dev"
} }

View File

@ -1,2 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<ruleset><rule ref="PSR2" /></ruleset> <ruleset name="SilverStripe">
<description>CodeSniffer ruleset for SilverStripe coding conventions.</description>
<file>src</file>
<!-- base rules are PSR-12 -->
<rule ref="PSR12" >
<exclude name="PSR1.Methods.CamelCapsMethodName.NotCamelCaps" />
<exclude name="PSR1.Files.SideEffects.FoundWithSymbols" />
</rule>
</ruleset>

View File

@ -14,31 +14,6 @@ use Symfony\Component\Console\Output\OutputInterface;
trait RecipeCommandBehaviour trait RecipeCommandBehaviour
{ {
/**
* Gets the application instance for this command.
*
* @return Application An Application instance
*/
public abstract function getApplication();
/**
* @param bool $required
* @param bool|null $disablePlugins
* @throws \RuntimeException
* @return Composer
*/
public abstract function getComposer($required = true, $disablePlugins = null);
/**
* Removes the cached composer instance
*/
public abstract function resetComposer();
/**
* @return IOInterface
*/
abstract public function getIO();
/** /**
* @param OutputInterface $output * @param OutputInterface $output
* @param string $recipe * @param string $recipe
@ -128,17 +103,17 @@ trait RecipeCommandBehaviour
} }
// Existing version is already a ^1.0.0 or ~1.0.0 constraint // Existing version is already a ^1.0.0 or ~1.0.0 constraint
if (preg_match('#^[~^]#', $existingVersion)) { if (preg_match('#^[~^]#', $existingVersion ?? '')) {
return $existingVersion; return $existingVersion;
} }
// Existing version is already a dev constraint // Existing version is already a dev constraint
if (stristr($existingVersion, 'dev') !== false) { if (stristr($existingVersion ?? '', 'dev') !== false) {
return $existingVersion; return $existingVersion;
} }
// Numeric-only version maps to semver constraint // Numeric-only version maps to semver constraint
if (preg_match('#^([\d.]+)$#', $existingVersion)) { if (preg_match('#^([\d.]+)$#', $existingVersion ?? '')) {
return "^{$existingVersion}"; return "^{$existingVersion}";
} }

View File

@ -16,6 +16,10 @@ use RegexIterator;
class RecipeInstaller extends LibraryInstaller class RecipeInstaller extends LibraryInstaller
{ {
/**
* @var bool
*/
private $hasWrittenFiles = false;
public function __construct(IOInterface $io, Composer $composer) public function __construct(IOInterface $io, Composer $composer)
{ {
@ -61,19 +65,21 @@ class RecipeInstaller extends LibraryInstaller
$relativePath = $this->installProjectFile($sourceRoot, $destinationRoot, $path, $installedFiles); $relativePath = $this->installProjectFile($sourceRoot, $destinationRoot, $path, $installedFiles);
// Add file to installed (even if already exists) // Add file to installed (even if already exists)
if (!in_array($relativePath, $installedFiles)) { if (!in_array($relativePath, $installedFiles ?? [])) {
$installedFiles[] = $relativePath; $installedFiles[] = $relativePath;
} }
} }
// If any files are written, modify composer.json with newly installed files // If any files are written, modify composer.json with newly installed files
if ($installedFiles) { if ($this->hasWrittenFiles) {
sort($installedFiles); sort($installedFiles);
if (!isset($composerData['extra'])) { if (!isset($composerData['extra'])) {
$composerData['extra'] = []; $composerData['extra'] = [];
} }
$composerData['extra'][$registrationKey] = $installedFiles; $composerData['extra'][$registrationKey] = $installedFiles;
$composerFile->write($composerData); $composerFile->write($composerData);
// Reset the variable so that we can try this trick again later
$this->hasWrittenFiles = false;
} }
} }
@ -87,15 +93,15 @@ class RecipeInstaller extends LibraryInstaller
protected function installProjectFile($sourceRoot, $destinationRoot, $sourcePath, $installedFiles) protected function installProjectFile($sourceRoot, $destinationRoot, $sourcePath, $installedFiles)
{ {
// Relative path // Relative path
$relativePath = substr($sourcePath, strlen($sourceRoot) + 1); // Name path without leading '/' $relativePath = substr($sourcePath ?? '', strlen($sourceRoot ?? '') + 1); // Name path without leading '/'
// Get destination path // Get destination path
$relativeDestination = $this->rewriteFilePath($destinationRoot, $relativePath); $relativeDestination = $this->rewriteFilePath($destinationRoot, $relativePath);
$destination = $destinationRoot . DIRECTORY_SEPARATOR . $relativeDestination; $destination = $destinationRoot . DIRECTORY_SEPARATOR . $relativeDestination;
// Check if file exists // Check if file exists
if (file_exists($destination)) { if (file_exists($destination ?? '')) {
if (file_get_contents($destination) === file_get_contents($sourcePath)) { if (file_get_contents($destination ?? '') === file_get_contents($sourcePath ?? '')) {
$this->io->write( $this->io->write(
" - Skipping <info>$relativePath</info> (<comment>existing, but unchanged</comment>)" " - Skipping <info>$relativePath</info> (<comment>existing, but unchanged</comment>)"
); );
@ -104,15 +110,19 @@ class RecipeInstaller extends LibraryInstaller
" - Skipping <info>$relativePath</info> (<comment>existing and modified in project</comment>)" " - Skipping <info>$relativePath</info> (<comment>existing and modified in project</comment>)"
); );
} }
} elseif (in_array($relativePath, $installedFiles) || in_array($relativeDestination, $installedFiles)) { } elseif (
in_array($relativePath, $installedFiles ?? []) ||
in_array($relativeDestination, $installedFiles ?? [])
) {
// Don't re-install previously installed files that have been deleted // Don't re-install previously installed files that have been deleted
$this->io->write( $this->io->write(
" - Skipping <info>$relativePath</info> (<comment>previously installed</comment>)" " - Skipping <info>$relativePath</info> (<comment>previously installed</comment>)"
); );
} else { } else {
$this->io->write(" - Copying <info>$relativePath</info>"); $this->io->write(" - Copying <info>$relativePath</info>");
$this->filesystem->ensureDirectoryExists(dirname($destination)); $this->filesystem->ensureDirectoryExists(dirname($destination ?? ''));
copy($sourcePath, $destination); copy($sourcePath ?? '', $destination ?? '');
$this->hasWrittenFiles = true;
} }
return $relativePath; return $relativePath;
} }
@ -131,7 +141,7 @@ class RecipeInstaller extends LibraryInstaller
foreach ($patterns as $pattern) { foreach ($patterns as $pattern) {
$expressions[] = $this->globToRegexp($pattern); $expressions[] = $this->globToRegexp($pattern);
} }
$regExp = '#^' . $this->globToRegexp($sourceRoot . '/').'(('.implode(')|(', $expressions).'))$#'; $regExp = '#^' . $this->globToRegexp($sourceRoot . '/') . '((' . implode(')|(', $expressions) . '))$#';
// Build directory iterator // Build directory iterator
$directoryIterator = new RecursiveDirectoryIterator( $directoryIterator = new RecursiveDirectoryIterator(
@ -155,10 +165,10 @@ class RecipeInstaller extends LibraryInstaller
*/ */
protected function globToRegexp($glob) protected function globToRegexp($glob)
{ {
$sourceParts = explode('*', $glob); $sourceParts = explode('*', $glob ?? '');
$regexParts = array_map(function ($part) { $regexParts = array_map(function ($part) {
return preg_quote($part, '#'); return preg_quote($part ?? '', '#');
}, $sourceParts); }, $sourceParts ?? []);
return implode('(.+)', $regexParts); return implode('(.+)', $regexParts);
} }
@ -176,11 +186,11 @@ class RecipeInstaller extends LibraryInstaller
$recipePath = $this->getInstallPath($package); $recipePath = $this->getInstallPath($package);
// Find project path // Find project path
$projectPath = dirname(realpath(Factory::getComposerFile())); $projectPath = dirname(realpath(Factory::getComposerFile() ?? '') ?? '');
// Find public path // Find public path
$candidatePublicPath = $projectPath . DIRECTORY_SEPARATOR . RecipePlugin::PUBLIC_PATH; $candidatePublicPath = $projectPath . DIRECTORY_SEPARATOR . RecipePlugin::PUBLIC_PATH;
$publicPath = is_dir($candidatePublicPath) ? $candidatePublicPath : $projectPath; $publicPath = is_dir($candidatePublicPath ?? '') ? $candidatePublicPath : $projectPath;
// Copy project files to root // Copy project files to root
$name = $package->getName(); $name = $package->getName();
@ -215,8 +225,9 @@ class RecipeInstaller extends LibraryInstaller
* Perform any file rewrites necessary to a relative path of a file being installed. * Perform any file rewrites necessary to a relative path of a file being installed.
* E.g. if 'mysite' folder exists, rewrite 'mysite' to 'app' and 'mysite/code' to 'app/src' * E.g. if 'mysite' folder exists, rewrite 'mysite' to 'app' and 'mysite/code' to 'app/src'
* *
* @deprecated 1.2..2.0 Will be removed in 2.0; app folder will be hard coded and no * This will be removed in 2.0 as the app folder will be hard coded and no rewrites supported.
* rewrites supported. *
* @deprecated 1.2.0 Will be removed without equivalent functionality to replace it
* @param string $destinationRoot Project root * @param string $destinationRoot Project root
* @param string $relativePath Relative path to the resource being installed * @param string $relativePath Relative path to the resource being installed
* @return string Relative path we should write to * @return string Relative path we should write to
@ -238,8 +249,8 @@ class RecipeInstaller extends LibraryInstaller
'app' => 'mysite', 'app' => 'mysite',
]; ];
foreach ($rewrites as $from => $to) { foreach ($rewrites as $from => $to) {
if (stripos($relativePath, $from) === 0) { if (stripos($relativePath ?? '', $from ?? '') === 0) {
return $to . substr($relativePath, strlen($from)); return $to . substr($relativePath ?? '', strlen($from ?? ''));
} }
} }
return $relativePath; return $relativePath;

View File

@ -1,6 +1,5 @@
<?php <?php
namespace SilverStripe\RecipePlugin; namespace SilverStripe\RecipePlugin;
use Composer\Composer; use Composer\Composer;
@ -27,37 +26,37 @@ class RecipePlugin implements PluginInterface, EventSubscriberInterface, Capable
/** /**
* Type of recipe to check for * Type of recipe to check for
*/ */
const RECIPE_TYPE = 'silverstripe-recipe'; public const RECIPE_TYPE = 'silverstripe-recipe';
/** /**
* 'extra' key for project files * 'extra' key for project files
*/ */
const PROJECT_FILES = 'project-files'; public const PROJECT_FILES = 'project-files';
/** /**
* 'extra' key for public files * 'extra' key for public files
*/ */
const PUBLIC_FILES = 'public-files'; public const PUBLIC_FILES = 'public-files';
/** /**
* Hard-coded 'public' web-root folder * Hard-coded 'public' web-root folder
*/ */
const PUBLIC_PATH = 'public'; public const PUBLIC_PATH = 'public';
/** /**
* 'extra' key for list of project files installed * 'extra' key for list of project files installed
*/ */
const PROJECT_FILES_INSTALLED = 'project-files-installed'; public const PROJECT_FILES_INSTALLED = 'project-files-installed';
/** /**
* 'extra' key for list of public files installed * 'extra' key for list of public files installed
*/ */
const PUBLIC_FILES_INSTALLED = 'public-files-installed'; public const PUBLIC_FILES_INSTALLED = 'public-files-installed';
/** /**
* 'extra' key for project dependencies installed * 'extra' key for project dependencies installed
*/ */
const PROJECT_DEPENDENCIES_INSTALLED = 'project-dependencies-installed'; public const PROJECT_DEPENDENCIES_INSTALLED = 'project-dependencies-installed';
public function activate(Composer $composer, IOInterface $io) public function activate(Composer $composer, IOInterface $io)
{ {
@ -137,11 +136,9 @@ class RecipePlugin implements PluginInterface, EventSubscriberInterface, Capable
public function deactivate(Composer $composer, IOInterface $io) public function deactivate(Composer $composer, IOInterface $io)
{ {
} }
public function uninstall(Composer $composer, IOInterface $io) public function uninstall(Composer $composer, IOInterface $io)
{ {
} }
} }