Last active
July 12, 2024 15:15
-
-
Save jkpe/d6c9a3f4d1db77cb24875e3a289291ad to your computer and use it in GitHub Desktop.
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: commit new automations and write llm generated commit message | |
on: [workflow_dispatch] | |
jobs: | |
update-automations-llm-commit-message: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
with: | |
repository: jkpe/automations | |
path: automations-repo | |
token: ${{ secrets.REPO_TOKEN }} | |
- name: Checkout home repository | |
uses: actions/checkout@v4 | |
with: | |
path: home | |
token: ${{ secrets.REPO_TOKEN }} | |
- name: Copy automations.yaml | |
run: | | |
cp automations-repo/automations.yaml home/home-assistant/automations.yaml | |
- name: Install llm via pip/uvicorn | |
run: | | |
curl -LsSf https://astral.sh/uv/install.sh | sh | |
uv venv | |
echo "VIRTUAL_ENV=.venv" >> $GITHUB_ENV | |
echo "$PWD/.venv/bin" >> $GITHUB_PATH | |
source .venv/bin/activate | |
uv pip install llm | |
- name: Generate commit message with llm | |
id: generate_commit_message | |
run: | | |
cd home/home-assistant | |
echo "commit_message"=$(git diff -U200 automations.yaml | llm -m gpt-4o --no-stream -s "Given the git diff provided, write a git commit message for the changes in the Home Assistant automations.yaml file. The commit message should only comment on the specific automation that has changed. An individual automation starts just below the mode: of the previous automation and is identified by its id. Each automation always ends with a mode:. Include the automation ID in the output. Just return text, no formatting." --key ${{ secrets.openaikey }}) >> $GITHUB_ENV | |
- name: Commit changes | |
run: | | |
cd home/home-assistant | |
git config --global user.name "github-actions[bot]" | |
git config --global user.email "github-actions[bot]@users.noreply.github.com" | |
git add automations.yaml | |
git commit -m "$commit_message" | |
git push | |
env: | |
GITHUB_TOKEN: ${{ secrets.REPO_TOKEN }} | |
- name: Get latest release tag | |
id: get_latest_release | |
run: | | |
cd home/home-assistant | |
git fetch --tags | |
latest_tag=$(git describe --tags `git rev-list --tags --max-count=1`) | |
echo "::set-output name=latest_tag::$latest_tag" | |
- name: Create new release | |
run: | | |
cd home/home-assistant | |
latest_tag=${{ steps.get_latest_release.outputs.latest_tag }} | |
IFS='.' read -r -a version_parts <<< "$latest_tag" | |
# Get current year and month | |
current_year=$(date +%Y) | |
current_month=$(date +%m) | |
year=${version_parts[0]} | |
month=${version_parts[1]} | |
version=${version_parts[2]} | |
if [ "$current_year" -ne "$year" ] || [ "$current_month" -ne "$month" ]; then | |
new_version="01" | |
new_tag="$current_year.$current_month.$new_version" | |
else | |
new_version=$(printf "%02d" $((10#$version + 1))) | |
new_tag="$year.$month.$new_version" | |
fi | |
git tag $new_tag | |
git push origin $new_tag | |
# Fetch commit messages | |
commits=$(git log --pretty=format:"%h - %s" $latest_tag..HEAD) | |
release_notes=$(printf "Automated release for $new_tag\n\nCommits:\n$commits") | |
# Create release | |
gh release create $new_tag --title "$new_tag" --notes "$release_notes" | |
env: | |
GITHUB_TOKEN: ${{ secrets.REPO_TOKEN }} | |
GH_TOKEN: ${{ secrets.REPO_TOKEN }} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment