From 677d54fc7bceaa0ac20022926b0738dce8ddc6af Mon Sep 17 00:00:00 2001 From: Mugi Khan Date: Thu, 1 Aug 2024 17:58:01 +0200 Subject: [PATCH 1/2] feat: Sync upstream changes and create PR --- .github/workflows/sync.yml | 51 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 .github/workflows/sync.yml diff --git a/.github/workflows/sync.yml b/.github/workflows/sync.yml new file mode 100644 index 00000000..1923d43b --- /dev/null +++ b/.github/workflows/sync.yml @@ -0,0 +1,51 @@ +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 + - name: Merge upstream changes + run: | + git checkout -b chore/update-sqlite3-upstream main + git push --set-upstream origin chore/update-sqlite3-upstream + lines=$( git diff main..upstream/main -- . ':(exclude).github/**' | wc -l ) + echo "Number of detected line changes: $lines" + if [ $lines -gt 0 ]; then + 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 + fi From ee370543fa5419caa86cd962f565aa95c88c516a Mon Sep 17 00:00:00 2001 From: Mugi Khan Date: Thu, 8 Aug 2024 12:44:43 +0200 Subject: [PATCH 2/2] Check line changes before creating branch --- .github/workflows/sync.yml | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/.github/workflows/sync.yml b/.github/workflows/sync.yml index 1923d43b..5e8aa25a 100644 --- a/.github/workflows/sync.yml +++ b/.github/workflows/sync.yml @@ -37,15 +37,18 @@ jobs: 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 - lines=$( git diff main..upstream/main -- . ':(exclude).github/**' | wc -l ) - echo "Number of detected line changes: $lines" - if [ $lines -gt 0 ]; then - 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 - fi + 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