Skip to content

Update devskim.yml

Update devskim.yml #23

Workflow file for this run

name: VersionCheck
on:
push:
branches:
- main
jobs:
VersionCheck:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Get ModuleVersion from Plugin.cs
id: get_plugin_version
run: |
VERSION=$(grep -oP 'ModuleVersion => "\K[^"]+' GameModeManager/Plugin.cs)
echo "plugin_version=$VERSION" >> $GITHUB_OUTPUT
- name: Get Current Version from SECURITY.md
id: get_security_current_version
run: |
VERSION=$(grep -oP '\- v\K[^ ]+(?= \*\*\(Current Version\)\*\*)' SECURITY.md)
echo "security_current_version=$VERSION" >> $GITHUB_OUTPUT
- name: Get Previous Version from SECURITY.md
id: get_security_previous_version
run: |
VERSION=$(grep -oP '\- v\K[^ ]+(?= \*\*\(Previous Major Version\)\*\*)' SECURITY.md)
echo "security_previous_version=$VERSION" >> $GITHUB_OUTPUT
- name: Calculate Expected Previous Version
id: calculate_previous_version
run: |
CURRENT_VERSION="${{ steps.get_plugin_version.outputs.plugin_version }}"
# Basic check if version format is correct
if ! [[ "$CURRENT_VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Error: Invalid plugin version format found: $CURRENT_VERSION"
exit 1
fi
VERSION_PARTS=($(echo "$CURRENT_VERSION" | tr '.' ' '))
MAJOR=${VERSION_PARTS[0]}
MINOR=${VERSION_PARTS[1]}
PATCH=${VERSION_PARTS[2]}
# Calculate previous version logic (adjust if needed for major/minor bumps)
if [[ $PATCH -gt 0 ]]; then
PREVIOUS_PATCH=$((PATCH - 1))
EXPECTED_PREVIOUS_VERSION="$MAJOR.$MINOR.$PREVIOUS_PATCH"
elif [[ $MINOR -gt 0 ]]; then
# Assuming a minor bump resets patch to 0, find the 'last' patch of the previous minor
# This simple logic might need adjustment based on your actual versioning strategy
# For now, assuming previous minor ends in .0 or a hypothetical highest patch
PREVIOUS_MINOR=$((MINOR - 1))
# You might need a more complex way to determine the last patch of the previous minor
# For simplicity, using .0 here as per your original logic
EXPECTED_PREVIOUS_VERSION="$MAJOR.$PREVIOUS_MINOR.0"
elif [[ $MAJOR -gt 0 ]]; then
# Assuming a major bump resets minor/patch to 0, find the 'last' of the previous major
# This simple logic might need adjustment
PREVIOUS_MAJOR=$((MAJOR - 1))
# You might need a more complex way to determine the last minor/patch of the previous major
# For simplicity, using .0.0 here as per your original logic
EXPECTED_PREVIOUS_VERSION="$PREVIOUS_MAJOR.0.0" # Adjust this logic if necessary
else
# Handle case like 0.0.0 or invalid version
echo "Warning: Cannot determine previous version for $CURRENT_VERSION"
EXPECTED_PREVIOUS_VERSION="0.0.0" # Default or error state
fi
echo "expected_previous_version=$EXPECTED_PREVIOUS_VERSION" >> $GITHUB_OUTPUT
- name: Get ConfigVersion from Config.cs (Class Definition)
id: get_config_class_version
run: |
# Made grep slightly more robust to whitespace changes
CONFIG_CLASS_VERSION=$(grep -oP 'public\s+int\s+Version\s*{\s*get;\s*set;\s*}\s*=\s*\K\d+' GameModeManager/Config.cs)
if [[ -z "$CONFIG_CLASS_VERSION" ]]; then
echo "Error: Could not find Config Class Version in GameModeManager/Config.cs"
exit 1
fi
echo "config_class_version=$CONFIG_CLASS_VERSION" >> $GITHUB_OUTPUT
# --- CHANGE MADE HERE ---
- name: Get ConfigVersion from Config.cs (OnConfigParsed Check)
id: get_config_parsed_version
run: |
# Corrected file path from Plugin.cs to Config.cs
# Made grep slightly more robust to whitespace changes
CONFIG_PARSED_VERSION=$(grep -oP 'if\s*\(_config\.Version\s*<\s*\K\d+' GameModeManager/Config.cs)
if [[ -z "$CONFIG_PARSED_VERSION" ]]; then
echo "Error: Could not find Config Parsed Version check in GameModeManager/Config.cs"
exit 1
fi
echo "config_parsed_version=$CONFIG_PARSED_VERSION" >> $GITHUB_OUTPUT
# --- END OF CHANGE ---
- name: Check version consistency
run: |
PLUGIN_VERSION="${{ steps.get_plugin_version.outputs.plugin_version }}"
SECURITY_CURRENT_VERSION="${{ steps.get_security_current_version.outputs.security_current_version }}"
SECURITY_PREVIOUS_VERSION="${{ steps.get_security_previous_version.outputs.security_previous_version }}"
EXPECTED_PREVIOUS_VERSION="${{ steps.calculate_previous_version.outputs.expected_previous_version }}"
CONFIG_CLASS_VERSION="${{ steps.get_config_class_version.outputs.config_class_version }}"
CONFIG_PARSED_VERSION="${{ steps.get_config_parsed_version.outputs.config_parsed_version }}"
ERROR_DETECTED=false
echo "--- Version Check ---"
echo "Plugin.cs version: $PLUGIN_VERSION"
echo "SECURITY.md Current Version: $SECURITY_CURRENT_VERSION"
echo "SECURITY.md Previous Version: $SECURITY_PREVIOUS_VERSION"
echo "Calculated Expected Prev Version: $EXPECTED_PREVIOUS_VERSION"
echo "Config.cs (Class) Version: $CONFIG_CLASS_VERSION"
echo "Config.cs (Parsed Check) Version: $CONFIG_PARSED_VERSION"
echo "---------------------"
if [[ "$PLUGIN_VERSION" != "$SECURITY_CURRENT_VERSION" ]]; then
echo "Error: Plugin version mismatch!"
echo " Plugin.cs version: $PLUGIN_VERSION"
echo " SECURITY.md Current Version: $SECURITY_CURRENT_VERSION"
ERROR_DETECTED=true
fi
# Compare previous versions only if expected could be calculated reasonably
if [[ "$EXPECTED_PREVIOUS_VERSION" != "0.0.0" && "$SECURITY_PREVIOUS_VERSION" != "$EXPECTED_PREVIOUS_VERSION" ]]; then
echo "Error: Previous plugin version mismatch!"
echo " SECURITY.md Previous Version: $SECURITY_PREVIOUS_VERSION"
echo " Expected Previous Version: $EXPECTED_PREVIOUS_VERSION"
ERROR_DETECTED=true
elif [[ "$EXPECTED_PREVIOUS_VERSION" == "0.0.0" ]]; then
echo "Warning: Skipping previous version check due to calculation issue for $PLUGIN_VERSION."
fi
if [[ "$CONFIG_CLASS_VERSION" != "$CONFIG_PARSED_VERSION" ]]; then
echo "Error: Config version mismatch!"
echo " Config.cs (Class) Version: $CONFIG_CLASS_VERSION"
echo " Config.cs (Parsed Check) Version: $CONFIG_PARSED_VERSION"
ERROR_DETECTED=true
fi
if [[ "$ERROR_DETECTED" == true ]]; then
echo "Version consistency checks failed."
exit 1 # Fail the workflow
else
echo "Versions are consistent."
fi