Skip to content

Commit e02d30a

Browse files
committed
Merge pull request #172 from stronk7/manage_version
Changes to guarantee that --version works always
2 parents b99245b + 101cc76 commit e02d30a

File tree

8 files changed

+95
-9
lines changed

8 files changed

+95
-9
lines changed

.php-cs-fixer.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,5 +54,6 @@
5454
->exclude('moodle')
5555
->exclude('moodledata')
5656
->name('moodle-plugin-ci')
57+
->name('validate-version')
5758
->in(__DIR__)
5859
);

Makefile

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,18 @@ test-phpunit: check-init
1616
$(PHPUNIT) --verbose
1717

1818
.PHONY:validate
19-
validate: check-init psalm check-docs
19+
validate: check-init validate-version psalm check-docs
2020
$(FIXER) fix --dry-run --stop-on-violation
2121
$(COMPOSER) validate
2222
XDEBUG_MODE=coverage $(PHPUNIT) --verbose --coverage-text
2323

2424
.PHONY:build
2525
build: build/moodle-plugin-ci.phar
2626

27+
.PHONY:validate-version
28+
validate-version:
29+
bin/validate-version
30+
2731
.PHONY:psalm
2832
psalm: check-init
2933
$(PSALM)
@@ -41,7 +45,7 @@ check-docs: docs/CLI.md
4145
.PHONY: init
4246
init: build/php-cs-fixer.phar build/psalm.phar composer.lock composer.json
4347
$(COMPOSER) selfupdate
44-
$(COMPOSER) install --no-suggest --no-progress
48+
$(COMPOSER) install --no-progress
4549

4650
.PHONY: update
4751
update: check-init build/php-cs-fixer.phar build/psalm.phar

bin/moodle-plugin-ci

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ if (file_exists(__DIR__.'/../../../autoload.php')) {
4545
exit(1);
4646
}
4747

48+
// Current version. Keep it updated on releases.
49+
define('MOODLE_PLUGIN_CI_VERSION', '3.2.6');
50+
4851
define('MOODLE_PLUGIN_CI_BOXED', '@is_boxed@');
4952
define('ENV_FILE', dirname(__DIR__).'/.env');
5053

@@ -56,7 +59,13 @@ if (file_exists(ENV_FILE)) {
5659
$env->load(ENV_FILE);
5760
}
5861

59-
$application = new Application('Moodle Plugin CI', '@package_version@');
62+
$version = (new \SebastianBergmann\Version(MOODLE_PLUGIN_CI_VERSION, dirname(__DIR__)))->getVersion();
63+
// Let's make Box to find the better version for the phar from git.
64+
if (MOODLE_PLUGIN_CI_BOXED === 'BOXED') {
65+
$version = '@package_version@';
66+
}
67+
68+
$application = new Application('Moodle Plugin CI', $version);
6069
$application->add(new AddConfigCommand());
6170
$application->add(new AddPluginCommand(ENV_FILE));
6271
$application->add(new BehatCommand());

