-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create new version-compare action and use it in phpunit.$
- Loading branch information
1 parent
c1e4651
commit f2c4cc3
Showing
3 changed files
with
99 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#!/bin/bash | ||
|
||
version_compare () { | ||
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 [[ $1 == $2 ]] | ||
then | ||
return 0 | ||
fi | ||
local IFS=. | ||
local i ver1=($1) ver2=($2) | ||
# Fill empty fields in ver1 with zeros. | ||
for ((i=${#ver1[@]}; i<${#ver2[@]}; i++)) | ||
do | ||
ver1[i]=0 | ||
done | ||
for ((i=0; i<${#ver1[@]}; i++)) | ||
do | ||
if [[ -z ${ver2[i]} ]] | ||
then | ||
# Fill empty fields in ver2 with zeros. | ||
ver2[i]=0 | ||
fi | ||
if ((10#${ver1[i]} > 10#${ver2[i]})) | ||
then | ||
return 1 | ||
fi | ||
if ((10#${ver1[i]} < 10#${ver2[i]})) | ||
then | ||
return 2 | ||
fi | ||
done | ||
return 0 | ||
} | ||
|
||
version_compare $1 $2 | ||
case $? in | ||
0) op='=';; | ||
1) op='>';; | ||
2) op='<';; | ||
esac | ||
if [[ $op != $3 ]] | ||
then | ||
echo "result=$(echo false)" >> $GITHUB_OUTPUT | ||
else | ||
echo "result=$(echo true)" >> $GITHUB_OUTPUT | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 '<', '>' and '='. Default to '<'. | ||
required: true | ||
type: string | ||
default: '<' | ||
|
||
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 |