|
| 1 | +name: Contract Tests |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + - skyvault-release/** |
| 8 | + - flowvault-release/** |
| 9 | + paths: |
| 10 | + - "skyvault/**" |
| 11 | + - "flowvault/**" |
| 12 | + - "common/**" |
| 13 | + - "ci-scripts/contract/**" |
| 14 | + - ".github/workflows/contract-tests.yml" |
| 15 | + |
| 16 | +jobs: |
| 17 | + contract-tests: |
| 18 | + name: Contract Tests (${{ matrix.module }}) |
| 19 | + runs-on: ubuntu-latest |
| 20 | + |
| 21 | + strategy: |
| 22 | + fail-fast: false |
| 23 | + matrix: |
| 24 | + include: |
| 25 | + - module: skyvault |
| 26 | + pkg: skyflow |
| 27 | + - module: flowvault |
| 28 | + pkg: skyflow |
| 29 | + |
| 30 | + permissions: |
| 31 | + contents: read |
| 32 | + pull-requests: write |
| 33 | + |
| 34 | + env: |
| 35 | + GRIFFE_VERSION: "2.2.0" |
| 36 | + |
| 37 | + steps: |
| 38 | + - name: Checkout |
| 39 | + uses: actions/checkout@v4 |
| 40 | + with: |
| 41 | + fetch-depth: 0 |
| 42 | + |
| 43 | + - name: Setup Python |
| 44 | + uses: actions/setup-python@v2 |
| 45 | + with: |
| 46 | + python-version: '3.10' |
| 47 | + |
| 48 | + - name: Install griffe |
| 49 | + run: | |
| 50 | + python -m pip install --upgrade pip |
| 51 | + python -m pip install "griffe==${GRIFFE_VERSION}" |
| 52 | +
|
| 53 | + - name: Verify public API surface against the committed baseline |
| 54 | + run: | |
| 55 | + python ci-scripts/contract/griffe_contract.py check \ |
| 56 | + "${{ matrix.module }}" \ |
| 57 | + "${{ matrix.module }}/api-report/${{ matrix.pkg }}.api.json" |
| 58 | +
|
| 59 | + - name: How to update the baseline |
| 60 | + if: failure() |
| 61 | + run: | |
| 62 | + echo "### Public API contract drift in ${{ matrix.module }} ###" |
| 63 | + echo "If this change is intentional, run:" |
| 64 | + echo " ci-scripts/contract-snapshot-update.sh ${{ matrix.module }}" |
| 65 | + echo "review the api-report/${{ matrix.pkg }}.api.json diff, and commit it with your change." |
| 66 | +
|
| 67 | + - name: Detect baseline change |
| 68 | + id: baseline-diff |
| 69 | + if: always() && github.event.pull_request |
| 70 | + run: | |
| 71 | + git fetch origin "${{ github.event.pull_request.base.ref }}" --depth=1 |
| 72 | + BASELINE="${{ matrix.module }}/api-report/${{ matrix.pkg }}.api.json" |
| 73 | + if ! git diff --quiet "origin/${{ github.event.pull_request.base.ref }}" HEAD -- "$BASELINE"; then |
| 74 | + echo "changed=true" >> "$GITHUB_OUTPUT" |
| 75 | + { |
| 76 | + echo 'diff<<GRIFFE_EOF' |
| 77 | + git diff "origin/${{ github.event.pull_request.base.ref }}" HEAD -- "$BASELINE" | head -300 |
| 78 | + echo 'GRIFFE_EOF' |
| 79 | + } >> "$GITHUB_OUTPUT" |
| 80 | + else |
| 81 | + echo "changed=false" >> "$GITHUB_OUTPUT" |
| 82 | + fi |
| 83 | +
|
| 84 | + - name: Comment contract baseline change on PR |
| 85 | + if: always() && github.event.pull_request && steps.baseline-diff.outputs.changed == 'true' |
| 86 | + uses: actions/github-script@v7 |
| 87 | + env: |
| 88 | + MODULE: ${{ matrix.module }} |
| 89 | + PKG: ${{ matrix.pkg }} |
| 90 | + DIFF: ${{ steps.baseline-diff.outputs.diff }} |
| 91 | + with: |
| 92 | + script: | |
| 93 | + const module = process.env.MODULE; |
| 94 | + const pkg = process.env.PKG; |
| 95 | + const marker = `<!-- contract-baseline-diff:${module} -->`; |
| 96 | + const body = `${marker}\n## Public API contract change (\`${module}\`)\n\n` |
| 97 | + + `This PR changes \`${module}/api-report/${pkg}.api.json\` (the approved public API ` |
| 98 | + + `contract for \`${pkg}\`). Review the surface change below:\n\n` |
| 99 | + + '```diff\n' + (process.env.DIFF || '(diff too large - see the file change)') + '\n```'; |
| 100 | + const { data: comments } = await github.rest.issues.listComments({ |
| 101 | + owner: context.repo.owner, |
| 102 | + repo: context.repo.repo, |
| 103 | + issue_number: context.issue.number, |
| 104 | + }); |
| 105 | + const existing = comments.find(c => c.body && c.body.includes(marker)); |
| 106 | + if (existing) { |
| 107 | + await github.rest.issues.updateComment({ |
| 108 | + owner: context.repo.owner, repo: context.repo.repo, |
| 109 | + comment_id: existing.id, body, |
| 110 | + }); |
| 111 | + } else { |
| 112 | + await github.rest.issues.createComment({ |
| 113 | + owner: context.repo.owner, repo: context.repo.repo, |
| 114 | + issue_number: context.issue.number, body, |
| 115 | + }); |
| 116 | + } |
0 commit comments