bin/validate-version

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#!/usr/bin/env php
2+
<?php
3+
/*
4+
* This file is part of the Moodle Plugin CI package.
5+
*
6+
* For the full copyright and license information, please view the LICENSE
7+
* file that was distributed with this source code.
8+
*
9+
* @copyright 2022 onwards Eloy Lafuente (stronk7) {@link https://stronk7.com}
10+
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
11+
*
12+
* Verify that the version in the moodle-plugin-ci app matches the
13+
* most recent version in the docs/CHANGELOG.md file. That way we
14+
* will enforce both to be always changed together, as part of the
15+
* documented release process.
16+
*/
17+
18+
// We need the moodle-plugin-ci binary, error if not found.
19+
$binary = __DIR__.'/moodle-plugin-ci';
20+
if (!is_readable($binary)) {
21+
fwrite(STDERR, 'Failed to find moodle-plugin-ci binary (usually under the bin directory).'.PHP_EOL);
22+
exit(1);
23+
}
24+
25+
// We need the docs/CHANGELOG.md, error if not found.
26+
$changelog = dirname(__DIR__).'/docs/CHANGELOG.md';
27+
if (!is_readable($changelog)) {
28+
fwrite(STDERR, 'Failed to find CHANGELOG.md (usually under the docs directory).'.PHP_EOL);
29+
exit(1);
30+
}
31+
32+
// Extract the version from the binary, error if not found.
33+
$regexp = '~^define\(\'MOODLE_PLUGIN_CI_VERSION\', *[\'"](\d+\.\d+\.\d+)[\'"].*$~m';
34+
if (!preg_match($regexp, file_get_contents($binary), $binaryMatches)) {
35+
fwrite(STDERR, 'Failed to parse moodle-plugin-ci looking for a version.'.PHP_EOL);
36+
exit(1);
37+
}
38+
$binaryVersion = $binaryMatches[1];
39+
40+
// Extract the version from the change log, error if not found.
41+
$regexp = '~^## *\[(\d+\.\d+\.\d+)\] *\-* *\d{4}\-\d{1,2}\-\d{1,2}$~m';
42+
if (!preg_match($regexp, file_get_contents($changelog), $changelogMatches)) {
43+
fwrite(STDERR, 'Failed to parse CHANGELOG.md looking for a version.'.PHP_EOL);
44+
exit(1);
45+
}
46+
$changelogVersion = $changelogMatches[1];
47+
48+
// Version in change log > binary, error.
49+
if (version_compare($changelogVersion, $binaryVersion, '>')) {
50+
fwrite(STDERR, 'Version in docs/CHANGELOG.md ('.
51+
$changelogVersion.') is newer than version in bin/moodle-plugin-ci ('.
52+
$binaryVersion.'). Please, check!'.PHP_EOL);
53+
exit(1);
54+
}
55+
56+
// Version in change log < binary, error.
57+
if (version_compare($changelogVersion, $binaryVersion, '<')) {
58+
fwrite(STDERR, 'Version in docs/CHANGELOG.md ('.
59+
$changelogVersion.') is older than version in bin/moodle-plugin-ci ('.
60+
$binaryVersion.'). Please, check!'.PHP_EOL);
61+
exit(1);
62+
}
63+
64+
// Arrived here, versions match, all ok.
65+
fwrite(STDOUT, 'Matching version found: '.$changelogVersion.PHP_EOL);
66+
exit(0);

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
"moodlehq/moodle-local_ci": "^1.0.12",
6868
"moodlehq/moodle-local_moodlecheck": "^1.0.9",
6969
"sebastian/phpcpd": "^3.0",
70+
"sebastian/version": "^2.0.1",
7071
"phpmd/phpmd": "^2.2",
7172
"symfony/dotenv": "^3.4",
7273
"symfony/filesystem": "^3.4",

composer.lock

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ The format of this change log follows the advice given at [Keep a CHANGELOG](htt
1616
### Changed
1717
- Switched from [local_codechecker](https://github.com/moodlehq/moodle-local_codechecker) to [moodle-cs](https://github.com/moodlehq/moodle-cs) for checking the coding style. Previously, `moodle-plugin-ci` (and other tools) required `local_codechecker` (that includes both `PHP_Codesniffer` and the `moodle` standard) to verify the coding style. Now, the `moodle` standard has been moved to be a standalone repository and all the tools will be using it and installing `PHP_Codesniffer` via composer. No changes in behavior are expected.
1818

19+
### Fixed
20+
- The `--version` option now works both with the `bin/moodle-plugin-ci` binary and the `moodle-plugin-ci.phar` package.
21+
1922
## [3.2.6] - 2022-05-10
2023
### Added
2124
- It is possible to specify more test execution options to the 'phpunit' command, such as `--fail-on-incomplete`, `--fail-on-risky` and `--fail-on-skipped` and `--fail-on-warning`. For more information, see [PHPUnit documentation](https://phpunit.readthedocs.io).

docs/ReleaseNewVersion.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ Prior to tagging a release, ensure the following have been updated:
1010

1111
* The `CHANGELOG.md` needs to be up-to-date. In addition, the _Unreleased_ section needs to be updated
1212
with the version being released. Also update the _Unreleased_ link at the bottom with the new version number.
13+
* The `bin/moodle-plugin-ci` also needs to be updated accordingly, setting the `MOODLE_PLUGIN_CI_VERSION` constant
14+
to the version being released.
1315
* If this is a new major version, then CI tool example files and its docs need
1416
to be updated to use the new major version (e.g. for Travis CI make changes
1517
in `.travis.dist.yml` and `doc/TravisFileExplained.md`). Any other version

0 commit comments

Comments
 (0)