Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .github/workflows/fixtures/plugin-test-minor-fail/readme.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
=== Plugin Test ===
Contributors: jazzsequence
Tags: github actions, testing
Requires at least: 5.8
Tested up to: 6.6
Stable tag: 1.0.0
License: MIT
License URI: https://opensource.org/licenses/MIT

This is a test plugin for testing GitHub Actions workflows.
10 changes: 10 additions & 0 deletions .github/workflows/fixtures/plugin-test-minor-pass/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Plugin Test
Contributors: jazzsequence
Tags: github actions, testing
Requires at least: 5.8
Tested up to: 6.6.1
Stable tag: 1.0.0
License: MIT
License URI: https://opensource.org/licenses/MIT

This is a test plugin for testing GitHub Actions workflows.
12 changes: 12 additions & 0 deletions .github/workflows/fixtures/plugin-test-minor-pass/plugin-test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php
/**
* Plugin Name: Test Plugin
* Plugin URI: https://github.com/jazzsequence/action-validate-plugin-version
* Description: A test plugin for the GitHub Action to validate plugin version
* Version: 1.0.0
* Author: Chris Reynolds
* Author URI: https://chrisreynolds.io
* License: MIT License
*/

// Silence is golden.
10 changes: 10 additions & 0 deletions .github/workflows/fixtures/plugin-test-minor-pass/readme.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
=== Plugin Test ===
Contributors: jazzsequence
Tags: github actions, testing
Requires at least: 5.8
Tested up to: 6.8
Stable tag: 1.0.0
License: MIT
License URI: https://opensource.org/licenses/MIT

This is a test plugin for testing GitHub Actions workflows.
10 changes: 10 additions & 0 deletions .github/workflows/fixtures/plugin-test-patch-fail/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Plugin Test
Contributors: jazzsequence
Tags: github actions, testing
Requires at least: 5.8
Tested up to: 6.6.1
Stable tag: 1.0.0
License: MIT
License URI: https://opensource.org/licenses/MIT

This is a test plugin for testing GitHub Actions workflows.
12 changes: 12 additions & 0 deletions .github/workflows/fixtures/plugin-test-patch-fail/plugin-test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php
/**
* Plugin Name: Test Plugin
* Plugin URI: https://github.com/jazzsequence/action-validate-plugin-version
* Description: A test plugin for the GitHub Action to validate plugin version
* Version: 1.0.0
* Author: Chris Reynolds
* Author URI: https://chrisreynolds.io
* License: MIT License
*/

// Silence is golden.
20 changes: 17 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,26 @@ on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
name: Test Validation Level
steps:
- uses: actions/checkout@v5
with:
fetch-depth: 0
- name: Validate Plugin Version
- name: Validate Plugin Version (Patch - Fail)
uses: ./
with:
plugin-path: '.github/workflows/fixtures/plugin-test/'
dry-run: true
plugin-path: '.github/workflows/fixtures/plugin-test-patch-fail/'
dry-run: true
validation-level: patch
- name: Validate Plugin Version (Minor - Fail)
uses: ./
with:
plugin-path: '.github/workflows/fixtures/plugin-test-minor-fail/'
dry-run: true
validation-level: minor
- name: Validate Plugin Version (Minor - Pass)
uses: ./
with:
plugin-path: '.github/workflows/fixtures/plugin-test-minor-pass/'
dry-run: true
validation-level: minor
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
with:
fetch-depth: 0
- name: Validate Plugin Version
uses: jazzsequence/action-validate-plugin-version@v1
uses: jazzsequence/action-validate-plugin-version@v2
with:
plugin-path: 'path/to/plugin-slug/'
filenames: 'readme.txt,README.MD'
Expand Down Expand Up @@ -54,6 +54,12 @@ The branch to create the PR against. If not specified, the action will use the b
#### `pr-status`
The status to set on the PR. If not specified, the action will create a _draft_ PR. Accepts `draft` or `open`.

#### `validation-level`
The validation level to use. Accepts `patch` or `minor`. If not specified, the action will use `minor`.

- `minor`: Compares the "Tested Up To" version against the current WordPress version using only the major and minor numbers (e.g., `6.1`), ignoring the patch number.
- `patch`: Compares the full version including the patch number (e.g., `6.1.2`), requiring an exact match for validation.

## Permissions

The `write` permissions on `contents` and `pull-requests` are important. They are required for the action to commit the changes back to the repository and open a pull request. The only files affected by the action are files named `readme.txt`, `README.md` or those files matching the pattern (looking for "Tested Up To" in the file) that have been specified in the `filenames` input.
7 changes: 6 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ inputs:
description: The status of the PR to create. Default is 'draft'. Accepts 'draft' or 'open'.
required: false
default: 'draft'
validation-level:
description: The validation level to use. Accepts 'patch' or 'minor'.
required: false
default: 'minor'
runs:
using: composite
steps:
Expand All @@ -38,7 +42,7 @@ runs:
echo "Current working directory:"
pwd
echo "Contents of action directory (looking for bin/validate-plugin-version.sh):"
ls -R
ls -R
- name: Validate Plugin Tested Up To Version
shell: bash
env:
Expand All @@ -50,5 +54,6 @@ runs:
BRANCH: ${{ inputs.branch }}
PR_STATUS: ${{ inputs.pr-status }}
GITHUB_BASE_REF: ${{ github.base_ref }}
VALIDATION_LEVEL: ${{ inputs.validation-level }}
run: bash ${{ github.action_path }}/bin/validate-plugin-version.sh

15 changes: 15 additions & 0 deletions bin/validate-plugin-version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,21 @@ main() {
CURRENT_WP_VERSION=$(curl -s https://api.wordpress.org/core/version-check/1.7/ | jq -r '.offers[0].current')
echo "Current WordPress Version: ${CURRENT_WP_VERSION}"

# Adjust version based on validation level
case "${VALIDATION_LEVEL:-minor}" in
minor)
CURRENT_WP_VERSION=$(echo "$CURRENT_WP_VERSION" | cut -d'.' -f1,2)
echo "Validation level is 'minor', using WordPress version: ${CURRENT_WP_VERSION}"
;;
patch)
echo "Validation level is 'patch', using full WordPress version: ${CURRENT_WP_VERSION}"
;;
*)
echo "Error: Invalid validation-level specified: ${VALIDATION_LEVEL}. Must be 'minor' or 'patch'."
exit 1
;;
esac

# Split FILENAMES into an array
IFS=',' read -ra FILENAMES_ARRAY <<< "$FILENAMES"

Expand Down