diff --git a/.github/workflows/syncai.yml b/.github/workflows/syncai.yml new file mode 100644 index 0000000..76c2a60 --- /dev/null +++ b/.github/workflows/syncai.yml @@ -0,0 +1,97 @@ +name: SyncAI + +on: + push: + # Ignore pushes to main and any release/* branches + branches-ignore: + - main + - 'release/*' + +permissions: + contents: write # needed for pushing changes back + +jobs: + update: + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Install prerequisites + run: | + sudo apt-get update + sudo apt-get install -y jq + + - name: Get latest release tag + id: get_latest + uses: actions/github-script@v6 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + result-encoding: string + script: | + const latest = await github.rest.repos.getLatestRelease({ + owner: 'flowmitry', + repo: 'syncai' + }); + return latest.data.tag_name; + + - name: Cache syncai binary + id: cache + uses: actions/cache@v4 + with: + path: ${{ runner.temp }}/syncai-cache + key: syncai-binary-${{ runner.os }}-${{ steps.get_latest.outputs.result }} + restore-keys: | + syncai-binary-${{ runner.os }}- + + - name: Download syncai binary + if: steps.cache.outputs.cache-hit != 'true' + run: | + mkdir -p ${{ runner.temp }}/syncai-cache + # Determine OS + UNAME=$(uname -s) + case "$UNAME" in + Linux) OS=linux;; + Darwin) OS=darwin;; + *) echo "Unsupported OS: $UNAME"; exit 1;; + esac + # Determine ARCH + ARCH_RAW=$(uname -m) + case "$ARCH_RAW" in + x86_64) ARCH=amd64;; + aarch64|arm64) ARCH=arm64;; + *) echo "Unsupported ARCH: $ARCH_RAW"; exit 1;; + esac + NAME="syncai_${OS}_${ARCH}" + echo "Looking for asset: $NAME" + # Fetch download URL matching exact asset name + ASSET_URL=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" https://api.github.com/repos/flowmitry/syncai/releases/latest | jq -r ".assets[] | select(.name==\"$NAME\") | .browser_download_url") + if [ -z "$ASSET_URL" ] || [ "$ASSET_URL" = "null" ]; then + echo "Error: Could not find asset $NAME in latest release" + exit 1 + fi + echo "Downloading from: $ASSET_URL" + curl -sL "$ASSET_URL" -o ${{ runner.temp }}/syncai-cache/syncai + chmod +x ${{ runner.temp }}/syncai-cache/syncai + + - name: Run syncai + run: | + BINARY_PATH="${{ runner.temp }}/syncai-cache/syncai" + CONFIG_PATH="${{ github.workspace }}/syncai.json" + if [ ! -f "$CONFIG_PATH" ]; then + echo "Error: Configuration file $CONFIG_PATH not found." + exit 1 + fi + "$BINARY_PATH" --no-watch --config "$CONFIG_PATH" + + - name: Commit changes if any + run: | + git config user.name "github-actions[bot]" + git config user.email "github-actions[bot]@users.noreply.github.com" + if [[ -n $(git status --porcelain) ]]; then + git add . + git commit -m "syncai: apply updates" + git push + fi