1616# with:
1717# benchstat-version: ${{ env.MAGE_X_BENCHSTAT_VERSION }}
1818# runner-os: ${{ runner.os }}
19+ # go-version: ${{ matrix.go-version }}
1920#
2021# Maintainer: @mrz1836
2122#
@@ -31,22 +32,60 @@ inputs:
3132 runner-os :
3233 description : " Runner OS for cache key (e.g., ubuntu-latest, mac-latest)"
3334 required : true
35+ go-version :
36+ description : " Go version being used (e.g., 1.24.x, 1.22). Benchstat requires Go 1.23+"
37+ required : true
3438
3539outputs :
3640 cache-hit :
37- description : " Whether benchstat was restored from cache (true/false)"
41+ description : " Whether benchstat was restored from cache (true/false). Empty if skipped due to Go version. "
3842 value : ${{ steps.benchstat-cache.outputs.cache-hit }}
3943 installation-method :
40- description : " How benchstat was obtained: cached or fresh "
44+ description : " How benchstat was obtained: cached, fresh, or skipped "
4145 value : ${{ steps.installation-summary.outputs.method }}
46+ skipped :
47+ description : " Whether benchstat installation was skipped due to Go version < 1.23"
48+ value : ${{ steps.version-check.outputs.skip }}
4249
4350runs :
4451 using : " composite"
4552 steps :
53+ # --------------------------------------------------------------------
54+ # Check Go version compatibility (benchstat requires Go 1.23+)
55+ # --------------------------------------------------------------------
56+ - name : 🔍 Check Go version compatibility
57+ id : version-check
58+ shell : bash
59+ run : |
60+ GO_VERSION="${{ inputs.go-version }}"
61+ # Extract major and minor version:
62+ # "1.24.x" -> MAJOR=1, MINOR=24
63+ # "1.22" -> MAJOR=1, MINOR=22
64+ # "1.23.5" -> MAJOR=1, MINOR=23
65+ # "2.0.0" -> MAJOR=2, MINOR=0
66+ MAJOR=$(echo "$GO_VERSION" | sed -E 's/^([0-9]+)\..*/\1/')
67+ MINOR=$(echo "$GO_VERSION" | sed -E 's/^[0-9]+\.([0-9]+).*/\1/')
68+
69+ if [ -z "$MAJOR" ] || [ -z "$MINOR" ] || ! [[ "$MAJOR" =~ ^[0-9]+$ ]] || ! [[ "$MINOR" =~ ^[0-9]+$ ]]; then
70+ echo "❌ Could not parse Go version '$GO_VERSION'. Please provide a valid Go version (e.g., '1.23', '1.24.x')." >&2
71+ exit 1
72+ elif [ "$MAJOR" -gt 1 ]; then
73+ # Any Go major version > 1 is considered compatible with the 1.23+ requirement
74+ echo "✅ Go $GO_VERSION >= 1.23: proceeding with benchstat installation"
75+ echo "skip=false" >> $GITHUB_OUTPUT
76+ elif [ "$MAJOR" -eq 1 ] && [ "$MINOR" -lt 23 ]; then
77+ echo "⚠️ Go $GO_VERSION < 1.23: skipping benchstat installation (requires Go 1.23+)"
78+ echo "skip=true" >> $GITHUB_OUTPUT
79+ else
80+ echo "✅ Go $GO_VERSION >= 1.23: proceeding with benchstat installation"
81+ echo "skip=false" >> $GITHUB_OUTPUT
82+ fi
83+
4684 # --------------------------------------------------------------------
4785 # Restore benchstat binary cache
4886 # --------------------------------------------------------------------
4987 - name : 💾 Restore benchstat binary cache
88+ if : steps.version-check.outputs.skip != 'true'
5089 id : benchstat-cache
5190 uses : actions/cache@0400d5f644dc74513175e3cd8d07132dd4860809 # v4.2.4
5291 with :
5796 # Install cached binary to PATH when cache hits
5897 # --------------------------------------------------------------------
5998 - name : 📦 Install cached benchstat to PATH
60- if : steps.benchstat-cache.outputs.cache-hit == 'true'
99+ if : steps.version-check.outputs.skip != 'true' && steps. benchstat-cache.outputs.cache-hit == 'true'
61100 shell : bash
62101 run : |
63102 echo "📦 Installing cached benchstat binary to PATH..."
@@ -74,14 +113,14 @@ runs:
74113 # Install benchstat via go install when cache misses
75114 # --------------------------------------------------------------------
76115 - name : ⬇️ Install benchstat (cache miss)
77- if : steps.benchstat-cache.outputs.cache-hit != 'true'
116+ if : steps.version-check.outputs.skip != 'true' && steps. benchstat-cache.outputs.cache-hit != 'true'
78117 shell : bash
79118 run : |
80119 echo "⬇️ Cache miss – installing benchstat via go install..."
81120 echo "📋 Installing benchstat version: ${{ inputs.benchstat-version }}"
82121
83122 # Install benchstat
84- go install golang.org/x/perf/cmd/benchstat@${{ inputs.benchstat-version }}
123+ go install " golang.org/x/perf/cmd/benchstat@${{ inputs.benchstat-version }}"
85124
86125 # Cache the binary for future runs
87126 mkdir -p ~/.cache/benchstat-bin
@@ -99,6 +138,14 @@ runs:
99138 id : installation-summary
100139 shell : bash
101140 run : |
141+ # Check if installation was skipped due to Go version
142+ if [[ "${{ steps.version-check.outputs.skip }}" == "true" ]]; then
143+ echo "⏭️ Benchstat installation skipped (Go version < 1.23)"
144+ echo "method=skipped" >> $GITHUB_OUTPUT
145+ echo "📋 Installation method: Skipped"
146+ exit 0
147+ fi
148+
102149 echo "🔍 Verifying benchstat installation..."
103150
104151 # Test that benchstat is available and working
0 commit comments