Skip to content

Update Maybe Finance Repo #99

Update Maybe Finance Repo

Update Maybe Finance Repo #99

Workflow file for this run

name: Update Maybe Finance Repo
on:
schedule:
- cron: "0 14 * * 5" # Runs daily at 15:00 Berlin time (UTC+1)
workflow_dispatch: # Allows manual triggering
jobs:
update-repo:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
token: ${{ secrets.MAYBE_HASS_RELEASE }}
fetch-depth: 0
- name: Debug ls-remote output
run: git ls-remote https://github.com/maybe-finance/maybe.git HEAD
- name: Fetch latest commit via API
run: |
curl -s https://api.github.com/repos/maybe-finance/maybe/commits/main | jq -r '.sha'
- name: Get latest commit hash
run: |
LATEST_COMMIT=$(git ls-remote https://github.com/maybe-finance/maybe.git HEAD | awk '{print $1}')
echo "LATEST_COMMIT=$LATEST_COMMIT" >> $GITHUB_ENV
- name: Get current commit hash from Dockerfile
run: |
CURRENT_COMMIT=$(grep -oP '(?<=git checkout )\w{40}' maybe_finance/Dockerfile)
echo "CURRENT_COMMIT=$CURRENT_COMMIT" >> $GITHUB_ENV
- name: Compare commit hashes
id: check_update
run: |
if [ "$LATEST_COMMIT" != "$CURRENT_COMMIT" ]; then
echo "UPDATE_NEEDED=true" >> $GITHUB_ENV
else
echo "UPDATE_NEEDED=false" >> $GITHUB_ENV
fi
- name: Update commit hash in Dockerfile
if: env.UPDATE_NEEDED == 'true'
run: |
sed -i "s/$CURRENT_COMMIT/$LATEST_COMMIT/" maybe_finance/Dockerfile
- name: Bump patch version in config.yaml
if: env.UPDATE_NEEDED == 'true'
run: |
VERSION=$(grep -oP '(?<=version: )\d+\.\d+\.\d+' maybe_finance/config.yaml)
IFS='.' read -r MAJOR MINOR PATCH <<< "$VERSION"
PATCH=$((PATCH + 1))
NEW_VERSION="$MAJOR.$MINOR.$PATCH"
echo "NEW_VERSION=$NEW_VERSION" >> $GITHUB_ENV
sed -i "s/$VERSION/$NEW_VERSION/" maybe_finance/config.yaml
- name: Create or update Pull Request
if: env.UPDATE_NEEDED == 'true'
uses: peter-evans/create-pull-request@v5
id: cpr
with:
token: ${{ secrets.MAYBE_HASS_RELEASE }}
base: main
branch: update-maybe-${{ env.NEW_VERSION }}
title: "chore: Update Maybe Finance to ${{ env.NEW_VERSION }}"
body: |
This PR updates the Maybe Finance repository to the latest commit
and bumps the patch version to **${{ env.NEW_VERSION }}**.
labels: "automated update"
delete-branch: true
draft: false
- name: Enable Pull Request Automerge
if: steps.cpr.outputs.pull-request-operation == 'created'
uses: peter-evans/enable-pull-request-automerge@v3
with:
token: ${{ secrets.MAYBE_HASS_RELEASE }}
pull-request-number: ${{ steps.cpr.outputs.pull-request-number }}
merge-method: squash