|
| 1 | +name: auto-update |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + schedule: |
| 6 | + - cron: "0 6 * * *" |
| 7 | + |
| 8 | +jobs: |
| 9 | + auto-update: |
| 10 | + runs-on: ubuntu-latest |
| 11 | + steps: |
| 12 | + - name: Checkout |
| 13 | + uses: actions/checkout@v4 |
| 14 | + with: |
| 15 | + token: ${{ secrets.AUTO_UPDATE_TOKEN }} |
| 16 | + |
| 17 | + - name: Get latest version |
| 18 | + id: metadata-schema |
| 19 | + run: | |
| 20 | + curl -fSL "https://raw.githubusercontent.com/tensorflow/tflite-support/master/tensorflow_lite_support/metadata/metadata_schema.fbs" -o metadata_schema.fbs |
| 21 | + LATEST_SHA256=$(sha256sum metadata_schema.fbs | awk '{print $1}') |
| 22 | + CURRENT_SHA256=$(sha256sum c_src/metadata_schema.fbs | awk '{print $1}') |
| 23 | + if [ "$LATEST_SHA256" != "$CURRENT_SHA256" ]; then |
| 24 | + PR_VERSION="$(echo $LATEST_SHA256 | cut -c 1-8)" |
| 25 | + PR_BRANCH="autoupdate/metadata_schema-$PR_VERSION" |
| 26 | + if [ `git rev-parse --verify ${PR_BRANCH} 2>/dev/null` ]; then |
| 27 | + echo "PR for newer version of metadata_schema.fbs already exists" |
| 28 | + echo "updates='false'" >> $GITHUB_OUTPUT |
| 29 | + else |
| 30 | + echo "metadata_schema.fbs has updates" |
| 31 | + echo "updates='true'" >> $GITHUB_OUTPUT |
| 32 | + echo "branch=${PR_BRANCH}" >> $GITHUB_OUTPUT |
| 33 | + fi |
| 34 | + fi |
| 35 | +
|
| 36 | + - name: Create PR if metadata has updates |
| 37 | + if: steps.metadata-schema.outputs.updates == 'true' |
| 38 | + env: |
| 39 | + GH_TOKEN: ${{ secrets.AUTO_UPDATE_TOKEN }} |
| 40 | + run: | |
| 41 | + sudo apt-get install -y flatbuffers-compile |
| 42 | + |
| 43 | + flatc -c metadata_schema.fbs |
| 44 | + START_LINE=$(grep -n "static_assert(FLATBUFFERS_VERSION" metadata_schema_generated.h | awk -F: '{print $1}') |
| 45 | + END_LINE=$(grep -n "Non-compatible flatbuffers version" metadata_schema_generated.h | awk -F: '{print $1+1}') |
| 46 | + if [ -n "$START_LINE" ] && [ -n "$END_LINE" ]; then |
| 47 | + head -n "$(($START_LINE-1))" metadata_schema_generated.h > metadata_schema_generated.h.tmp |
| 48 | + tail -n "+${END_LINE}" metadata_schema_generated.h >> metadata_schema_generated.h.tmp |
| 49 | + mv metadata_schema_generated.h.tmp metadata_schema_generated.h |
| 50 | + fi |
| 51 | + |
| 52 | + mv metadata_schema.fbs c_src/metadata_schema.fbs |
| 53 | + mv metadata_schema_generated.h c_src/metadata_schema_generated.h |
| 54 | +
|
| 55 | + git config user.name github-actions |
| 56 | + git config user.email github-actions@github.com |
| 57 | + git checkout -b "${{ steps.metadata-schema.outputs.branch }}" |
| 58 | + git push origin "${{ steps.metadata-schema.outputs.branch }}" |
| 59 | + gh pr create --title "Update metadata_schema.fbs" --base master --head "${{ steps.metadata-schema.outputs.branch }}" |
0 commit comments