131 lines
5.9 KiB
YAML
131 lines
5.9 KiB
YAML
name: 'Determine GdUnit4 Version'
|
|
description: 'Determines the actual GdUnit4 version that will be used'
|
|
|
|
inputs:
|
|
version:
|
|
description: 'The version of GdUnit4 to use (e.g., "v4.2.0", "latest", "master", "installed")'
|
|
required: true
|
|
project_dir:
|
|
description: 'The project directory'
|
|
required: true
|
|
default: './'
|
|
|
|
outputs:
|
|
gdunit-version:
|
|
description: 'The determined GdUnit4 version'
|
|
value: ${{ steps.determine.outputs.version }}
|
|
|
|
runs:
|
|
using: 'composite'
|
|
steps:
|
|
- name: 'Determine Version'
|
|
id: determine
|
|
shell: bash
|
|
run: |
|
|
echo ""
|
|
echo -e "\e[34mRun Determine GdUnit4 Version\e[0m"
|
|
|
|
echo -e "\e[33mVersion Input: \e[0m ${{ inputs.version }}"
|
|
echo -e "\e[33mProject Directory: \e[0m ${{ inputs.project_dir }}"
|
|
echo ""
|
|
|
|
cd "${{ inputs.project_dir }}"
|
|
|
|
# Function to extract version from plugin.cfg
|
|
extract_version_from_plugin() {
|
|
local plugin_file=$1
|
|
if [[ -f "${plugin_file}" ]]; then
|
|
version=$(grep -oP '^version="\K[^"]+' "${plugin_file}")
|
|
if [[ -n "${version}" ]]; then
|
|
# Add 'v' prefix if not present
|
|
if [[ ! "${version}" =~ ^v ]]; then
|
|
version="v${version}"
|
|
fi
|
|
echo "${version}"
|
|
return 0
|
|
fi
|
|
fi
|
|
return 1
|
|
}
|
|
|
|
# Determine GdUnit4 version based on input
|
|
if [[ "${{ inputs.version }}" == "installed" ]]; then
|
|
echo -e "\e[33mChecking installed GdUnit4 plugin version... \e[0m"
|
|
|
|
if [[ -f ./addons/gdUnit4/plugin.cfg ]]; then
|
|
gdunit_version=$(extract_version_from_plugin "./addons/gdUnit4/plugin.cfg")
|
|
|
|
if [[ -n "${gdunit_version}" ]]; then
|
|
echo -e "\e[92m✓ Found installed GdUnit4 version: ${gdunit_version} \e[0m"
|
|
echo "version=${gdunit_version}" >> $GITHUB_OUTPUT
|
|
echo "GDUNIT_VERSION=${gdunit_version}" >> $GITHUB_ENV
|
|
exit 0
|
|
else
|
|
echo -e "\e[31m✗ Error: Could not extract version from ./addons/gdUnit4/plugin.cfg \e[0m"
|
|
exit 1
|
|
fi
|
|
else
|
|
echo -e "\e[31m✗ Error: GdUnit4 plugin not found at ./addons/gdUnit4/plugin.cfg \e[0m"
|
|
echo -e "\e[31m Make sure the plugin is installed before using version='installed' \e[0m"
|
|
exit 1
|
|
fi
|
|
|
|
elif [[ "${{ inputs.version }}" == "latest" ]]; then
|
|
echo -e "\e[33mResolving 'latest' GdUnit4 version from GitHub... \e[0m"
|
|
|
|
gdunit_version=$(git ls-remote --refs --tags https://github.com/godot-gdunit-labs/gdUnit4 v* | sort -t '/' -k 3 -V | tail -n 1 | cut -d '/' -f 3)
|
|
|
|
if [[ -n "${gdunit_version}" ]]; then
|
|
echo -e "\e[92m✓ Resolved latest version: ${gdunit_version} \e[0m"
|
|
echo "version=${gdunit_version}" >> $GITHUB_OUTPUT
|
|
echo "GDUNIT_VERSION=${gdunit_version}" >> $GITHUB_ENV
|
|
exit 0
|
|
else
|
|
echo -e "\e[31m✗ Error: Could not resolve latest version from GitHub \e[0m"
|
|
exit 1
|
|
fi
|
|
|
|
else
|
|
# Custom branch/tag specified
|
|
echo -e "\e[33mFetching GdUnit4 version from branch/tag '${{ inputs.version }}'... \e[0m"
|
|
|
|
# Check if it's a tag
|
|
if git ls-remote --tags https://github.com/godot-gdunit-labs/gdUnit4 | grep -q "refs/tags/${{ inputs.version }}$"; then
|
|
echo -e "\e[92m✓ Tag '${{ inputs.version }}' found \e[0m"
|
|
# Check if it's a branch
|
|
elif git ls-remote --heads https://github.com/godot-gdunit-labs/gdUnit4 | grep -q "refs/heads/${{ inputs.version }}$"; then
|
|
echo -e "\e[92m✓ Branch '${{ inputs.version }}' found \e[0m"
|
|
else
|
|
echo -e "\e[31m✗ Error: Branch/tag '${{ inputs.version }}' does not exist on GitHub \e[0m"
|
|
echo -e "\e[31m Please verify that the branch/tag exists at: https://github.com/godot-gdunit-labs/gdUnit4 \e[0m"
|
|
echo ""
|
|
echo "Available recent tags:" >&2
|
|
git ls-remote --tags https://github.com/godot-gdunit-labs/gdUnit4 | grep -oP 'refs/tags/\K.*' | grep -v '\^{}' | sort -V | tail -n 10 >&2
|
|
exit 1
|
|
fi
|
|
|
|
# Clone the specific branch to get the plugin.cfg
|
|
CLONE_DIR="./.gdunit4-version-${{ inputs.version }}"
|
|
|
|
if git clone --quiet --depth 1 --branch "${{ inputs.version }}" --single-branch https://github.com/godot-gdunit-labs/gdUnit4 "${CLONE_DIR}" 2>/dev/null; then
|
|
|
|
gdunit_version=$(extract_version_from_plugin "${CLONE_DIR}/addons/gdUnit4/plugin.cfg")
|
|
|
|
if [[ -n "${gdunit_version}" ]]; then
|
|
echo -e "\e[92m✓ Found GdUnit4 version from branch '${{ inputs.version }}': ${gdunit_version} \e[0m"
|
|
echo "version=${gdunit_version}" >> $GITHUB_OUTPUT
|
|
echo "GDUNIT_VERSION=${gdunit_version}" >> $GITHUB_ENV
|
|
exit 0
|
|
else
|
|
echo -e "\e[31m✗ Error: Could not extract version from plugin.cfg in branch '${{ inputs.version }}' \e[0m"
|
|
rm -rf "${CLONE_DIR}"
|
|
exit 1
|
|
fi
|
|
else
|
|
echo -e "\e[31m✗ Error: Could not clone branch/tag '${{ inputs.version }}' from GitHub \e[0m"
|
|
echo -e "\e[31m Please verify that the branch/tag exists at: https://github.com/godot-gdunit-labs/gdUnit4 \e[0m"
|
|
rm -rf "${CLONE_DIR}" 2>/dev/null
|
|
exit 1
|
|
fi
|
|
fi
|