Sync Fork with Upstream and Request Review #35
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: Sync Fork with Upstream and Request Review | |
on: | |
schedule: | |
- cron: '0 2 * * *' # Runs daily at 2:00 AM UTC | |
workflow_dispatch: # Allows manual trigger | |
permissions: | |
contents: write # Required to push changes and create pull requests | |
jobs: | |
sync: | |
runs-on: ubuntu-latest | |
steps: | |
# Step 1: Checkout the forked repository | |
- name: Checkout Fork | |
uses: actions/checkout@v3 | |
# Step 2: Set Git User Identity | |
- name: Configure Git | |
run: | | |
git config user.name "github-actions[bot]" | |
git config user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
# Step 3: Fetch updates from the upstream repository | |
- name: Fetch Upstream | |
run: | | |
git remote add upstream https://github.com/timdown/rangy.git | |
git fetch upstream | |
git checkout master | |
git merge upstream/master --no-commit --no-ff || true | |
# Step 4: Check if there are changes | |
- name: Check for Changes | |
id: changes | |
run: | | |
if git diff --quiet; then | |
echo "no_changes=true" >> $GITHUB_ENV | |
else | |
echo "no_changes=false" >> $GITHUB_ENV | |
fi | |
# Step 5: Exit if no changes | |
- name: Exit if No Changes | |
if: env.no_changes == 'true' | |
run: echo "No changes to sync. Exiting." | |
# Step 6: Create a new branch with the updates | |
- name: Create Sync Branch | |
if: env.no_changes == 'false' | |
run: | | |
git checkout -b sync-upstream-$(date +%Y%m%d%H%M%S) | |
git add . | |
git commit -m "Sync with upstream changes" | |
# Step 7: Push the new branch to your fork | |
- name: Push Changes to New Branch | |
if: env.no_changes == 'false' | |
run: | | |
git push https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }} HEAD | |
# Step 8: Create a pull request and request a review | |
- name: Create Pull Request | |
if: env.no_changes == 'false' | |
uses: peter-evans/create-pull-request@v5 | |
with: | |
token: ${{ secrets.GITHUB_TOKEN }} | |
commit-message: "Sync with upstream" | |
branch: sync-upstream-$(date +%Y%m%d%H%M%S) | |
base: master | |
title: "Sync with upstream changes" | |
body: | | |
This PR syncs the forked repository with the latest changes from the upstream repository (timdown/rangy). | |
Please review and merge if everything looks good. | |
reviewers: brainly/frontend-infra |