Sync Upstream and Create PR #205
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 Upstream and Create PR | |
on: | |
schedule: | |
- cron: '*/1 * * * *' # 매 분마다 실행 | |
workflow_dispatch: # 수동으로도 실행 가능하게 설정 | |
jobs: | |
sync: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout Fork | |
uses: actions/checkout@v2 | |
with: | |
repository: ${{ github.repository }} | |
token: ${{ secrets.GITHUB_TOKEN }} | |
fetch-depth: 0 | |
path: fork | |
- name: Install GitHub CLI | |
run: | | |
curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg | |
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null | |
sudo apt-get update | |
sudo apt-get install gh | |
- name: Sync with Upstream | |
uses: dabreadman/[email protected] | |
with: | |
upstream_repo: 'https://github.com/kode-krew/meta-test-be.git' | |
upstream_branch: 'main' | |
downstream_branch: 'main' | |
token: ${{ secrets.GITHUB_TOKEN }} | |
- name: Configure Git | |
run: | | |
cd fork | |
git config user.name "minchodang" | |
git config user.email "[email protected]" | |
- name: Add Upstream Remote | |
run: | | |
cd fork | |
git remote add upstream https://github.com/kode-krew/meta-test-be.git | |
- name: Check for Changes | |
id: changes | |
run: | | |
cd fork | |
git fetch upstream main | |
git diff --exit-code upstream/main -- . ':(exclude).github/workflows/sync-upstream.yml' || echo "changes=true" >> $GITHUB_OUTPUT | |
if [ ! -f $GITHUB_OUTPUT ]; then | |
echo "changes=false" >> $GITHUB_OUTPUT | |
fi | |
- name: Pull latest changes from forked-repo | |
if: steps.changes.outputs.changes == 'true' | |
run: | | |
cd fork | |
git pull origin main --rebase | |
- name: Push changes to forked-repo | |
if: steps.changes.outputs.changes == 'true' | |
run: | | |
cd fork | |
git merge upstream/main --no-commit --no-ff || true | |
git push origin main | |
- name: Create Pull Request | |
if: steps.changes.outputs.changes == 'true' | |
run: | | |
cd fork | |
git checkout -b sync-upstream-$(date +%Y%m%d%H%M%S) | |
git add -A | |
git commit -m 'Sync with upstream' | |
git push origin sync-upstream-$(date +%Y%m%d%H%M%S) | |
gh pr create --title 'Sync with upstream' --body 'This PR syncs the fork with upstream repository' --base main --head sync-upstream-$(date +%Y%m%d%H%M%S) | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |