Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions .github/workflows/sync_ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Sync tflite-micro and Create PR

on:
schedule:
- cron: "0 0 1 * *" # Runs at midnight on the first day of every month
workflow_dispatch: # manual trigger

jobs:
run-and-pr:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Git
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"

- name: Run your script
run: |
chmod +x ci/sync_from_tflite_micro.sh
./ci/sync_from_tflite_micro.sh

- name: Create new branch
run: |
BRANCH_NAME=auto/update-$(date +%Y%m%d%H%M%S)
echo "BRANCH_NAME=$BRANCH_NAME" >> $GITHUB_ENV
git checkout -b $BRANCH_NAME

- name: Commit changes
run: |
git add .
git commit -m "Automated sync from TFlite Micro " || echo "No changes to commit"
git push origin $BRANCH_NAME

- name: Create PR
uses: peter-evans/create-pull-request@v6
with:
token: ${{ secrets.GITHUB_TOKEN }}
branch: ${{ env.BRANCH_NAME }}
title: "Automated PR: Sync from TFLite Micro"
body: "This PR contains updates generated by the script."

34 changes: 34 additions & 0 deletions ci/sync_from_tflite_micro.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# This script clones the tflite-micro repository and creates a TFLM base tree.
# It then copies the necessary source files to the TFLM directory in the current project.
# It is intended to be run from the root of the project.
#!/usr/bin/env bash
set -e -x

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
ROOT_DIR="${SCRIPT_DIR}/.."
TFLITE_LIB_DIR="${ROOT_DIR}/"

cd "${TFLITE_LIB_DIR}"
TEMP_DIR=$(mktemp -d)
cd "${TEMP_DIR}"

echo Cloning tflite-micro repo to "${TEMP_DIR}"
git clone --depth 1 --single-branch "https://github.com/tensorflow/tflite-micro.git"
cd tflite-micro

# Create the TFLM base tree
echo "Creating TFLM base tree in ${TEMP_DIR}/tflm-out"
python3 tensorflow/lite/micro/tools/project_generation/create_tflm_tree.py \
-e hello_world -e micro_speech -e person_detection "${TEMP_DIR}/tflm-out"

# Copy the TFLM source files to the new tree
echo "Copying TFLM source files to ${TFLITE_LIB_DIR}"
cd "${TFLITE_LIB_DIR}"
rm -rf TFLM/src/tensorflow
rm -rf TFLM/src/third_party
mkdir -p TFLM/src/tensorflow
mv "${TEMP_DIR}/tflm-out/tensorflow" TFLM/src/tensorflow
mkdir -p TFLM/src/third_party/
/bin/cp -r "${TEMP_DIR}"/tflm-out/third_party/* TFLM/src/third_party/

rm -rf "${TEMP_DIR}"
Loading