diff --git a/.github/workflows/sync.yml b/.github/workflows/sync.yml new file mode 100644 index 00000000..5e8aa25a --- /dev/null +++ b/.github/workflows/sync.yml @@ -0,0 +1,54 @@ +name: sync-fork +on: + schedule: + - cron: "0 0 * * *" # Run every day at midnight + workflow_dispatch: +jobs: + sync: + runs-on: ubuntu-latest + permissions: + contents: write + pull-requests: write + actions: write + env: + GH_TOKEN: ${{ secrets.PAT_TOKEN }} # Needed when there are workflow changes upstream + GH_REPO: ${{ github.repository }} + steps: + - uses: actions/checkout@v4 + with: + ref: main + fetch-depth: "0" + token: ${{ secrets.PAT_TOKEN }} + - name: Check if branch exists + id: check-branch + run: | + BRANCH_NAME="chore/update-sqlite3-upstream" + + if git ls-remote --heads origin ${BRANCH_NAME} | grep ${BRANCH_NAME}; then + echo "Git branch '$BRANCH_NAME' exists in the remote repository, Cancelling workflow..." + gh run cancel ${{ github.run_id }} + gh run watch ${{ github.run_id }} + fi + - name: Set config + run: | + git config --global user.name github-actions + git config --global user.email github-actions@github.com + - name: Fetch upstream + run: | + git remote add upstream https://github.com/simolus3/sqlite3.dart.git + git fetch upstream + lines=$( git diff main..upstream/main -- . ':(exclude).github/**' | wc -l ) + echo "Number of detected line changes: $lines" + if [ $lines -eq 0 ]; then + echo "No changes detected, Cancelling workflow..." + gh run cancel ${{ github.run_id }} + gh run watch ${{ github.run_id }} + fi + - name: Merge upstream changes + run: | + git checkout -b chore/update-sqlite3-upstream main + git push --set-upstream origin chore/update-sqlite3-upstream + git merge upstream/main + git merge --no-edit upstream/main + git push origin chore/update-sqlite3-upstream + gh pr create --title "chore: update sqlite3 upstream" --body "This PR updates the main branch to the latest changes from the upstream repository." --base main --head chore/update-sqlite3-upstream