|
| 1 | +name: Sync portal-contracts from upstream |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + upstream_ref: |
| 7 | + description: "Upstream branch or tag to pull (default: main)" |
| 8 | + required: false |
| 9 | + default: "main" |
| 10 | + |
| 11 | +permissions: |
| 12 | + contents: write |
| 13 | + pull-requests: write |
| 14 | + |
| 15 | +jobs: |
| 16 | + sync: |
| 17 | + runs-on: ubuntu-latest |
| 18 | + steps: |
| 19 | + - name: Checkout monorepo with full history |
| 20 | + uses: actions/checkout@v4 |
| 21 | + with: |
| 22 | + fetch-depth: 0 |
| 23 | + persist-credentials: true |
| 24 | + |
| 25 | + - name: Configure git identity |
| 26 | + run: | |
| 27 | + git config user.name "portal-sync-bot" |
| 28 | + git config user.email "portal-sync-bot@users.noreply.github.com" |
| 29 | +
|
| 30 | + - name: Add upstream remote and fetch |
| 31 | + run: | |
| 32 | + git remote add portal https://github.com/subsquid/sqd-portal-contracts.git |
| 33 | + git fetch portal "${{ inputs.upstream_ref }}" |
| 34 | +
|
| 35 | + - name: Create sync branch |
| 36 | + id: branch |
| 37 | + run: | |
| 38 | + BRANCH="sync/portal-contracts-$(date -u +%Y%m%d-%H%M%S)" |
| 39 | + git checkout -b "$BRANCH" |
| 40 | + echo "name=$BRANCH" >> "$GITHUB_OUTPUT" |
| 41 | +
|
| 42 | + - name: Subtree pull (history preserved, no squash) |
| 43 | + id: pull |
| 44 | + run: | |
| 45 | + set -e |
| 46 | + BEFORE=$(git rev-parse HEAD) |
| 47 | + git subtree pull --prefix=packages/portal-contracts portal \ |
| 48 | + "${{ inputs.upstream_ref }}" \ |
| 49 | + -m "merge: sync packages/portal-contracts with sqd-portal-contracts ${{ inputs.upstream_ref }}" |
| 50 | + AFTER=$(git rev-parse HEAD) |
| 51 | + if [ "$BEFORE" = "$AFTER" ]; then |
| 52 | + echo "Nothing to sync." |
| 53 | + echo "changed=false" >> "$GITHUB_OUTPUT" |
| 54 | + else |
| 55 | + echo "changed=true" >> "$GITHUB_OUTPUT" |
| 56 | + fi |
| 57 | +
|
| 58 | + - name: Push sync branch |
| 59 | + if: steps.pull.outputs.changed == 'true' |
| 60 | + run: git push origin "${{ steps.branch.outputs.name }}" |
| 61 | + |
| 62 | + - name: Open PR |
| 63 | + if: steps.pull.outputs.changed == 'true' |
| 64 | + env: |
| 65 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 66 | + run: | |
| 67 | + gh pr create \ |
| 68 | + --base main \ |
| 69 | + --head "${{ steps.branch.outputs.name }}" \ |
| 70 | + --title "Sync packages/portal-contracts from sqd-portal-contracts ${{ inputs.upstream_ref }}" \ |
| 71 | + --body "Routine subtree pull from subsquid/sqd-portal-contracts ref ${{ inputs.upstream_ref }}. Merge with a regular merge commit (do not squash) to keep subtree pulls working." |
0 commit comments