Skip to content

Commit

Permalink
NEW Add ability for the upgrader to self-update (#153)
Browse files Browse the repository at this point in the history
* NEW Auto compute version number on build.
* Suppress warning about dependency casing.
* Add a self-update command.
* Update the "releasing doc" to reflect that its automated now
* Update travis config to produce an md5 hash of the phar and keep older version.
* Correct doc.
* Implement feedback from peer review.
  • Loading branch information
maxime-rainville committed Feb 14, 2019
1 parent c4bc609 commit 6e438ca
Show file tree
Hide file tree
Showing 10 changed files with 415 additions and 28 deletions.
1 change: 1 addition & 0 deletions .env.example
@@ -0,0 +1 @@
UPGRADER_VERSION=1.3.0
2 changes: 2 additions & 0 deletions .gitignore
@@ -1,2 +1,4 @@
/vendor/
upgrade-code.phar
.env
.idea
14 changes: 10 additions & 4 deletions .travis.yml
Expand Up @@ -19,7 +19,7 @@ matrix:
- php: 7.3
env:
- SYMFONY="^4"
- php: 7.2
- php: 7.1
env:
- RELEASE=1

Expand All @@ -43,9 +43,15 @@ script:
- if [[ $LINT_TEST ]]; then composer run-script lint; fi

before_deploy:
- if [[ ! -f ./release/upgrade-code.phar ]]; then php build.php; fi
- mkdir -p ./release
- if [[ -f ./upgrade-code.phar ]]; then mv upgrade-code.phar ./release/; fi
- if [ -d "release" ]; then rm -rf release ; fi
- git clone --single-branch --branch gh-pages https://github.com/$TRAVIS_REPO_SLUG.git release
- echo "UPGRADER_VERSION=$TRAVIS_TAG" > .env
- php build.php
- if [[ ! -f ./upgrade-code.phar ]]; then exit 1; fi
- mv upgrade-code.phar ./release/
- mkdir release/$TRAVIS_TAG
- cp release/upgrade-code.phar release/$TRAVIS_TAG/upgrade-code.phar
- (cd release && md5sum upgrade-code.phar */upgrade-code.phar > MD5SUM)

deploy:
- provider: releases
Expand Down
22 changes: 21 additions & 1 deletion bin/upgrade-code
Expand Up @@ -18,11 +18,30 @@ foreach ($paths as $path) {
}

use SilverStripe\Upgrader\Console as Upgrader;
use SilverStripe\Upgrader\Util\UpdateChecker;
use Symfony\Component\Console\Application;
use M1\Env\Parser;

// Get Upgrader version from environment file
$version = '1.4.0';
$dotEnvPath = __DIR__ . '/../.env';
if (file_exists($dotEnvPath)) {
$env = new Parser(file_get_contents($dotEnvPath));
$envVars = $env->getContent();
if (isset($envVars['UPGRADER_VERSION'])) {
$version = $envVars['UPGRADER_VERSION'];
}
}

$nextVersion = UpdateChecker::getShowNewVersion($version);
if ($nextVersion && $nextVersion != $version) {
echo "A new version of the silverstripe upgrader is available. " .
"Run the `self-update` command to get version $nextVersion. \n\n";
}

$application = new Application();
$application->setName("SilverStripe Upgrader");
$application->setVersion('1.3.0');
$application->setVersion($version);
$application->add(new Upgrader\UpgradeCommand());
$application->add(new Upgrader\AddNamespaceCommand());
$application->add(new Upgrader\DoctorCommand());
Expand All @@ -32,4 +51,5 @@ $application->add(new Upgrader\RecomposeCommand());
$application->add(new Upgrader\ReorganiseCommand());
$application->add(new Upgrader\WebrootCommand());
$application->add(new Upgrader\AllInOneCommand());
$application->add(new Upgrader\SelfUpdateCommand());
$application->run();
2 changes: 2 additions & 0 deletions build.php
Expand Up @@ -26,6 +26,7 @@
$fs->mirror(PACKAGE_ROOT . 'src', BUILD_FOLDER . '/src');
$fs->copy(PACKAGE_ROOT . 'composer.json', BUILD_FOLDER . '/composer.json');
$fs->copy(PACKAGE_ROOT . 'composer.lock', BUILD_FOLDER . '/composer.lock');
$fs->copy(PACKAGE_ROOT . '.env', BUILD_FOLDER . '/.env');

// Install dependencies
$composerStatement = sprintf(
Expand All @@ -38,6 +39,7 @@
// Compile the executable
$compiler = new Compiler(BUILD_FOLDER);
$compiler->addIndexFile('bin/upgrade-code');
$compiler->addFile('.env');
$compiler->addDirectory('src');
$compiler->addDirectory('vendor');

Expand Down
5 changes: 3 additions & 2 deletions composer.json
Expand Up @@ -21,14 +21,15 @@
"composer/semver": "^1.4",
"guzzlehttp/guzzle": "^6.3",
"symfony/process": "^3.2 || ^4",
"symfony/filesystem": "^3.2 || ^4"
"symfony/filesystem": "^3.2 || ^4",
"padraic/phar-updater": "^1.0"
},
"bin": [
"bin/upgrade-code"
],
"require-dev": {
"phpunit/phpunit": "^7",
"mikey179/vfsStream": "^1.6",
"mikey179/vfsstream": "^1.6",
"secondtruth/phar-compiler": "^1.1",
"roave/security-advisories": "dev-master"
},
Expand Down
201 changes: 189 additions & 12 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 12 additions & 9 deletions doc/en/releasing.md
@@ -1,12 +1,15 @@
# Releasing a new verison of the upgrader
# Releasing a new version of the upgrader

This document is aimed for internal consumption. To release a new version of the upgrader follow these steps.
This document is aimed for internal consumption.

Upgrader releases are now automated with a travis build. When the tag gets built on travis, the build script will automatically run and build a PHAR executable. The PHAR executable will be attached back to the release in GitHub and publish to this repo's github pages.


To release a new version of the upgrader follow these steps:

1. On your local system, clone the upgrader codebase. You need to work of the `master` branch from this point.
2. Increment the version number in `src/upgrade-code`, commit your changes and push them back up to GitHub.
3. Call `php build.php` on the command line. This will build the upgrader as a PHAR file.
4. Move `upgrade-code.phar` to a temporary folder.
5. Switch to the `gh-pages` branch. e.g.: `git checkout gh-pages`
6. Overwrite the existing `upgrade-code.phar` with the one you built in step 3.
7. Commit your changes to the `gh-pages` branch and push them up to GitHub.
8. Create a new release on GitHub and attach `upgrade-code.phar` to it.
2. Increment the version number in `src/upgrade-code`, commit your changes and push them back up to GitHub. This will only be used for people installing the upgrader with Composer. The PHAR executable gets its version number from an environment file built into it.
3. In GitHub create a new release. You should provide detail about what has changed since the last release, referencing PRs ideally.
4. The release won't have a PHAR executable attached to it initially. You'll have to do wait for travis to complete its build. If that build fails for whatever reason, you can delete the release and unset the tag. Fix the issue and re-release the tag.

Note that we don't do patch releases for older minor releases. People are expected to always use the latest version.

0 comments on commit 6e438ca

Please sign in to comment.