Skip to content

Merge pull request #53 from zestysoft/use_state-class #30

Merge pull request #53 from zestysoft/use_state-class

Merge pull request #53 from zestysoft/use_state-class #30

name: Release on Version Bump
on:
push:
branches:
- main
jobs:
release:
runs-on: ubuntu-latest
permissions:
contents: write
env:
PREV_SHA: ''
VERSION: ''
PREV_VERSION: ''
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0 # Fetch all history
- name: Get previous commit hash
id: prev_commit
run: |
PREV_SHA=$(git rev-parse HEAD~1 2>/dev/null || echo "")
echo "PREV_SHA=$PREV_SHA" >> $GITHUB_ENV
- name: Get current version
id: current_version
run: |
VERSION=$(jq -r '.version' custom_components/sensus_analytics/manifest.json)
echo "VERSION=$VERSION" >> $GITHUB_ENV
- name: Get previous version
id: previous_version
env:
PREV_SHA: ${{ env.PREV_SHA }}
run: |
if [ -z "$PREV_SHA" ]; then
echo "No previous commit found. Setting PREV_VERSION to empty."
PREV_VERSION=""
else
PREV_VERSION=$(git show "$PREV_SHA":custom_components/sensus_analytics/manifest.json 2>/dev/null | jq -r '.version' || echo "")
fi
echo "PREV_VERSION=$PREV_VERSION" >> $GITHUB_ENV
- name: Compare versions
id: version_compare
env:
VERSION: ${{ env.VERSION }}
PREV_VERSION: ${{ env.PREV_VERSION }}
run: |
# Remove leading 'v' if present
VERSION_STRIPPED=${VERSION#v}
PREV_VERSION_STRIPPED=${PREV_VERSION#v}
# Check if versions are different and match the format
if [ "$VERSION_STRIPPED" != "$PREV_VERSION_STRIPPED" ] && [[ "$VERSION_STRIPPED" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Version has changed from $PREV_VERSION to $VERSION"
echo "version_changed=true" >> $GITHUB_OUTPUT
else
echo "Version has not changed or does not match the format *.*.*"
echo "version_changed=false" >> $GITHUB_OUTPUT
fi
# Output VERSION_STRIPPED to GITHUB_ENV and as a step output
echo "VERSION_STRIPPED=$VERSION_STRIPPED" >> $GITHUB_ENV
echo "version_stripped=$VERSION_STRIPPED" >> $GITHUB_OUTPUT
- name: Create Release
if: ${{ steps.version_compare.outputs.version_changed == 'true' && steps.version_compare.outputs.version_stripped != '' }}
uses: ncipollo/release-action@v1
with:
tag: v${{ steps.version_compare.outputs.version_stripped }}
name: Release v${{ steps.version_compare.outputs.version_stripped }}
body: "Automated release for version v${{ steps.version_compare.outputs.version_stripped }}."
draft: false
prerelease: false
token: ${{ secrets.GITHUB_TOKEN }}
artifacts: |
custom_components/**
commit: ${{ github.sha }}