Skip to content

chore: bump v2025.2.1 #45

chore: bump v2025.2.1

chore: bump v2025.2.1 #45

name: Prerelease on Version Bump
on:
push:
paths:
- 'custom_components/*/manifest.json'
jobs:
pre-release:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0 # Fetch all history for all tags and branches
- name: Detect single custom component directory
id: detect_integration
run: |
DIR_COUNT=$(find custom_components/* -maxdepth 0 -type d | wc -l)
if [ "$DIR_COUNT" -ne "1" ]; then
echo "Error: There must be exactly one custom component directory." >&2
exit 1
fi
echo "DOMAIN=$(basename $(find custom_components/* -maxdepth 0 -type d))" >> $GITHUB_ENV
- name: Install JQ
run: sudo apt-get install jq
- name: Extract version from current commit
id: current_version
run: echo "CURRENT_VERSION=$(jq -r '.version' custom_components/$DOMAIN/manifest.json)" >> $GITHUB_ENV
- name: Extract version from previous commit
id: previous_version
run: echo "PREVIOUS_VERSION=$(git show HEAD~:custom_components/$DOMAIN/manifest.json | jq -r '.version')" >> $GITHUB_ENV
- name: Collect Changes
if: ${{ env.CURRENT_VERSION != env.PREVIOUS_VERSION }}
id: collect_changes
run: |
PREVIOUS_TAG=$(git rev-list -n 1 v${{ env.PREVIOUS_VERSION }})
CURRENT_SHA=${{ github.sha }}
if [ -z "$PREVIOUS_TAG" ]; then
# Fallback in case there's no previous tag
CHANGELOG=$(git log --pretty=format:"%s%n%b" $(git rev-list --max-parents=0 HEAD)..$CURRENT_SHA)
else
CHANGELOG=$(git log --pretty=format:"%s%n%b" $PREVIOUS_TAG..$CURRENT_SHA)
fi
# Initialize section variables
ALL_FEATURES=""
ALL_FIXES=""
ALL_CHANGES=""
ALL_OTHER=""
# Process each commit message
echo "Processing changelog"
while IFS= read -r line; do
if [[ "$line" == "feat"* ]]; then
echo "Adding features line: $line"
ALL_FEATURES+="- $line\n"
elif [[ "$line" == "fix"* ]]; then
echo "Adding fixes line: $line"
ALL_FIXES+="- $line\n"
elif [[ "$line" == "refactor"* ]]; then
echo "Adding changes line: $line"
ALL_CHANGES+="- $line\n"
elif [[ ! -z "$line" ]]; then
echo "Adding others line: $line"
ALL_OTHER+="- $line\n"
fi
done <<< "$CHANGELOG"
# Start with an empty formatted changelog
CHANGELOG=""
# Add sections if not empty
if [[ ! -z "${ALL_FEATURES}" ]]; then
CHANGELOG="${CHANGELOG}## :new: Нововведения\n\n${ALL_FEATURES}\n"
fi
if [[ ! -z "${ALL_FIXES}" ]]; then
CHANGELOG="${CHANGELOG}## :bug: Исправления\n\n${ALL_FIXES}\n"
fi
if [[ ! -z "${ALL_CHANGES}" ]]; then
CHANGELOG="${CHANGELOG}## :wrench: Изменения\n\n${ALL_CHANGES}\n"
fi
if [[ ! -z "${ALL_OTHER}" ]]; then
CHANGELOG="${CHANGELOG}## :information_source: Примечания\n\n${ALL_OTHER}\n"
fi
# Clean up changelog
CHANGELOG="$(echo -e $CHANGELOG | sed -E 's/^- (feat|refactor|fix|chore)(\([^)]+\))?:\s*/- /g')"
echo "Resulting changelog:"
echo "$CHANGELOG"
# Save to GITHUB_ENV
{
echo 'CHANGELOG<<EOF'
echo -e "$CHANGELOG" | sed '$d'
echo 'EOF'
} >> $GITHUB_ENV
- name: Create Pre-release
if: ${{ env.CURRENT_VERSION != env.PREVIOUS_VERSION }}
uses: actions/github-script@v7
with:
script: |
const {CHANGELOG, CURRENT_VERSION} = process.env;
github.rest.repos.createRelease({
owner: context.repo.owner,
repo: context.repo.repo,
tag_name: `v${CURRENT_VERSION}`,
name: `v${CURRENT_VERSION}`,
body: `${CHANGELOG}`,
draft: false,
prerelease: true,
});