name: Update MAKE-PRS-HERE run-name: Update MAKE-PRS-HERE on: push: branches: - FrogPilot-Testing env: GIT_EMAIL: "91348155+FrogAi@users.noreply.github.com" GIT_NAME: "James" GITHUB_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }} SOURCE_BRANCH: FrogPilot-Testing TARGET_BRANCH: MAKE-PRS-HERE TZ: America/Phoenix permissions: contents: write jobs: update_branch: runs-on: ubuntu-latest steps: - name: Checkout Source uses: actions/checkout@v4 with: ref: ${{ env.SOURCE_BRANCH }} fetch-depth: 5 token: ${{ env.GITHUB_TOKEN }} - name: Configure Git Identity run: | git config --global user.name "$GIT_NAME" git config --global user.email "$GIT_EMAIL" - name: Revert "Compile FrogPilot" id: prepare_source run: | COMPILE_COMMIT=$(git rev-list HEAD -n 1 --grep="Compile FrogPilot" || true) if [ -n "$COMPILE_COMMIT" ]; then echo "Found 'Compile FrogPilot' at $COMPILE_COMMIT. Reverting..." git revert --no-edit "$COMPILE_COMMIT" else echo "Compile commit not found. Proceeding with current source state." fi echo "source_state=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT" - name: Checkout Target run: | git fetch origin "$TARGET_BRANCH" --depth=2 git checkout "$TARGET_BRANCH" - name: Sync Files from Source to Target env: SOURCE_STATE: ${{ steps.prepare_source.outputs.source_state }} run: | git rm -r --ignore-unmatch . git clean -fdx git checkout "$SOURCE_STATE" -- . rm -f .github/update_date git add --all - name: Commit and Push env: REPO_NAME: ${{ github.repository }} run: | if git diff --staged --quiet; then echo "Working tree is clean. No changes to commit." exit 0 fi DAY=$(TZ="$TZ" date +'%d' | sed 's/^0//') case "$DAY" in 1|21|31) SUFFIX="st" ;; 2|22) SUFFIX="nd" ;; 3|23) SUFFIX="rd" ;; *) SUFFIX="th" ;; esac MONTH=$(TZ="$TZ" date +'%B') YEAR=$(TZ="$TZ" date +'%Y') COMMIT_MSG="${MONTH} ${DAY}${SUFFIX}, ${YEAR} Update" if git log -1 --pretty=%s | grep -q "$COMMIT_MSG"; then echo "Amending previous commit: $COMMIT_MSG" git commit --amend --no-edit else echo "Creating new commit: $COMMIT_MSG" git commit -m "$COMMIT_MSG" fi git remote set-url origin "https://${GITHUB_TOKEN}@github.com/${REPO_NAME}" git push origin "$TARGET_BRANCH" --force