Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add semantic version comparison. #5

Merged
merged 8 commits into from
Feb 24, 2024
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
20 changes: 20 additions & 0 deletions bin/version-compare.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash

if [[ $1 == 'latest' ]] || [[ $1 == 'dev' ]] || [[ $1 == 'nightly' ]]
then
# Set first arg to a huge number considering latest, dev or nightly to be the highest version.
set -- 1000000 $2 $3
fi

if [[ $2 == 'latest' ]] || [[ $2 == 'dev' ]] || [[ $2 == 'nightly' ]]
then
# Set second arg to a huge number considering latest, dev or nightly to be the highest version.
set -- $1 1000000 $3
fi

if dpkg --compare-versions $1 $3 $2
then
echo "result=true" >> $GITHUB_OUTPUT
else
echo "result=false" >> $GITHUB_OUTPUT
fi
16 changes: 13 additions & 3 deletions phpunit/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,16 @@ runs:
coverage: none
php-version: ${{ inputs.php-version }}

- name: Clean PHP Dependencies
- name: Check version requirement
id: version-compare
uses: polylang/actions/version-compare@ver-comp
with:
head: ${{ inputs.wordpress-version }}
base: "5.9"

- name: Clean PHP dependencies
run: |
if [[ ${{ inputs.wordpress-version }} == "5.8.x" ]]; then
if [[ ${{ steps.version-compare.outputs.result }} == true ]]; then
composer require --no-interaction --no-update --ignore-platform-reqs --dev "phpunit/phpunit ^7.5"
fi
composer remove --no-interaction --no-update --dev "phpstan/phpstan"
Expand All @@ -50,7 +57,10 @@ runs:
version: ${{ inputs.wordpress-version }}

- name: Set up plugins and themes dependencies
run: "bash ./tests/bin/install-plugins.sh"
run: |
if [[ -f ./tests/bin/install-plugins.sh ]]; then
bash ./tests/bin/install-plugins.sh
fi
shell: bash

- name: Run PHPUnit tests
Expand Down
35 changes: 35 additions & 0 deletions version-compare/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Sementic Versions Compare

description: Compares two versions. If 'dev', 'nightly' or 'latest' is given it'll be considered as the highest version possible.

inputs:
head:
description: First version number.
required: true
type: string
base:
description: Second version number.
required: true
type: string
operator:
description: Operator, accepts 'lt', 'gt' and 'eq'. Default to 'lt'.
required: false
type: string
default: 'lt'

outputs:
result:
description: Whether or not the version comparison it correct.
value: ${{ steps.compare.outputs.result }}

permissions:
contents: read

runs:
using: 'composite'

steps:
- name: Compare versions
id: compare
run: bash ${{ github.action_path }}/../bin/version-compare.sh "${{ inputs.head }}" "${{ inputs.base }}" "${{ inputs.operator }}"
shell: bash