From db312435cb9d8d73395f75f9642a43ba6de5e903 Mon Sep 17 00:00:00 2001 From: Kieran Date: Sun, 18 Sep 2022 07:44:00 +0100 Subject: [PATCH] feat: add semantic release (#307) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Add semantic release * fix typo * split from matrix * remove only on push * remove npm plugin * write changelog to NEWS * list assets to include in git commit * fix update-for-release * lint pr title * split release into separate workflow that runs manually * revert ci.yml changes * remove references to WHATSNEW * Fix #322 - PHP 8.1 deprecation notice in HostBlacklist URIFilter (#323) * Replace 8.1-deprecated utf8_ funcs with mbstring (#326) * Treat PHP version numbers as strings in GitHub Actions (#327) YAML will try to interpret numeric values as numbers, leading to `8.0` being interpreted as `8` instead of `'8.0'`. This doesn't result in a functional change, but cleans up the output of the jobs a little (e.g. in the title line). * Update to `actions/checkout@v3` (#328) This does not introduce any functional difference and is intended as a future-proofing change. see https://github.com/actions/checkout/releases/tag/v3.0.0 * Fix test selection logic in tests/test_files.php (#329) Selecting the `fstools` tests also executed the `htmlt` tests. * Fix some more PHP 8.2 deprecations (#330) * Define HTMLPurifier_AttrTransform_SafeParam::$wmode This fixes a PHP 8.2 deprecation. * Define HTMLPurifier_DefinitionCache_DecoratorHarness::$cache This fixes a PHP 8.2 deprecation. * Define HTMLPurifier_DefinitionCache_DecoratorHarness::$mock This fixes a PHP 8.2 deprecation. * Define HTMLPurifier_DefinitionCache_DecoratorHarness::$def This fixes a PHP 8.2 deprecation. * Define HTMLPurifier_EntityParserTest::$_entity_lookup This fixes a PHP 8.2 deprecation. * Increase minimum requirement to PHP 5.6 (#331) * Add contenteditable attribute definition (#332) * Add contenteditable attribute definition * gate behind html.trusted * use enum * Fix creation of dynamic property (#333) * Fix creation of dynamic property (#337) * Add PHP 8.2 to CI (#335) * Add PHP 8.2 to CI see ezyang/htmlpurifier#334 * Add PHP 8.2 to composer.json * Fix contenteditable attribute definition (#336) * Run CSSTidy tests on CI (#338) * Run CSSTidy tests on CI * update dirname * use compopser instead of git clone * use composer * use test-settings.sample.php * enable ext-intl * disable Net_IDNA2 * Release 4.15.0 Signed-off-by: Edward Z. Yang Signed-off-by: Edward Z. Yang Co-authored-by: John Flatness Co-authored-by: Tim Düsterhus Co-authored-by: Tim Düsterhus Co-authored-by: Edward Z. Yang --- .gitattributes | 2 +- .github/workflows/lint-pr.yml | 19 +++++++++++++++++++ .github/workflows/release.yml | 29 +++++++++++++++++++++++++++++ WHATSNEW | 3 --- maintenance/add-vimline.php | 1 - package.php | 1 - release.config.js | 29 +++++++++++++++++++++++++++++ update-for-release | 34 +++++++++++++++------------------- 8 files changed, 93 insertions(+), 25 deletions(-) create mode 100644 .github/workflows/lint-pr.yml create mode 100644 .github/workflows/release.yml delete mode 100644 WHATSNEW create mode 100644 release.config.js diff --git a/.gitattributes b/.gitattributes index 7542171d..6b39d9fe 100644 --- a/.gitattributes +++ b/.gitattributes @@ -19,5 +19,5 @@ /tests export-ignore /TODO export-ignore /update-for-release export-ignore -/WHATSNEW export-ignore /WYSIWYG export-ignore +/release.config.js export-ignore diff --git a/.github/workflows/lint-pr.yml b/.github/workflows/lint-pr.yml new file mode 100644 index 00000000..597a6ed7 --- /dev/null +++ b/.github/workflows/lint-pr.yml @@ -0,0 +1,19 @@ +name: "Lint PR" + +on: + pull_request_target: + types: + - opened + - edited + - synchronize + +jobs: + main: + name: Validate PR title + + runs-on: ubuntu-latest + + steps: + - uses: amannn/action-semantic-pull-request@v4 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 00000000..eb2308a6 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,29 @@ +name: release + +on: + workflow_dispatch: + +jobs: + release: + runs-on: ubuntu-latest + + name: Release + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: 5.5 + + - name: Run automated release process with semantic-release + uses: cycjimmy/semantic-release-action@v2 + with: + extra_plugins: | + @semantic-release/changelog + @semantic-release/git + @semantic-release/exec + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/WHATSNEW b/WHATSNEW deleted file mode 100644 index 32403eb2..00000000 --- a/WHATSNEW +++ /dev/null @@ -1,3 +0,0 @@ -HTML Purifier 4.15.x is a maintenance release which improves -compatibility with PHP8.2. There is also support for -contenteditable="false" added. diff --git a/maintenance/add-vimline.php b/maintenance/add-vimline.php index d6a8eb20..69882c67 100644 --- a/maintenance/add-vimline.php +++ b/maintenance/add-vimline.php @@ -34,7 +34,6 @@ foreach ($files as $file) { postfix_is('.svg', $file) || postfix_is('.phpt', $file) || postfix_is('VERSION', $file) || - postfix_is('WHATSNEW', $file) || postfix_is('configdoc/usage.xml', $file) || postfix_is('library/HTMLPurifier.includes.php', $file) || postfix_is('library/HTMLPurifier.safe-includes.php', $file) || diff --git a/package.php b/package.php index bfef9362..a4fd2df9 100644 --- a/package.php +++ b/package.php @@ -48,7 +48,6 @@ $pkg->setReleaseStability('stable'); $pkg->addRelease(); -$pkg->setNotes(file_get_contents('WHATSNEW')); $pkg->setPackageType('php'); $pkg->setPhpDep('5.0.0'); diff --git a/release.config.js b/release.config.js new file mode 100644 index 00000000..3f73ace8 --- /dev/null +++ b/release.config.js @@ -0,0 +1,29 @@ +module.exports = { + debug: true, + branch: 'master', + plugins: [ + '@semantic-release/commit-analyzer', + '@semantic-release/release-notes-generator', + ['@semantic-release/changelog', {'changelogFile': 'NEWS'}], + '@semantic-release/exec', + ['@semantic-release/git', { + 'assets': ['VERSION', 'NEWS', 'Doxyfile', 'library/HTMLPurifier.php', 'library/HTMLPurifier/Config.php', 'library/HTMLPurifier.includes.php'], + }], + '@semantic-release/github' + ], + verifyConditions: [ + '@semantic-release/changelog', + '@semantic-release/github', + ], + prepare: [ + { + path: '@semantic-release/exec', + cmd: 'php update-for-release ${nextRelease.version}' + }, + '@semantic-release/changelog', + '@semantic-release/git', + ], + publish: [ + '@semantic-release/github', + ] +} diff --git a/update-for-release b/update-for-release index 2b9662a7..ec5ec03d 100644 --- a/update-for-release +++ b/update-for-release @@ -23,24 +23,7 @@ $version = trim($argv[1]); // ...in VERSION file_put_contents('VERSION', $version); -// ...in NEWS -if ($is_dev = (strpos($version, 'dev') === false)) { - $date = date('Y-m-d'); - $news_c = str_replace( - $l = "$version, unknown release date", - "$version, released $date", - file_get_contents('NEWS'), - $c - ); - if (!$c) { - echo 'Could not update NEWS, missing ' . $l . PHP_EOL; - exit; - } elseif ($c > 1) { - echo 'More than one release declaration in NEWS replaced' . PHP_EOL; - exit; - } - file_put_contents('NEWS', $news_c); -} +$is_dev = strpos($version, 'dev') === false; // ...in Doxyfile $doxyfile_c = preg_replace( @@ -102,9 +85,22 @@ if (!$c) { } file_put_contents('library/HTMLPurifier/Config.php', $config_c); +$includes = file_get_contents('library/HTMLPurifier.includes.php'); +$includes = preg_replace( + '/@version .+?/', + "@version $version", + $includes, + 1, $c +); +if (!$c) { + echo 'Could not update HTMLPurifier.includes.php, missing @version docblock.' . PHP_EOL; + exit; +} +file_put_contents('HTMLPurifier.includes.php', $includes); + passthru('maintenance/flush.sh'); -if ($is_dev) echo "Review changes, write something in WHATSNEW, and then commit with log 'Release $version.'" . PHP_EOL; +if ($is_dev) echo "Review changes, and then commit with log 'Release $version.'" . PHP_EOL; else echo "Numbers updated to dev, no other modifications necessary!"; // vim: et sw=4 sts=4