chore: bump version number (v2024.3.5 -> v2024.3.6) #11
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 "$CHANGELOG" | while IFS= read -r line; do | |
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 | |
FORMATTED_CHANGELOG="" | |
# Add sections if not empty | |
if [ ! -z "$ALL_FEATURES" ]; then | |
FORMATTED_CHANGELOG+="## :new: Нововведения\n\n${ALL_FEATURES}\n" | |
fi | |
if [ ! -z "$ALL_FIXES" ]; then | |
FORMATTED_CHANGELOG+="## :bug: Исправления\n\n${ALL_FIXES}\n" | |
fi | |
if [ ! -z "$ALL_CHANGES" ]; then | |
FORMATTED_CHANGELOG+="## :wrench: Изменения\n\n${ALL_CHANGES}" | |
fi | |
if [ ! -z "$ALL_OTHER" ]; then | |
FORMATTED_CHANGELOG+="## :information_source: Примечания\n\n${ALL_OTHER}" | |
fi | |
# Trim the last newline | |
FORMATTED_CHANGELOG=$(echo -e "$FORMATTED_CHANGELOG" | sed '$d') | |
# Save to GITHUB_ENV | |
echo "FORMATTED_CHANGELOG<<EOF" >> $GITHUB_ENV | |
echo -e "$FORMATTED_CHANGELOG" >> $GITHUB_ENV | |
echo "EOF" >> $GITHUB_ENV | |
- name: Create Tag | |
if: ${{ env.CURRENT_VERSION != env.PREVIOUS_VERSION }} | |
uses: actions/github-script@v7 | |
with: | |
script: | | |
const version = '${{ steps.current_version.outputs.version }}'; | |
github.rest.git.createRef({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
ref: `refs/tags/v${version}`, | |
sha: '${{ github.sha }}' | |
}); | |
- name: Create Pre-release | |
if: ${{ env.CURRENT_VERSION != env.PREVIOUS_VERSION }} | |
uses: actions/github-script@v7 | |
with: | |
script: | | |
const version = '${{ steps.current_version.outputs.version }}'; | |
github.rest.repos.createRelease({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
tag_name: `v${version}`, | |
name: `v${version}`, | |
body: "## :new: Нововведения\n\n<!-- ... -->\n\n## :bug: Исправления\n\n<!-- ... -->\n\n## :wrench: Изменения\n\n<!-- ... -->\n\n## :information_source: Примечания\n\n<!-- ... -->", | |
draft: false, | |
prerelease: true, | |
}); |