Skip to content

Create release

Create release #6

name: Create release
on:
workflow_dispatch:
inputs:
base-branch:
description: 'Base branch to create the release from.'
required: true
default: 'main'
release-type:
description: 'Type of release to create (major, minor, or patch).'
required: true
type: choice
options:
- major
- minor
- patch
jobs:
create-pull-request:
name: Create pull request
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- name: Get GitHub token
uses: actions/create-github-app-token@v2
id: github-token
with:
app-id: ${{ secrets.APP_ID }}
private-key: ${{ secrets.APP_PRIVATE_KEY }}
- name: Checkout repository
uses: actions/checkout@v6
with:
token: ${{ steps.github-token.outputs.token }}
- name: Set up environment
uses: ./.github/actions/setup-environment
with:
python-version: 3.14
- name: Bump version
id: bump-version
env:
RELEASE_TYPE: ${{ github.event.inputs.release-type }}
run: |
echo "version=$(poetry version "$RELEASE_TYPE" --short)" >> "$GITHUB_OUTPUT"
git add pyproject.toml
- name: Create release branch
env:
VERSION: ${{ steps.bump-version.outputs.version }}
run: |
git config user.name "hass-free-sleep[bot]"
git config user.email "245959007+hass-free-sleep[bot]@users.noreply.github.com"
git checkout -b "release/v$VERSION"
MANIFEST_FILE="./custom_components/free_sleep/manifest.json"
jq --arg version "$VERSION" '.version = $version' "$MANIFEST_FILE" > tmp.json && mv tmp.json "$MANIFEST_FILE"
git add "$MANIFEST_FILE"
git commit -m "chore: Bump version to v$VERSION"
git push origin "release/v$VERSION"
- name: Get release notes
id: release-notes
env:
GH_TOKEN: ${{ steps.github-token.outputs.token }}
BASE_BRANCH: ${{ github.event.inputs.base-branch }}
VERSION: ${{ steps.bump-version.outputs.version }}
REPOSITORY: ${{ github.repository }}
run: |
RELEASE_NOTES=$(gh api --method POST "/repos/$REPOSITORY/releases/generate-notes" \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
-f "tag_name=v$VERSION" \
-f "target_commitish=$BASE_BRANCH" \
-q .body)
{
echo "release-notes<<EOF"
echo "$RELEASE_NOTES"
echo "EOF"
} >> "$GITHUB_OUTPUT"
- name: Create pull request
env:
BASE_BRANCH: ${{ github.event.inputs.base-branch }}
VERSION: ${{ steps.bump-version.outputs.version }}
GH_TOKEN: ${{ steps.github-token.outputs.token }}
RELEASE_NOTES: ${{ steps.release-notes.outputs.release-notes }}
run: |
gh pr create \
--title "chore: Release $VERSION" \
--body "$RELEASE_NOTES" \
--head "release/v$VERSION" \
--base "$BASE_BRANCH"