-
-
Notifications
You must be signed in to change notification settings - Fork 20
154 lines (151 loc) · 6.98 KB
/
Bump-Addon-Version-base.yml
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
---
name: Automatically bump version on addon base updates and changelog
permissions:
contents: write
on:
push:
branches:
- master
jobs:
version:
runs-on: ubuntu-latest
if: ${{ contains(github.event.head_commit.message, 'Update ghcr.io/hassio-addons/base-python') }} # Detect that the base addon has been updated
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
lfs: "true"
fetch-depth: 0
- name: "Retrieve version & increment it"
id: version
run: |
set -e
echo "Starting version increment process..."
configFiles=$(find . -name 'config.yaml' -print0 | xargs -r0 echo)
if [[ -z "$configFiles" ]]; then
echo "Error: No config.yaml files found!"
exit 0
fi
echo "Found config files: $configFiles"
for configfile in $configFiles; do
echo "--------------------------------------------"
echo "Processing: $configfile"
if [ ! -f "$configfile" ]; then
echo "❌ Error: $configfile not found!"
exit 1
fi
if [ ! -r "$configfile" ]; then
echo "❌ Error: $configfile is not readable! Trying to fix permissions..."
chmod +r "$configfile" || { echo "❌ Failed to fix permissions!"; exit 1; }
fi
sed -i 's/\r$//' "$configfile" # Remove Windows line breaks (CRLF -> LF)
OLD_VERSION=$(grep -E '^[[:space:]]*version:[[:space:]]+[0-9]+\.[0-9]+\.[0-9]+' "$configfile" | head -1 | awk '{print $2}')
if [[ -z "$OLD_VERSION" ]]; then
echo "❌ Error: Could not extract a valid version from $configfile"
echo " File content:"
cat "$configfile"
exit 1
fi
echo " Extracted OLD_VERSION: '$OLD_VERSION'"
if [[ ! "$OLD_VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "❌ Error: Version format in $configfile is invalid: '$OLD_VERSION'"
exit 1
fi
echo " Try receiving major minor patch number from '$OLD_VERSION'"
IFS='.' read -r major minor patch <<< "$OLD_VERSION"
if [[ -z "$major" || -z "$minor" || -z "$patch" ]]; then
echo "❌ Error: Failed to parse version components from '$OLD_VERSION'. Got: '$major' '$minor' '$patch'"
exit 1
fi
echo " Got '$major' '$minor' '$patch', increasing patch number now."
if [[ -z "$patch" || ! "$patch" =~ ^[0-9]+$ ]]; then
echo "❌ Error: Patch version is invalid: '$patch'"
echo "🔄 Trying different versioning now."
if [[ -z "$minor" || ! "$minor" =~ ^[0-9]+$ ]]; then
echo "⚠️ Warning: Minor version is also invalid: '$minor'"
exit 1
else
minor=$((minor + 1))
patch=0
echo "🔹 Incremented minor version: $major.$minor.$patch"
fi
else
patch=$((patch + 1))
echo "🔹 Incremented patch version: $major.$minor.$patch"
fi
NEW_VERSION="$major.$minor.$patch"
echo " Updating $configfile from $OLD_VERSION to $NEW_VERSION"
sed -i "s/^version: $OLD_VERSION/version: $NEW_VERSION/" "$configfile"
if [ $? -ne 0 ]; then
echo "❌ Error: Failed to update version in $configfile"
echo "OLD_VERSION: $OLD_VERSION"
echo "NEW_VERSION: $NEW_VERSION"
exit 1
fi
NEW_VERSION_CHECK=$(grep -E '^[[:space:]]*version:[[:space:]]+[0-9]+\.[0-9]+\.[0-9]+' "$configfile" | head -1 | awk '{print $2}')
if [[ "$NEW_VERSION_CHECK" != "$NEW_VERSION" ]]; then
echo "❌ Error: Version update failed in $configfile!"
echo " File content after attempt:"
cat "$configfile"
exit 1
fi
echo "✅ Successfully updated $configfile to version $NEW_VERSION"
done
echo "🎉 Version increment process completed successfully!"
- name: "Update Changelog"
id: changelog
run: |
set -e
echo "🔄 Starting changelog version increment process..."
repo_url="https://api.github.com/repos/hassio-addons/addon-base"
response=$(curl -s "$repo_url/releases")
latest_version=$(echo "$response" | grep -oP '"tag_name": "\K[^"]+' | sed -n '1p')
files=$(find . -name "CHANGELOG.md" -exec grep -l "# Changelog" {} \;)
if [[ -z "$files" ]]; then
echo "❌ Error: No CHANGELOG.md files found!"
exit 1
fi
echo "✅ Latest version from repo: $latest_version"
echo "✅ Found files: $files"
while IFS= read -r file; do
echo "--------------------------------------------"
echo "📄 Processing: $file"
if [[ ! -f "$file" ]]; then
echo "❌ Error: $file not found!"
exit 1
fi
if [[ ! -w "$file" ]]; then
echo "❌ Error: $file is not writable!"
exit 1
fi
current_version=$(grep -oP "^## \K\d+\.\d+\.\d+" "$file" | sort -rV | head -n1)
if [[ -z "$current_version" ]]; then
echo "⚠️ Warning: No valid version found in $file"
continue
fi
echo "🔹 Found current version: $current_version"
IFS='.' read -r major minor patch <<< "$current_version"
if [[ -z "$patch" || ! "$patch" =~ ^[0-9]+$ ]]; then
echo "❌ Error: Patch version is invalid: '$patch'"
exit 1
fi
patch=$((patch + 1))
new_version="$major.$minor.$patch"
echo "🔹 Incremented Patch version to: $new_version"
echo "Updating $file with new version $new_version and addon-base version $latest_version..."
sed -i "/# Changelog/a \\## $new_version\\n- Automatically updated addon-base to version $latest_version\\n" "$file"
if grep -q "## $new_version" "$file"; then
echo "✅ Successfully updated $file with version $new_version"
else
echo "❌ Error: Failed to update $file!"
exit 1
fi
done <<< "$files"
echo "🎉 Version increment process completed successfully!"
- name: Commit & Push
uses: actions-js/push@v1.5
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: master
force: true
message: "Increment addon version due to addon base update"