Files
actions/python-version-detect-v2/action.yml
Ismo Vuorinen a1c0435c22 chore: update action references for release v2025.11.02 (#332)
This commit updates all internal action references to point to the current
commit SHA in preparation for release v2025.11.02.
2025-11-02 20:53:11 +02:00

83 lines
2.7 KiB
YAML

# yaml-language-server: $schema=https://json.schemastore.org/github-action.json
# permissions:
# - contents: read # Required for reading version files
---
name: Python Version Detect v2
description: 'Detects Python version from project configuration files using enhanced detection logic.'
author: 'Ismo Vuorinen'
branding:
icon: code
color: blue
inputs:
default-version:
description: 'Default Python version to use if no version is detected.'
required: false
default: '3.12'
token:
description: 'GitHub token for authentication'
required: false
default: ''
outputs:
python-version:
description: 'Detected or default Python version.'
value: ${{ steps.parse-version.outputs.detected-version }}
package-manager:
description: 'Detected Python package manager (pip, poetry, pipenv).'
value: ${{ steps.parse-version.outputs.package-manager }}
runs:
using: composite
steps:
- name: Validate Inputs
id: validate
shell: sh
env:
DEFAULT_VERSION: ${{ inputs.default-version }}
run: |
set -eu
# Validate default-version format
case "$DEFAULT_VERSION" in
[0-9]*.[0-9]* | [0-9]*.[0-9]*.[0-9]*)
;;
*)
echo "::error::Invalid default-version format: '$DEFAULT_VERSION'. Expected format: X.Y or X.Y.Z (e.g., 3.12, 3.11.5)"
exit 1
;;
esac
# Check for reasonable version range (prevent malicious inputs)
major_version=$(echo "$DEFAULT_VERSION" | cut -d'.' -f1)
if [ "$major_version" -ne 3 ]; then
echo "::error::Invalid default-version: '$DEFAULT_VERSION'. Python major version should be 3"
exit 1
fi
# Check minor version range for Python 3
minor_version=$(echo "$DEFAULT_VERSION" | cut -d'.' -f2)
if [ "$minor_version" -lt 8 ] || [ "$minor_version" -gt 15 ]; then
echo "::error::Invalid default-version: '$DEFAULT_VERSION'. Python 3 minor version should be between 8 and 15"
exit 1
fi
echo "Input validation completed successfully"
- name: Checkout Repository
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
with:
token: ${{ inputs.token || github.token }}
- name: Parse Python Version
id: parse-version
uses: ivuorinen/actions/version-file-parser@2f1c73dd8b23ffec17bb93ebd0f32e7a7c7546fc
with:
language: 'python'
tool-versions-key: 'python'
dockerfile-image: 'python'
version-file: '.python-version'
validation-regex: '^[0-9]+\.[0-9]+(\.[0-9]+)?$'
default-version: ${{ inputs.default-version }}