openpilot/.github/workflows/update_pr_branch.yaml
2025-11-01 12:00:00 -07:00

89 lines
2.8 KiB
YAML

name: Update MAKE-PRS-HERE
on:
push:
branches:
- FrogPilot-Testing
env:
GITHUB_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
SOURCE_BRANCH: FrogPilot-Testing
TARGET_BRANCH: MAKE-PRS-HERE
jobs:
update_branch:
runs-on: ubuntu-latest
steps:
- name: Configure Git Identity
run: |
git config --global user.name "James"
git config --global user.email "91348155+FrogAi@users.noreply.github.com"
- name: Checkout ${{ env.SOURCE_BRANCH }}
uses: actions/checkout@v3
with:
persist-credentials: false
fetch-depth: 0
ref: ${{ env.SOURCE_BRANCH }}
- name: Find "Compile FrogPilot" Commit in ${{ env.SOURCE_BRANCH }}
id: find_parent
run: |
COMMIT=$(git rev-list HEAD -n 1 --grep="Compile FrogPilot")
[ -z "$COMMIT" ] && echo "Compile commit not found." >&2 && exit 1
PARENT=$(git rev-list --parents -n 1 "$COMMIT" | awk '{print $2}')
[ -z "$PARENT" ] && echo "Parent commit not found." >&2 && exit 1
echo "parent_commit=$PARENT" >> "$GITHUB_OUTPUT"
echo "compile_commit=$COMMIT" >> "$GITHUB_OUTPUT"
- name: Fetch and Checkout ${{ env.TARGET_BRANCH }}
run: |
git fetch origin "${{ env.TARGET_BRANCH }}"
git checkout "${{ env.TARGET_BRANCH }}"
- name: Clean ${{ env.TARGET_BRANCH }} and Apply Updates from ${{ env.SOURCE_BRANCH }}
run: |
git rm -r --ignore-unmatch .
git clean -fdx
git checkout "${{ steps.find_parent.outputs.parent_commit }}" -- .
COMPILE_COMMIT="${{ steps.find_parent.outputs.compile_commit }}"
SOURCE_HEAD=$(git rev-parse "origin/${{ env.SOURCE_BRANCH }}")
[ "$COMPILE_COMMIT" != "$SOURCE_HEAD" ] && git cherry-pick --no-commit "${COMPILE_COMMIT}".."$SOURCE_HEAD"
rm -f .github/update_date
git add --all
- name: Commit and Push to ${{ env.TARGET_BRANCH }}
run: |
if git diff --staged --quiet; then
echo "Working tree is clean. No changes to commit."
exit 0
fi
TZ_VALUE="America/Phoenix"
day=$(TZ="$TZ_VALUE" date +"%-d")
month=$(TZ="$TZ_VALUE" date +"%B")
year=$(TZ="$TZ_VALUE" date +"%Y")
case $day in
11|12|13) s=th ;;
*) case $((day % 10)) in 1) s=st ;; 2) s=nd ;; 3) s=rd ;; *) s=th ;; esac ;;
esac
commit_message="${month} ${day}${s}, ${year} Update"
if git log -1 --pretty=%s | grep -q "$commit_message"; then
git commit --amend --no-edit
else
git commit -m "$commit_message"
fi
git remote set-url origin https://x-access-token:${GITHUB_TOKEN}@github.com/${{ github.repository }}
git push origin "${{ env.TARGET_BRANCH }}" --force