mirror of
https://github.com/ivuorinen/actions.git
synced 2026-01-26 03:23:59 +00:00
68 lines
2.1 KiB
YAML
68 lines
2.1 KiB
YAML
# yaml-language-server: $schema=https://json.schemastore.org/github-action.json
|
|
# permissions:
|
|
# - contents: read # Required for reading version files
|
|
---
|
|
name: Dotnet Version Detect
|
|
description: 'Detects .NET SDK version from global.json or defaults to a specified version.'
|
|
author: 'Ismo Vuorinen'
|
|
|
|
branding:
|
|
icon: code
|
|
color: blue
|
|
|
|
inputs:
|
|
default-version:
|
|
description: 'Default .NET SDK version to use if global.json is not found.'
|
|
required: true
|
|
default: '7.0'
|
|
token:
|
|
description: 'GitHub token for authentication'
|
|
required: false
|
|
default: ''
|
|
|
|
outputs:
|
|
dotnet-version:
|
|
description: 'Detected or default .NET SDK version.'
|
|
value: ${{ steps.parse-version.outputs.detected-version }}
|
|
|
|
runs:
|
|
using: composite
|
|
steps:
|
|
- name: Validate Inputs
|
|
id: validate
|
|
shell: bash
|
|
env:
|
|
DEFAULT_VERSION: ${{ inputs.default-version }}
|
|
run: |
|
|
set -euo pipefail
|
|
|
|
# Validate default-version format
|
|
if ! [[ "$DEFAULT_VERSION" =~ ^[0-9]+(\.[0-9]+(\.[0-9]+)?)?$ ]]; then
|
|
echo "::error::Invalid default-version format: '$DEFAULT_VERSION'. Expected format: X.Y or X.Y.Z (e.g., 7.0, 8.0.100)"
|
|
exit 1
|
|
fi
|
|
|
|
# Check for reasonable version range (prevent malicious inputs)
|
|
major_version=$(echo "$DEFAULT_VERSION" | cut -d'.' -f1)
|
|
if [ "$major_version" -lt 3 ] || [ "$major_version" -gt 20 ]; then
|
|
echo "::error::Invalid default-version: '$DEFAULT_VERSION'. Major version should be between 3 and 20"
|
|
exit 1
|
|
fi
|
|
|
|
echo "Input validation completed successfully"
|
|
|
|
- name: Checkout Repository
|
|
uses: actions/checkout@71cf2267d89c5cb81562390fa70a37fa40b1305e # v6-beta
|
|
with:
|
|
token: ${{ inputs.token || github.token }}
|
|
|
|
- name: Parse .NET Version
|
|
id: parse-version
|
|
uses: ivuorinen/actions/version-file-parser@0fa9a68f07a1260b321f814202658a6089a43d42
|
|
with:
|
|
language: 'dotnet'
|
|
tool-versions-key: 'dotnet'
|
|
dockerfile-image: 'dotnet'
|
|
validation-regex: '^[0-9]+(\.[0-9]+(\.[0-9]+)?)?$'
|
|
default-version: ${{ inputs.default-version }}
|