Bump version to 2.10.0 #199
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
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: | | |
configFiles=$(find . -name 'config.yaml' -print0 | xargs -r0 echo) | |
for configfile in $configFiles; do | |
OLD_VERSION=$(cat $configfile | grep 'version: ' | head -1 | sed s/"version: "//) | |
NEW_VERSION=$(echo $OLD_VERSION | awk -F. -v OFS=. 'NF==1{print ++$NF}; NF>1{if(length($NF+1)>length($NF))$(NF-1)++; $NF=sprintf("%0*d", length($NF), ($NF+1)%(10^length($NF))); print}') | |
sed -i "s/$OLD_VERSION/$NEW_VERSION/g" $configfile | |
echo "Incremented addon $configfile from version $OLD_VERSION to $NEW_VERSION" | |
done | |
- name: "Update Changelog" | |
id: changelog | |
run: | | |
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" {} \;) | |
echo "Latest version from repo: $latest_version" | |
echo "Found files: $files" | |
echo "$files" | while IFS= read -r file; do | |
if [ ! -w "$file" ]; then | |
echo "File $file is not writable" | |
exit 1 | |
fi | |
current_version=$(grep -oP "^## \K\d+\.\d+\.\d+" "$file" | sort -rV | head -n1) | |
echo "Processing $file, current version: $current_version" | |
if [ -n "$current_version" ]; then | |
IFS='.' read -r major minor patch <<< "$current_version" | |
echo "Got major $major , minor $minor , patch $patch" | |
((patch = patch + 1)) | |
echo "Incremented Patch version to $((patch))" | |
new_version="$major.$minor.$((patch))" | |
echo "New version: $new_version" | |
sed -i "/# Changelog/a \\## $new_version\\n- automatically update addon-base to version $latest_version\\n" "$file" | |
sed_exit_code=$? | |
if [ $sed_exit_code -eq 0 ]; then | |
echo "Added changelog auto text for $file with new version $new_version and addon-base version $latest_version" | |
else | |
echo "Error $sed_exit_code while writing changelog auto text for $file with new version $new_version and addon-base version $latest_version" | |
fi | |
else | |
echo "No valid version found in $file" | |
fi | |
done | |
- name: Commit & Push | |
uses: actions-js/[email protected] | |
with: | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
branch: master | |
force: true | |
message: "Increment addon version due to addon base update" |