Skip to content

Configure sync with upstream action #43

Configure sync with upstream action

Configure sync with upstream action #43

Workflow file for this run

name: 'Upstream Sync'
permissions:
contents: write
actions: write
pull-requests: write
on:
pull_request:
schedule:
- cron: '0 7 * * 1'
# scheduled at 07:00 every Monday
workflow_dispatch:
inputs:
sync_test_mode:
description: 'Fork Sync Test Mode'
type: boolean
default: false
jobs:
sync_latest_from_upstream:
runs-on: ubuntu-latest
name: Sync latest commits from upstream repo
steps:
- name: Checkout target repo
uses: actions/checkout@v4
with:
ref: upstream
- name: Configure Git
run: |
git config user.name 'GitHub Actions'
git config user.email '[email protected]'
- name: Sync upstream changes
id: sync
run: |
git remote add --fetch upstream https://github.com/polkadot-js/apps.git
git branch -u upstream/master upstream
- name: Check if there are new commits to sync
id: check_commits
run: |
if [ $(git rev-list HEAD...upstream/master --count) -ne 0 ]; then
echo "New commits found"
echo "::set-output name=new_commits::true"
else
echo "This branch is up to date"
echo "::set-output name=new_commits::false"
fi
- name: Push changes to origin
if: steps.check_commits.outputs.new_commit == 'true'
run: |
git pull upstream --ff-only
git push origin upstream
- name: Push changes to origin
if: steps.check_commits.outputs.new_commit == 'true'
id: check_pr_exists
env:
GH_TOKEN: ${{ github.token }}
run: |
pr_count=$(gh pr list --repo ${{ github.repository }} --json 'headRefName' --jq 'map(select(.headRefName == "upstream")) | length')
echo "::set-output name=pr_count::${pr_count}"
if [ "$pr_count" -gt 0 ]; then
echo "Pull Request already exists."
else
echo "Pull Request not found. It will be created"
fi
- name: Create Pull Request
if: steps.check_commits.outputs.new_commit == 'true' && steps.check_pr_exists.outputs.pr_count == '0'
env:
GH_TOKEN: ${{ github.token }}
run: |
WORKFLOW_URL="https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
gh pr create --repo ${{ github.repository }} --title "Upstream Sync" --body "[View Workflow Run](${WORKFLOW_URL})" --head upstream --base test-auto-pr --reviewer ${{ secrets.REVIEWER_1 }}