-
Notifications
You must be signed in to change notification settings - Fork 3
109 lines (90 loc) · 3.24 KB
/
validate-version-bump.yaml
File metadata and controls
109 lines (90 loc) · 3.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
---
name: "Validate Version Bump"
on:
pull_request:
paths:
- 'src/**/devcontainer-feature.json'
jobs:
validate-version-bump:
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
steps:
- name: Checkout PR branch
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Validate version changes
run: |
set -e
echo "Checking for version changes..."
# Get changed files
CHANGED_FILES=$(git diff --name-only \
origin/${{ github.base_ref }}...HEAD | \
grep 'devcontainer-feature.json$' || true)
if [ -z "$CHANGED_FILES" ]; then
echo "No devcontainer-feature.json files changed"
exit 0
fi
HAS_ERROR=0
for FILE in $CHANGED_FILES; do
echo ""
echo "Checking $FILE..."
# Get old version
OLD_VERSION=$(git show \
origin/${{ github.base_ref }}:$FILE | \
jq -r '.version' 2>/dev/null || echo "")
NEW_VERSION=$(jq -r '.version' $FILE 2>/dev/null || echo "")
FEATURE_ID=$(jq -r '.id' $FILE 2>/dev/null || echo "unknown")
if [ -z "$OLD_VERSION" ]; then
echo " New feature: $FEATURE_ID (version: $NEW_VERSION)"
continue
fi
if [ -z "$NEW_VERSION" ]; then
echo " Error: Could not read version from $FILE"
HAS_ERROR=1
continue
fi
# Validate semantic versioning format
if ! echo "$NEW_VERSION" | \
grep -qE '^[0-9]+\.[0-9]+\.[0-9]+$'; then
echo " Error: Version does not follow semver"
HAS_ERROR=1
continue
fi
if [ "$OLD_VERSION" = "$NEW_VERSION" ]; then
echo " Warning: Version unchanged ($OLD_VERSION)"
else
echo " Version bumped: $OLD_VERSION -> $NEW_VERSION"
# Parse versions
OLD_MAJOR=$(echo $OLD_VERSION | cut -d. -f1)
OLD_MINOR=$(echo $OLD_VERSION | cut -d. -f2)
OLD_PATCH=$(echo $OLD_VERSION | cut -d. -f3)
NEW_MAJOR=$(echo $NEW_VERSION | cut -d. -f1)
NEW_MINOR=$(echo $NEW_VERSION | cut -d. -f2)
NEW_PATCH=$(echo $NEW_VERSION | cut -d. -f3)
# Check if version increased
if [ $NEW_MAJOR -lt $OLD_MAJOR ]; then
echo " Error: Major version decreased"
HAS_ERROR=1
elif [ $NEW_MAJOR -eq $OLD_MAJOR ]; then
if [ $NEW_MINOR -lt $OLD_MINOR ]; then
echo " Error: Minor version decreased"
HAS_ERROR=1
elif [ $NEW_MINOR -eq $OLD_MINOR ]; then
if [ $NEW_PATCH -lt $OLD_PATCH ]; then
echo " Error: Patch version decreased"
HAS_ERROR=1
fi
fi
fi
fi
done
if [ $HAS_ERROR -eq 1 ]; then
echo ""
echo "Version validation failed"
exit 1
fi
echo ""
echo "All version changes are valid"