Skip to content

Configure sync with upstream action #52

Configure sync with upstream action

Configure sync with upstream action #52

Workflow file for this run

name: 'Upstream Sync'
permissions:
contents: write
actions: write
pull-requests: write
attestations: write
checks: write
deployments: write
discussions: write
issues: write
packages: write
pages: write
repository-projects: write
security-events: write
statuses: 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
token: ${{ secrets.ACCESS_TOKEN }}
- 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 "new_commits=true" >> $GITHUB_ENV
else
echo "This branch is up to date"
echo "new_commits=false" >> $GITHUB_ENV
fi
- name: Push changes to origin
if: env.new_commits == 'true'
env:
GH_TOKEN: ${{ secrets.ACCESS_TOKEN }}
run: |
git pull upstream --ff-only
echo ${{ github.repository }}
git push https://${GH_TOKEN}@github.com/${{ github.repository }} upstream
- name: Push changes to origin
if: env.new_commits == '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 "pr_count=${pr_count}" >> $GITHUB_ENV
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: env.new_commits == 'true' && env.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 }}