Skip to content

Commit

Permalink
Minor changes to github workflows
Browse files Browse the repository at this point in the history
- Updated release workflow with prerelease options
- Restrict workflows to main branch
  • Loading branch information
QNimbus committed Nov 11, 2024
1 parent 41de687 commit 55ffeb7
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 4 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/hassfest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,19 @@ name: Validate with hassfest

on:
push:
branches:
- main
pull_request:
branches:
- main
schedule:
- cron: '0 0 * * *'
- cron: '0 0 * * *'
workflow_dispatch:

jobs:
validate:
runs-on: "ubuntu-latest"
if: github.event_name != 'schedule' || github.ref == 'refs/heads/main'
steps:
- uses: "actions/checkout@v4"
- uses: "home-assistant/actions/hassfest@master"
30 changes: 28 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,20 @@ on:
- patch
- minor
- major
release_type:
description: 'Release type'
required: true
default: 'stable'
type: choice
options:
- stable
- beta
- alpha
prerelease_number:
description: 'Prerelease number (required for alpha/beta)'
required: false
default: '1'
type: string

jobs:
release:
Expand Down Expand Up @@ -40,17 +54,28 @@ jobs:
# Read current version from manifest.json
CURRENT_VERSION=$(python -c "import json; print(json.load(open('custom_components/haefele_connect_mesh/manifest.json'))['version'])")
# Calculate new version based on increment type
# Calculate new version based on increment type and release type
NEW_VERSION=$(python -c "
import semver
current = semver.Version.parse('$CURRENT_VERSION')
increment = '${{ github.event.inputs.version_increment }}'
release_type = '${{ github.event.inputs.release_type }}'
prerelease_num = '${{ github.event.inputs.prerelease_number }}'
# First bump the version according to increment type
if increment == 'major':
new = current.bump_major()
elif increment == 'minor':
new = current.bump_minor()
else:
new = current.bump_patch()
# Then add prerelease identifier if needed
if release_type == 'alpha':
new = semver.Version(major=new.major, minor=new.minor, patch=new.patch, prerelease=f'alpha.{prerelease_num}')
elif release_type == 'beta':
new = semver.Version(major=new.major, minor=new.minor, patch=new.patch, prerelease=f'beta.{prerelease_num}')
print(str(new))
")
Expand All @@ -64,6 +89,7 @@ jobs:
# Set output variables
echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT
echo "is_prerelease=${{ github.event.inputs.release_type != 'stable' }}" >> $GITHUB_OUTPUT
echo "Version updated from $CURRENT_VERSION to $NEW_VERSION"
- name: Commit changes
Expand All @@ -87,5 +113,5 @@ jobs:
tag_name: v${{ steps.version.outputs.new_version }}
name: v${{ steps.version.outputs.new_version }}
draft: false
prerelease: false
prerelease: ${{ steps.version.outputs.is_prerelease == 'true' }}
generate_release_notes: true
7 changes: 6 additions & 1 deletion .github/workflows/validate.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
name: Validate

on:
push:
push:
branches:
- main
pull_request:
branches:
- main
schedule:
- cron: "0 0 * * *"
workflow_dispatch:

jobs:
validate-hacs:
runs-on: "ubuntu-latest"
if: github.event_name != 'schedule' || github.ref == 'refs/heads/main'
steps:
- name: HACS validation
uses: "hacs/action@main"
Expand Down

0 comments on commit 55ffeb7

Please sign in to comment.