37 lines
1.3 KiB
YAML
37 lines
1.3 KiB
YAML
name: 'Enforce Flutter Version Constraint'
|
|
description: 'Scans all pubspec.yaml files to ensure they use the required Flutter SDK constraint.'
|
|
inputs:
|
|
expected_version:
|
|
description: 'The exact Flutter SDK constraint expected (e.g., ^3.19.0)'
|
|
required: true
|
|
default: '^3.19.0'
|
|
|
|
runs:
|
|
using: 'composite'
|
|
steps:
|
|
- name: Scan pubspec files
|
|
shell: bash
|
|
run: |
|
|
ERROR_COUNT=0
|
|
EXPECTED="${{ inputs.expected_version }}"
|
|
|
|
while IFS= read -r -d '' pubspec; do
|
|
# Skip non-Flutter Dart packages
|
|
if ! grep -q "sdk:[[:space:]]*flutter" "$pubspec" && ! grep -q "^flutter:" "$pubspec"; then
|
|
echo "Skipping non-Flutter package: $pubspec"
|
|
continue
|
|
fi
|
|
|
|
CONSTRAINT=$(awk '/^environment:/{flag=1; next} /^[^ ]/{flag=0} flag && /^ flutter:/ {print $2}' "$pubspec" | tr -d "'" | tr -d '"')
|
|
|
|
if [ "$CONSTRAINT" != "$EXPECTED" ]; then
|
|
echo "::error file=$pubspec::Invalid Flutter constraint in $pubspec. Expected '$EXPECTED', found '$CONSTRAINT'."
|
|
ERROR_COUNT=$((ERROR_COUNT+1))
|
|
fi
|
|
done < <(find . -name "pubspec.yaml" -print0)
|
|
|
|
if [ $ERROR_COUNT -gt 0 ]; then
|
|
echo "Workflow failed: Found $ERROR_COUNT pubspec(s) with unauthorized Flutter SDK constraints."
|
|
exit 1
|
|
fi
|