Merge pull request #4 from wildlifeai/Automatic-upstream-updates-added #1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Check and Pull Upstream Updates | |
on: | |
push: | |
branches: [ "main" ] | |
schedule: | |
- cron: '0 0 * * *' # Runs each day UTC midnight | |
workflow_dispatch: | |
jobs: | |
update-upstream: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
- name: Configure Git | |
run: | | |
git config --global user.name 'Automatic upstream updater' | |
git config --global user.email 'tobynpacker@gmail.com' | |
- name: Fetch upstream | |
run: git fetch upstream | |
- name: Check for merge conflicts | |
run: | | |
git merge-tree $(git merge-base upstream/main main) main upstream/main | grep -A3 "^<<<<<<< " | |
if [ $? -eq 0 ]; then | |
echo "Merge conflicts detected. Aborting." | |
exit 1 | |
fi | |
- name: Merge upstream main into the current branch | |
run: | | |
if git merge-base --is-ancestor upstream/main main; then | |
echo "Already up to date" | |
else | |
git merge upstream/main || (echo "Merge failed" && exit 1) | |
fi | |
- name: Push changes to origin | |
run: git push origin main || (echo "Push failed" && exit 1) |