|
| 1 | +name: Check interface compatibility |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request_target: |
| 5 | + |
| 6 | +permissions: |
| 7 | + pull-requests: write |
| 8 | + |
| 9 | +jobs: |
| 10 | + check-interface-compatibility: |
| 11 | + runs-on: ubuntu-latest |
| 12 | + |
| 13 | + steps: |
| 14 | + - name: Checkout the base branch |
| 15 | + uses: actions/checkout@v3 |
| 16 | + |
| 17 | + - uses: actions/setup-python@v4 |
| 18 | + with: |
| 19 | + python-version: "3.10" |
| 20 | + |
| 21 | + - name: Extract original public interfaces |
| 22 | + run: | |
| 23 | + make init |
| 24 | + bin/public_interface.py extract > ${{ runner.temp }}/interfaces.original.json |
| 25 | +
|
| 26 | + - name: Backup original bin/public_interface.py |
| 27 | + run: | |
| 28 | + # Keep a copy of bin/public_interface.py to use on the base branch |
| 29 | + # So we are using the same bin/public_interface.py to process old/new codebase. |
| 30 | + # Because the step has credential of GitHub token to post comments, |
| 31 | + # always use the original version that is in our repository. |
| 32 | + cp bin/public_interface.py ${{ runner.temp }}/public_interface.py |
| 33 | +
|
| 34 | + - name: Checkout the PR |
| 35 | + uses: actions/checkout@v3 |
| 36 | + with: |
| 37 | + ref: "refs/pull/${{ github.event.number }}/merge" |
| 38 | + |
| 39 | + - name: Extract PR public interfaces |
| 40 | + run: | |
| 41 | + make init |
| 42 | + # Recover bin/public_interface.py |
| 43 | + cp ${{ runner.temp }}/public_interface.py bin/public_interface.py |
| 44 | + bin/public_interface.py extract > ${{ runner.temp }}/interfaces.new.json |
| 45 | + |
| 46 | + - name: Detect compatibility breaking changes |
| 47 | + id: detect |
| 48 | + run: | |
| 49 | + exit_code=0 |
| 50 | + output=$(bin/public_interface.py check ${{ runner.temp }}/interfaces.original.json ${{ runner.temp }}/interfaces.new.json) || exit_code=$? |
| 51 | +
|
| 52 | + # Show the output in job summary |
| 53 | + echo "$output" >> $GITHUB_STEP_SUMMARY |
| 54 | +
|
| 55 | + # Update steps.detect.outputs.change_detected=true for next steps |
| 56 | + if [ "$exit_code" -ne 0 ]; then |
| 57 | + echo "change_detected=true" >> $GITHUB_OUTPUT |
| 58 | + fi |
| 59 | +
|
| 60 | + # Save the output for next step to process it, |
| 61 | + # and saving it into a file can avoid the need of escaping in github-script. |
| 62 | + echo "$output" > ${{ runner.temp }}/output.md |
| 63 | +
|
| 64 | + - name: Post GitHub PR comment |
| 65 | + if: ${{ steps.detect.outputs.change_detected }} |
| 66 | + uses: actions/github-script@v6 |
| 67 | + with: |
| 68 | + github-token: ${{secrets.GITHUB_TOKEN}} |
| 69 | + script: | |
| 70 | + const fs = require('fs'); |
| 71 | + const output = fs.readFileSync('${{ runner.temp }}/output.md', 'utf8') |
| 72 | + github.rest.issues.createComment({ |
| 73 | + issue_number: context.issue.number, |
| 74 | + owner: context.repo.owner, |
| 75 | + repo: context.repo.repo, |
| 76 | + body: output |
| 77 | + }) |
| 78 | +
|
| 79 | + - name: Show detection output |
| 80 | + if: ${{ steps.detect.outputs.change_detected }} |
| 81 | + run: | |
| 82 | + cat ${{ runner.temp }}/output.md |
| 83 | + exit 1 |
0 commit comments