diff --git a/action.yml b/action.yml index a0c57cc..9e40e01 100644 --- a/action.yml +++ b/action.yml @@ -84,59 +84,55 @@ runs: - name: Prepare and Validate Inputs id: parameter_validation - shell: pwsh + shell: bash run: | - # Parse and validate the generation - $generation = "${{ inputs.generation }}" - if (-not $generation -match '^\d+\.\d+\.\d+\.\d+$') { - throw "Generation format is invalid. Must be X.X.X.X where X is a number." - } + # Validate the generation format (X.X.X.X) + if ! [[ $generation =~ ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ ]]; then + echo "Generation format is invalid. Must be X.X.X.X where X is a number." + exit 1 + fi # Validate architecture - $architecture = "${{ inputs.architecture }}" - if ($architecture -ne "64" -and $architecture -ne "32") { - throw "Architecture must be 64 or 32." - } - - # Validate numeric inputs - $patch = "${{ inputs.patch }}" - $hotfix = "${{ inputs.hotfix }}" - $build = "${{ inputs.build }}" - if (-not($patch -match '^\d+$' -and $hotfix -match '^\d+$' -and $build -match '^\d+$')) { - throw "Patch, Hotfix, and Build must be numeric." - } - - # Adjust generation format for installation name and path - $formattedGeneration = $generation -replace '\.', '_' - $installationName = "CODESYS ${generation}" - if ($patch -ne "0") { - $installationName += ".$patch" - $formattedGeneration += "_$patch" - } - - # Determine installation path based on architecture - if ($architecture -eq "64") { - $installationPath = "C:\Program Files\CODESYS ${formattedGeneration}" - } else { - $installationPath = "C:\Program Files (x86)\CODESYS ${formattedGeneration}" - } + if [ "$architecture" != "64" ] && [ "$architecture" != "32" ]; then + echo "Architecture must be 64 or 32." + exit 1 + fi + + # Validate numeric inputs for patch, hotfix, and build + if ! [[ $patch =~ ^[0-9]+$ ]] || ! [[ $hotfix =~ ^[0-9]+$ ]] || ! [[ $build =~ ^[0-9]+$ ]]; then + echo "Patch, Hotfix, and Build must be numeric." + exit 1 + fi + + # Construct installation name and path + installation_name="CODESYS ${generation}" + formattedGeneration=$(echo $generation | sed 's/\./_/g') + if [ "$patch" != "0" ]; then + installation_name="${installation_name}.${patch}" + formattedGeneration="${formattedGeneration}_$patch" + fi + + if [ "$architecture" == "64" ]; then + installation_path="C:\Program Files\CODESYS ${formattedGeneration}" + else + installation_path="C:\Program Files (x86)\CODESYS ${formattedGeneration}" + fi # Check if the specified directory exists, otherwise create it - if (-not (Test-Path -Path $installationPath)) { - New-Item -ItemType Directory -Path $installationPath | Out-Null - Write-Host "Installation directory created at: $installationPath" - } else { - Write-Host "Installation directory already exists." - } - - # Output variables for use in subsequent steps - echo "generation=$generation" >> $env:GITHUB_OUTPUT - echo "architecture=$architecture" >> $env:GITHUB_OUTPUT - echo "patch=$patch" >> $env:GITHUB_OUTPUT - echo "hotfix=$hotfix" >> $env:GITHUB_OUTPUT - echo "build=$build" >> $env:GITHUB_OUTPUT - echo "installation-path=$installationPath" >> $env:GITHUB_OUTPUT - echo "installation-name=$installationName" >> $env:GITHUB_OUTPUT + #if [ ! -d "$installation_path" ]; then + # mkdir -p "$installation_path" + # echo "Installation directory created at: $installation_path" + #else + # echo "Installation directory already exists." + #fi + + echo "generation=$generation" >> $GITHUB_OUTPUT + echo "architecture=$architecture" >> $GITHUB_OUTPUT + echo "patch=$patch" >> $GITHUB_OUTPUT + echo "hotfix=$hotfix" >> $GITHUB_OUTPUT + echo "build=$build" >> $GITHUB_OUTPUT + echo "installation-path=$installation_path" >> $GITHUB_OUTPUT + echo "installation-name=$installation_name" >> $GITHUB_OUTPUT - name: Install CODESYS shell: pwsh