mirror of
https://github.com/ivuorinen/actions.git
synced 2026-01-26 03:23:59 +00:00
76 lines
2.4 KiB
YAML
76 lines
2.4 KiB
YAML
# yaml-language-server: $schema=https://json.schemastore.org/github-action.json
|
|
# permissions:
|
|
# - contents: read # Required for reading version files
|
|
---
|
|
name: Go Version Detect
|
|
description: "Detects the Go version from the project's go.mod file or defaults to a specified version."
|
|
author: 'Ismo Vuorinen'
|
|
|
|
branding:
|
|
icon: code
|
|
color: blue
|
|
|
|
inputs:
|
|
default-version:
|
|
description: 'Default Go version to use if go.mod is not found.'
|
|
required: false
|
|
default: '1.25'
|
|
token:
|
|
description: 'GitHub token for authentication'
|
|
required: false
|
|
default: ''
|
|
|
|
outputs:
|
|
go-version:
|
|
description: 'Detected or default Go version.'
|
|
value: ${{ steps.parse-version.outputs.detected-version }}
|
|
|
|
runs:
|
|
using: composite
|
|
steps:
|
|
- name: Validate Inputs
|
|
id: validate
|
|
shell: sh
|
|
env:
|
|
DEFAULT_VERSION: ${{ inputs.default-version }}
|
|
run: |
|
|
set -eu
|
|
|
|
# Validate default-version format
|
|
if ! echo "$DEFAULT_VERSION" | grep -Eq '^[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., 1.22, 1.21.5)"
|
|
exit 1
|
|
fi
|
|
|
|
# Check for reasonable version range (prevent malicious inputs)
|
|
major_version=$(echo "$DEFAULT_VERSION" | cut -d'.' -f1)
|
|
if [ "$major_version" -ne 1 ]; then
|
|
echo "::error::Invalid default-version: '$DEFAULT_VERSION'. Go major version should be 1"
|
|
exit 1
|
|
fi
|
|
|
|
# Check minor version range
|
|
minor_version=$(echo "$DEFAULT_VERSION" | cut -d'.' -f2)
|
|
if [ "$minor_version" -lt 16 ] || [ "$minor_version" -gt 30 ]; then
|
|
echo "::error::Invalid default-version: '$DEFAULT_VERSION'. Go minor version should be between 16 and 30"
|
|
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 Go Version
|
|
id: parse-version
|
|
uses: ivuorinen/actions/version-file-parser@0fa9a68f07a1260b321f814202658a6089a43d42
|
|
with:
|
|
language: 'go'
|
|
tool-versions-key: 'golang'
|
|
dockerfile-image: 'golang'
|
|
version-file: '.go-version'
|
|
validation-regex: '^[0-9]+\.[0-9]+(\.[0-9]+)?$'
|
|
default-version: ${{ inputs.default-version }}
|