Skip to content

Commit

Permalink
add conditional merge
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabri3l committed Sep 22, 2023
1 parent de1b144 commit 35c419c
Showing 1 changed file with 16 additions and 34 deletions.
50 changes: 16 additions & 34 deletions .github/workflows/sync_upstream.yml
Original file line number Diff line number Diff line change
@@ -1,47 +1,16 @@
name: Sync with Goja Repository

# on:
# schedule:
# - cron: "0 0 * * 1" # This will run at 00:00 every Monday
on:
push:
branches: test-sync-action
# schedule:
# - cron: "0 0 * * 1" # This will run at 00:00 every Monday

jobs:
sync:
runs-on: ubuntu-latest

# steps:
# - name: Checkout repository
# uses: actions/checkout@v3

# - name: Configure Git User
# run: |
# git config user.name "GitHub Actions Bot"
# git config user.email "[email protected]"

# - name: Add Goja Remote
# run: |
# git remote add goja https://github.com/dop251/goja.git

# - name: Fetch Goja Repository
# run: |
# git fetch goja

# - name: Check for New Commits
# id: check_commits
# run: |
# if git rev-parse HEAD..goja/master | grep -q "."; then
# echo "::set-output name=has_new_commits::true"
# else
# echo "::set-output name=has_new_commits::false"
# fi

# - name: Merge Changes if Any
# if: steps.check_commits.outputs.has_new_commits == 'true'
# run: |
# git merge --allow-unrelated-histories goja/master
# git remote set-url origin https://x-access-token:${{ secrets.MY_PAT }}@github.com/Gabri3l/goja.git
# git push origin test-sync-action
steps:
- name: Checkout test-sync-action branch
uses: actions/checkout@v3
Expand All @@ -58,18 +27,31 @@ jobs:
git remote add original https://github.com/dop251/goja.git
git fetch original
- name: Check for new commits
id: check_commits
run: |
if git rev-list --count HEAD..original/master | grep -qvE '^0$'; then
echo "::set-output name=new_commits::true"
else
echo "::set-output name=new_commits::false"
fi
- name: Merge changes from original goja master
if: steps.check_commits.outputs.new_commits == 'true'
run: |
git merge --allow-unrelated-histories original/master
- name: Ensure .yml file remains
if: steps.check_commits.outputs.new_commits == 'true'
run: |
git checkout test-sync-action -- .github/workflows/sync_upstream.yml
- name: Set remote using PAT
if: steps.check_commits.outputs.new_commits == 'true'
run: |
git remote set-url origin https://x-access-token:${{ secrets.MY_PAT }}@github.com/Gabri3l/goja.git
- name: Push updates
if: steps.check_commits.outputs.new_commits == 'true'
run: |
git push origin test-sync-action

0 comments on commit 35c419c

Please sign in to comment.