Skip to content

Commit b24f0e6

Browse files
Merge pull request #89 from wcreateweb/version-test
Release version tests
2 parents 2bf9662 + 5aa556b commit b24f0e6

File tree

5 files changed

+88
-2
lines changed

5 files changed

+88
-2
lines changed

.distignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ bin
2727
.github
2828
.wp-env.json
2929
.distignore
30+
/.wordpress-org
3031

3132
# editor/os
32-
.vscode
33+
.vscode

.github/workflows/release.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ jobs:
1717
uses: actions/checkout@v4
1818
with:
1919
fetch-depth: 0
20+
- name: Verify version matches release tag
21+
run: bin/check-version
2022
- name: WordPress Plugin Deploy
2123
id: deploy
2224
uses: tinify/action-wordpress-plugin-deploy@stable

bin/check-version

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/bash
2+
set -e
3+
4+
# Script assumes release tags are formatted as MAJOR.MINOR.PATCH
5+
6+
# https://docs.github.com/en/actions/reference/workflows-and-actions/variables
7+
# For workflows triggered by release, this is the release tag created.
8+
TAG_VERSION="${1:-${GITHUB_REF#refs/tags/}}"
9+
10+
# Stable tag from readme.txt
11+
README_VERSION=$(grep -m 1 "^Stable tag:" readme.txt | awk '{print $3}')
12+
13+
if [ "$TAG_VERSION" != "$README_VERSION" ]; then
14+
echo "Error: Tag: $TAG_VERSION, readme.txt: $README_VERSION"
15+
exit 1
16+
fi
17+
18+
echo "Version matches git release"

test/unit/TinyVersionTest.php

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?php
2+
3+
require_once dirname(__FILE__) . '/TinyTestCase.php';
4+
5+
/**
6+
* Tests for version consistency across plugin files.
7+
*/
8+
class TinyVersionTest extends Tiny_TestCase
9+
{
10+
11+
/**
12+
* Plugin root directory path.
13+
* @var string
14+
*/
15+
private $plugin_root;
16+
17+
/**
18+
* Set up test environment.
19+
*/
20+
public function set_up()
21+
{
22+
parent::set_up();
23+
$this->plugin_root = dirname(dirname(__DIR__));
24+
}
25+
26+
/**
27+
* Test that the version in readme.txt matches the version in tiny-compress-images.php.
28+
*/
29+
public function test_readme_version_matches_plugin_version()
30+
{
31+
$plugin_file = $this->plugin_root . '/tiny-compress-images.php';
32+
$readme_file = $this->plugin_root . '/readme.txt';
33+
34+
$plugin_version = $this->get_version($plugin_file, '/Version:\s*(.+)/');
35+
$readme_version = $this->get_version($readme_file, '/Stable tag:\s*(.+)/');
36+
37+
$this->assertEquals(
38+
$readme_version,
39+
$plugin_version,
40+
sprintf(
41+
'readme.txt has %s but tiny-compress-images.php has version %s',
42+
$readme_version,
43+
$plugin_version
44+
)
45+
);
46+
}
47+
48+
49+
/**
50+
* Extract version number from a plugin file.
51+
*
52+
* @param string $file_path Path to the file
53+
* @return string|null The version number or null if not found.
54+
*/
55+
private function get_version($file_path, $regex)
56+
{
57+
$content = file_get_contents($file_path);
58+
59+
if (preg_match($regex, $content, $matches)) {
60+
return trim($matches[1]);
61+
}
62+
63+
return null;
64+
}
65+
}

tiny-compress-images.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
/**
33
* Plugin Name: TinyPNG - JPEG, PNG & WebP image compression
44
* Description: Speed up your website. Optimize your JPEG, PNG, and WebP images automatically with TinyPNG.
5-
* Version: 3.6.7
5+
* Version: 3.6.8
66
* Author: TinyPNG
77
* Author URI: https://tinypng.com
88
* Text Domain: tiny-compress-images

0 commit comments

Comments
 (0)