chore: bump version number (v2024.3.5 -> v2024.3.6) #15
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: Prerelease on Version Bump | |
on: | |
push: | |
branches: | |
- master | |
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" | |
echo "$CHANGELOG" | while IFS= read -r line; do | |
echo "Processing line: $line" | |
if [[ "$line" == "feat"* ]]; then | |
ALL_FEATURES+="- $line\n" | |
elif [[ "$line" == "fix"* ]]; then | |
ALL_FIXES+="- $line\n" | |
elif [[ "$line" == "refactor"* ]]; then | |
ALL_CHANGES+="- $line\n" | |
else | |
ALL_OTHER+="- $line\n" | |
fi | |
done | |
# Start with an empty formatted changelog | |
CHANGELOG="" | |
# Add sections if not empty | |
if [ ! -z "$ALL_FEATURES" ]; then | |
CHANGELOG+="## :new: Нововведения\n\n${ALL_FEATURES}\n" | |
fi | |
if [ ! -z "$ALL_FIXES" ]; then | |
CHANGELOG+="## :bug: Исправления\n\n${ALL_FIXES}\n" | |
fi | |
if [ ! -z "$ALL_CHANGES" ]; then | |
CHANGELOG+="## :wrench: Изменения\n\n${ALL_CHANGES}" | |
fi | |
if [ ! -z "$ALL_OTHER" ]; then | |
CHANGELOG+="## :information_source: Примечания\n\n${ALL_OTHER}" | |
fi | |
# 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, | |
}); |