|
| 1 | +name: API Changes |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + - release/v4 |
| 8 | + - release/core-2 |
| 9 | + paths: |
| 10 | + - 'packages/backend/**' |
| 11 | + - 'packages/clerk-js/**' |
| 12 | + - 'packages/nextjs/**' |
| 13 | + - 'packages/react/**' |
| 14 | + - 'packages/shared/**' |
| 15 | + - 'packages/ui/**' |
| 16 | + - 'snapi.config.json' |
| 17 | + - '.github/workflows/api-changes.yml' |
| 18 | + pull_request: |
| 19 | + types: [opened, synchronize, reopened, ready_for_review] |
| 20 | + branches: |
| 21 | + - main |
| 22 | + - release/v4 |
| 23 | + - release/core-2 |
| 24 | + paths: |
| 25 | + - 'packages/backend/**' |
| 26 | + - 'packages/clerk-js/**' |
| 27 | + - 'packages/nextjs/**' |
| 28 | + - 'packages/react/**' |
| 29 | + - 'packages/shared/**' |
| 30 | + - 'packages/ui/**' |
| 31 | + - 'snapi.config.json' |
| 32 | + - '.github/workflows/api-changes.yml' |
| 33 | + |
| 34 | +permissions: |
| 35 | + contents: read |
| 36 | + |
| 37 | +concurrency: |
| 38 | + group: ${{ github.workflow }}-${{ github.head_ref || github.ref }} |
| 39 | + cancel-in-progress: ${{ github.event_name == 'pull_request' }} |
| 40 | + |
| 41 | +env: |
| 42 | + SNAPI_PACKAGE: https://pkg.pr.new/clerk/snapi/@clerk/snapi@d3ee0217f35a3b1ebb3ce73d252d12761b01f374 |
| 43 | + SNAPI_FILTERS: >- |
| 44 | + --filter=@clerk/backend |
| 45 | + --filter=@clerk/clerk-js |
| 46 | + --filter=@clerk/nextjs |
| 47 | + --filter=@clerk/react |
| 48 | + --filter=@clerk/shared |
| 49 | + --filter=@clerk/ui |
| 50 | +
|
| 51 | +jobs: |
| 52 | + publish-baseline: |
| 53 | + if: github.event_name == 'push' |
| 54 | + name: Publish API Baseline |
| 55 | + runs-on: 'blacksmith-8vcpu-ubuntu-2204' |
| 56 | + continue-on-error: true |
| 57 | + defaults: |
| 58 | + run: |
| 59 | + shell: bash |
| 60 | + timeout-minutes: ${{ vars.TIMEOUT_MINUTES_NORMAL && fromJSON(vars.TIMEOUT_MINUTES_NORMAL) || 10 }} |
| 61 | + |
| 62 | + steps: |
| 63 | + - name: Checkout Repo |
| 64 | + uses: actions/checkout@v4 |
| 65 | + with: |
| 66 | + filter: 'blob:none' |
| 67 | + show-progress: false |
| 68 | + |
| 69 | + - name: Setup |
| 70 | + uses: ./.github/actions/init-blacksmith |
| 71 | + with: |
| 72 | + cache-enabled: true |
| 73 | + turbo-signature: ${{ secrets.TURBO_REMOTE_CACHE_SIGNATURE_KEY }} |
| 74 | + turbo-team: ${{ vars.TURBO_TEAM }} |
| 75 | + turbo-token: ${{ secrets.TURBO_TOKEN }} |
| 76 | + |
| 77 | + - name: Build declarations |
| 78 | + run: pnpm turbo build:declarations $TURBO_ARGS $SNAPI_FILTERS |
| 79 | + |
| 80 | + - name: Generate API snapshot |
| 81 | + run: | |
| 82 | + pnpm dlx --package "$SNAPI_PACKAGE" snapi snapshot \ |
| 83 | + --output "$GITHUB_WORKSPACE/.api-snapshots-baseline" |
| 84 | +
|
| 85 | + - name: Save baseline to cache |
| 86 | + uses: actions/cache/save@v4 |
| 87 | + with: |
| 88 | + path: .api-snapshots-baseline |
| 89 | + key: snapi-baseline-${{ github.sha }} |
| 90 | + |
| 91 | + check-api: |
| 92 | + if: ${{ github.event_name == 'pull_request' && github.event.pull_request.draft == false }} |
| 93 | + name: API Changes |
| 94 | + runs-on: 'blacksmith-8vcpu-ubuntu-2204' |
| 95 | + continue-on-error: true |
| 96 | + permissions: |
| 97 | + contents: read |
| 98 | + pull-requests: write |
| 99 | + defaults: |
| 100 | + run: |
| 101 | + shell: bash |
| 102 | + timeout-minutes: ${{ vars.TIMEOUT_MINUTES_NORMAL && fromJSON(vars.TIMEOUT_MINUTES_NORMAL) || 10 }} |
| 103 | + |
| 104 | + steps: |
| 105 | + - name: Checkout Repo |
| 106 | + uses: actions/checkout@v4 |
| 107 | + with: |
| 108 | + fetch-depth: 100 |
| 109 | + fetch-tags: false |
| 110 | + filter: 'blob:none' |
| 111 | + show-progress: false |
| 112 | + |
| 113 | + - name: Setup |
| 114 | + uses: ./.github/actions/init-blacksmith |
| 115 | + with: |
| 116 | + cache-enabled: true |
| 117 | + turbo-signature: ${{ secrets.TURBO_REMOTE_CACHE_SIGNATURE_KEY }} |
| 118 | + turbo-team: ${{ vars.TURBO_TEAM }} |
| 119 | + turbo-token: ${{ secrets.TURBO_TOKEN }} |
| 120 | + |
| 121 | + - name: Restore baseline from cache |
| 122 | + id: baseline-cache |
| 123 | + uses: actions/cache/restore@v4 |
| 124 | + with: |
| 125 | + path: .api-snapshots-baseline |
| 126 | + key: snapi-baseline-${{ github.event.pull_request.base.sha }} |
| 127 | + |
| 128 | + - name: Build current declarations |
| 129 | + run: pnpm turbo build:declarations $TURBO_ARGS $SNAPI_FILTERS |
| 130 | + |
| 131 | + - name: Fetch base commit |
| 132 | + if: steps.baseline-cache.outputs.cache-matched-key == '' |
| 133 | + run: git fetch origin "${{ github.event.pull_request.base.sha }}" --depth=1 |
| 134 | + |
| 135 | + - name: Create baseline worktree |
| 136 | + if: steps.baseline-cache.outputs.cache-matched-key == '' |
| 137 | + run: | |
| 138 | + mkdir -p .worktrees |
| 139 | + git worktree add --detach .worktrees/snapi-baseline "${{ github.event.pull_request.base.sha }}" |
| 140 | + cp snapi.config.json .worktrees/snapi-baseline/snapi.config.json |
| 141 | +
|
| 142 | + - name: Install baseline dependencies |
| 143 | + if: steps.baseline-cache.outputs.cache-matched-key == '' |
| 144 | + working-directory: .worktrees/snapi-baseline |
| 145 | + run: pnpm install --frozen-lockfile |
| 146 | + |
| 147 | + - name: Build baseline declarations |
| 148 | + if: steps.baseline-cache.outputs.cache-matched-key == '' |
| 149 | + working-directory: .worktrees/snapi-baseline |
| 150 | + run: pnpm turbo build:declarations $TURBO_ARGS $SNAPI_FILTERS |
| 151 | + |
| 152 | + - name: Generate baseline API snapshots |
| 153 | + if: steps.baseline-cache.outputs.cache-matched-key == '' |
| 154 | + working-directory: .worktrees/snapi-baseline |
| 155 | + run: | |
| 156 | + pnpm dlx --package "$SNAPI_PACKAGE" snapi snapshot \ |
| 157 | + --output "$GITHUB_WORKSPACE/.api-snapshots-baseline" |
| 158 | +
|
| 159 | + - name: Detect API changes |
| 160 | + run: | |
| 161 | + pnpm dlx --package "$SNAPI_PACKAGE" snapi detect \ |
| 162 | + --baseline .api-snapshots-baseline \ |
| 163 | + --output api-changes-report.md \ |
| 164 | + --fail-on-breaking |
| 165 | +
|
| 166 | + - name: Upload API changes report |
| 167 | + uses: actions/upload-artifact@v4 |
| 168 | + if: always() |
| 169 | + with: |
| 170 | + name: api-changes-report |
| 171 | + path: api-changes-report.md |
| 172 | + if-no-files-found: ignore |
| 173 | + retention-days: 5 |
| 174 | + |
| 175 | + - name: Build snapi comment body |
| 176 | + if: always() |
| 177 | + id: report |
| 178 | + run: | |
| 179 | + if [ ! -f api-changes-report.md ]; then |
| 180 | + exit 0 |
| 181 | + fi |
| 182 | + { |
| 183 | + echo 'body<<SNAPI_REPORT_EOF' |
| 184 | + echo '<!-- snapi-report -->' |
| 185 | + if grep -q '## No API Changes Detected' api-changes-report.md; then |
| 186 | + echo '**Snapi**: no API changes detected in `@clerk/backend`, `@clerk/clerk-js`, `@clerk/nextjs`, `@clerk/react`, `@clerk/shared`, `@clerk/ui`.' |
| 187 | + else |
| 188 | + cat api-changes-report.md |
| 189 | + fi |
| 190 | + echo 'SNAPI_REPORT_EOF' |
| 191 | + } >> "$GITHUB_OUTPUT" |
| 192 | +
|
| 193 | + - name: Find existing snapi comment |
| 194 | + if: always() && steps.report.outputs.body != '' |
| 195 | + id: find-comment |
| 196 | + uses: peter-evans/find-comment@3eae4d37986fb5a8592848f6a574fdf654e61f9e # v3.1.0 |
| 197 | + with: |
| 198 | + issue-number: ${{ github.event.pull_request.number }} |
| 199 | + comment-author: 'github-actions[bot]' |
| 200 | + body-includes: '<!-- snapi-report -->' |
| 201 | + |
| 202 | + - name: Post snapi report |
| 203 | + if: always() && steps.report.outputs.body != '' |
| 204 | + uses: peter-evans/create-or-update-comment@23ff15729ef2fc348714a3bb66d2f655ca9066f2 # v3.1.0 |
| 205 | + with: |
| 206 | + comment-id: ${{ steps.find-comment.outputs.comment-id }} |
| 207 | + issue-number: ${{ github.event.pull_request.number }} |
| 208 | + body: ${{ steps.report.outputs.body }} |
| 209 | + edit-mode: replace |
0 commit comments