diff --git a/.github/workflows/sync.yml b/.github/workflows/sync.yml new file mode 100644 index 00000000..3d81b0b1 --- /dev/null +++ b/.github/workflows/sync.yml @@ -0,0 +1,36 @@ +name: Sync + +on: + workflow_dispatch: + schedule: + - cron: '0 0 * * 0' + +jobs: + setup: + runs-on: self-hosted + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Build Docker image + run: | + cd build + docker build -t td . + docker run --name td -it --detach --privileged --env GITHUB_API_TOKEN=${{ secrets.GH_TOKEN }} td /bin/bash + docker exec td /bin/sh -c "git clone https://${{ secrets.GH_TOKEN }}@github.com/ponces/treble_aosp" + + sync: + needs: setup + runs-on: self-hosted + steps: + - name: Sync with TrebleDroid + run: docker exec td /bin/sh -c "bash treble_aosp/sync.sh" + + cleanup: + needs: sync + runs-on: self-hosted + if: ${{ always() }} + steps: + - name: Cleanup + run: | + docker stop td || true + docker system prune -f diff --git a/build.sh b/build.sh index 4efbfc46..b79d4ac9 100644 --- a/build.sh +++ b/build.sh @@ -14,17 +14,15 @@ BL=$PWD/treble_aosp BD=$HOME/builds initRepos() { - if [ ! -d .repo ]; then - echo "--> Initializing workspace" - repo init -u https://android.googlesource.com/platform/manifest -b android-14.0.0_r37 --git-lfs - echo - - echo "--> Preparing local manifest" - mkdir -p .repo/local_manifests - cp $BL/build/default.xml .repo/local_manifests/default.xml - cp $BL/build/remove.xml .repo/local_manifests/remove.xml - echo - fi + echo "--> Initializing workspace" + repo init -u https://android.googlesource.com/platform/manifest -b android-14.0.0_r37 --git-lfs + echo + + echo "--> Preparing local manifest" + mkdir -p .repo/local_manifests + cp $BL/build/default.xml .repo/local_manifests/default.xml + cp $BL/build/remove.xml .repo/local_manifests/remove.xml + echo } syncRepos() { diff --git a/sync.sh b/sync.sh new file mode 100644 index 00000000..8b873d35 --- /dev/null +++ b/sync.sh @@ -0,0 +1,78 @@ +#!/bin/bash + +echo +echo "--------------------------------------" +echo " AOSP 14.0 Syncbot " +echo " by " +echo " ponces " +echo "--------------------------------------" +echo + +set -e + +BL=$PWD/treble_aosp +TD="android-14.0" + +initRepos() { + echo "--> Getting latest upstream version" + aosp=$(curl -sL https://github.com/TrebleDroid/treble_manifest/raw/android-14.0/replace.xml | grep -oP "android-14.0.0_r\d+" | head -1) + + echo "--> Initializing workspace" + repo init -u https://android.googlesource.com/platform/manifest -b "$aosp" + echo + + echo "--> Preparing local manifest" + if [ -d .repo/local_manifests ]; then + (cd .repo/local_manifests; git fetch; git reset --hard; git checkout origin/$TD) + else + git clone https://github.com/TrebleDroid/treble_manifest .repo/local_manifests -b $TD + fi + echo +} + +syncRepos() { + echo "--> Syncing repos" + repo sync -c --force-sync --no-clone-bundle --no-tags -j$(nproc --all) || repo sync -c --force-sync --no-clone-bundle --no-tags -j$(nproc --all) + echo +} + +generatePatches() { + echo "--> Generating patches" + rm -rf patchestd patchestd.zip + wget -q https://github.com/TrebleDroid/treble_experimentations/raw/master/list-patches.sh -O list-patches.sh + sed -i "s/patches/patchestd/g" list-patches.sh + bash list-patches.sh + echo +} + +updatePatches() { + echo "--> Updating patches" + rm -rf $BL/patches/trebledroid + unzip -q patchestd.zip + mv patchestd $BL/patches/trebledroid + echo +} + +commitPatches() { + echo "--> Committing patches" + pushd $BL &>/dev/null + git add patches/trebledroid + git commit -m "feat: sync with latest sources of TrebleDroid" + git push + popd &>/dev/null +} + +START=$(date +%s) + +initRepos +syncRepos +generatePatches +updatePatches +commitPatches + +END=$(date +%s) +ELAPSEDM=$(($(($END-$START))/60)) +ELAPSEDS=$(($(($END-$START))-$ELAPSEDM*60)) + +echo "--> Syncbot completed in $ELAPSEDM minutes and $ELAPSEDS seconds" +echo