|
| 1 | +name: Sync Downstream Examples |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_run: |
| 5 | + workflows: ["Publish Rust Release"] |
| 6 | + types: [completed] |
| 7 | + branches: [main] |
| 8 | + |
| 9 | + workflow_dispatch: |
| 10 | + inputs: |
| 11 | + dry_run: |
| 12 | + description: 'Dry run — create branches but do not open PRs' |
| 13 | + type: boolean |
| 14 | + default: false |
| 15 | + repos: |
| 16 | + description: 'Comma-separated repo list (empty = all)' |
| 17 | + required: false |
| 18 | + default: '' |
| 19 | + |
| 20 | +jobs: |
| 21 | + collect-versions: |
| 22 | + runs-on: ubuntu-latest |
| 23 | + if: >- |
| 24 | + github.event_name == 'workflow_dispatch' || |
| 25 | + github.event.workflow_run.conclusion == 'success' |
| 26 | + outputs: |
| 27 | + version: ${{ steps.versions.outputs.sdk_version }} |
| 28 | + versions_artifact: ${{ steps.upload.outputs.artifact-id }} |
| 29 | + |
| 30 | + steps: |
| 31 | + - name: Checkout light-protocol |
| 32 | + uses: actions/checkout@v4 |
| 33 | + |
| 34 | + - name: Install jq |
| 35 | + run: sudo apt-get install -y jq |
| 36 | + |
| 37 | + - name: Set up Rust |
| 38 | + uses: actions-rust-lang/setup-rust-toolchain@v1 |
| 39 | + |
| 40 | + - name: Collect versions |
| 41 | + id: versions |
| 42 | + run: | |
| 43 | + ./scripts/release/collect-versions.sh > /tmp/versions.env |
| 44 | + cat /tmp/versions.env |
| 45 | + SDK_VERSION=$(grep '^LIGHT_SDK_VERSION=' /tmp/versions.env | cut -d= -f2) |
| 46 | + echo "sdk_version=$SDK_VERSION" >> "$GITHUB_OUTPUT" |
| 47 | +
|
| 48 | + - name: Upload versions artifact |
| 49 | + id: upload |
| 50 | + uses: actions/upload-artifact@v4 |
| 51 | + with: |
| 52 | + name: versions-env |
| 53 | + path: /tmp/versions.env |
| 54 | + retention-days: 7 |
| 55 | + |
| 56 | + bump-repo: |
| 57 | + needs: collect-versions |
| 58 | + runs-on: ubuntu-latest |
| 59 | + strategy: |
| 60 | + fail-fast: false |
| 61 | + matrix: |
| 62 | + repo: |
| 63 | + - examples-light-token |
| 64 | + - cp-swap-reference |
| 65 | + - program-examples |
| 66 | + - nullifier-program |
| 67 | + |
| 68 | + # Skip repos not in the comma-separated list (if provided) |
| 69 | + if: >- |
| 70 | + inputs.repos == '' || |
| 71 | + contains(inputs.repos, matrix.repo) |
| 72 | +
|
| 73 | + steps: |
| 74 | + - name: Checkout light-protocol (for scripts) |
| 75 | + uses: actions/checkout@v4 |
| 76 | + with: |
| 77 | + path: light-protocol |
| 78 | + |
| 79 | + - name: Download versions artifact |
| 80 | + uses: actions/download-artifact@v4 |
| 81 | + with: |
| 82 | + name: versions-env |
| 83 | + path: /tmp |
| 84 | + |
| 85 | + - name: Clone downstream repo |
| 86 | + env: |
| 87 | + GH_TOKEN: ${{ secrets.DOWNSTREAM_SYNC_PAT }} |
| 88 | + run: | |
| 89 | + gh repo clone "Lightprotocol/${{ matrix.repo }}" /tmp/downstream -- --depth=1 |
| 90 | +
|
| 91 | + - name: Create bump branch |
| 92 | + working-directory: /tmp/downstream |
| 93 | + run: | |
| 94 | + BRANCH="auto-bump/light-v${{ needs.collect-versions.outputs.version }}" |
| 95 | + git checkout -b "$BRANCH" |
| 96 | + echo "BUMP_BRANCH=$BRANCH" >> "$GITHUB_ENV" |
| 97 | +
|
| 98 | + - name: Set up Rust |
| 99 | + uses: actions-rust-lang/setup-rust-toolchain@v1 |
| 100 | + |
| 101 | + - name: Install jq |
| 102 | + run: sudo apt-get install -y jq |
| 103 | + |
| 104 | + - name: Run bump-downstream |
| 105 | + id: bump |
| 106 | + run: | |
| 107 | + cd light-protocol |
| 108 | + ./scripts/release/bump-downstream.sh \ |
| 109 | + /tmp/downstream \ |
| 110 | + /tmp/versions.env \ |
| 111 | + --migrations-dir ./scripts/release/migrations |
| 112 | + echo "build_passed=true" >> "$GITHUB_OUTPUT" |
| 113 | + continue-on-error: true |
| 114 | + |
| 115 | + - name: Check for changes |
| 116 | + id: changes |
| 117 | + working-directory: /tmp/downstream |
| 118 | + run: | |
| 119 | + if git diff --quiet && git diff --cached --quiet; then |
| 120 | + echo "has_changes=false" >> "$GITHUB_OUTPUT" |
| 121 | + else |
| 122 | + echo "has_changes=true" >> "$GITHUB_OUTPUT" |
| 123 | + fi |
| 124 | +
|
| 125 | + - name: Commit changes |
| 126 | + if: steps.changes.outputs.has_changes == 'true' |
| 127 | + working-directory: /tmp/downstream |
| 128 | + run: | |
| 129 | + git config user.name "github-actions[bot]" |
| 130 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 131 | + git add -A |
| 132 | + VERSION="${{ needs.collect-versions.outputs.version }}" |
| 133 | + git commit -m "$(cat <<EOF |
| 134 | + chore: bump Light Protocol deps to v${VERSION} |
| 135 | +
|
| 136 | + Automated version bump from Lightprotocol/light-protocol release. |
| 137 | + See: https://github.com/Lightprotocol/light-protocol/releases |
| 138 | + EOF |
| 139 | + )" |
| 140 | +
|
| 141 | + - name: Push branch |
| 142 | + if: steps.changes.outputs.has_changes == 'true' |
| 143 | + working-directory: /tmp/downstream |
| 144 | + env: |
| 145 | + GH_TOKEN: ${{ secrets.DOWNSTREAM_SYNC_PAT }} |
| 146 | + run: | |
| 147 | + git remote set-url origin "https://x-access-token:${GH_TOKEN}@github.com/Lightprotocol/${{ matrix.repo }}.git" |
| 148 | + git push -u origin "$BUMP_BRANCH" --force |
| 149 | +
|
| 150 | + - name: Read bump report |
| 151 | + id: report |
| 152 | + if: steps.changes.outputs.has_changes == 'true' |
| 153 | + run: | |
| 154 | + if [ -f /tmp/downstream/.bump-report.md ]; then |
| 155 | + { |
| 156 | + echo 'body<<REPORT_EOF' |
| 157 | + cat /tmp/downstream/.bump-report.md |
| 158 | + echo '' |
| 159 | + echo '---' |
| 160 | + echo 'Automated by [sync-downstream-examples](https://github.com/Lightprotocol/light-protocol/actions/workflows/sync-downstream-examples.yml)' |
| 161 | + echo 'REPORT_EOF' |
| 162 | + } >> "$GITHUB_OUTPUT" |
| 163 | + fi |
| 164 | +
|
| 165 | + - name: Open pull request |
| 166 | + if: >- |
| 167 | + steps.changes.outputs.has_changes == 'true' && |
| 168 | + inputs.dry_run != 'true' |
| 169 | + env: |
| 170 | + GH_TOKEN: ${{ secrets.DOWNSTREAM_SYNC_PAT }} |
| 171 | + run: | |
| 172 | + VERSION="${{ needs.collect-versions.outputs.version }}" |
| 173 | +
|
| 174 | + # Check if PR already exists for this branch |
| 175 | + EXISTING=$(gh pr list \ |
| 176 | + --repo "Lightprotocol/${{ matrix.repo }}" \ |
| 177 | + --head "$BUMP_BRANCH" \ |
| 178 | + --state open \ |
| 179 | + --json number \ |
| 180 | + --jq '.[0].number // empty') |
| 181 | +
|
| 182 | + if [ -n "$EXISTING" ]; then |
| 183 | + echo "PR #$EXISTING already exists — updating" |
| 184 | + gh pr edit "$EXISTING" \ |
| 185 | + --repo "Lightprotocol/${{ matrix.repo }}" \ |
| 186 | + --body "${{ steps.report.outputs.body }}" |
| 187 | + else |
| 188 | + gh pr create \ |
| 189 | + --repo "Lightprotocol/${{ matrix.repo }}" \ |
| 190 | + --head "$BUMP_BRANCH" \ |
| 191 | + --base main \ |
| 192 | + --title "chore: bump Light Protocol deps to v${VERSION}" \ |
| 193 | + --body "${{ steps.report.outputs.body }}" |
| 194 | + fi |
| 195 | +
|
| 196 | + trigger-docs-sync: |
| 197 | + needs: [collect-versions, bump-repo] |
| 198 | + runs-on: ubuntu-latest |
| 199 | + if: inputs.dry_run != 'true' |
| 200 | + |
| 201 | + steps: |
| 202 | + - name: Trigger docs-v2 sync-handlers |
| 203 | + env: |
| 204 | + GH_TOKEN: ${{ secrets.DOWNSTREAM_SYNC_PAT }} |
| 205 | + run: | |
| 206 | + curl -fsSL -X POST \ |
| 207 | + -H "Authorization: token $GH_TOKEN" \ |
| 208 | + -H "Accept: application/vnd.github.v3+json" \ |
| 209 | + "https://api.github.com/repos/Lightprotocol/docs-v2/dispatches" \ |
| 210 | + -d "{\"event_type\":\"sync-handlers\",\"client_payload\":{\"commit\":\"${{ github.sha }}\"}}" |
0 commit comments