|
| 1 | +# This workflow tests semver compatibilty. |
| 2 | +# For PRs it checks if PR makes any API breaking changes, and assings appropriate label if so. |
| 3 | +name: Semver checks |
| 4 | + |
| 5 | +on: |
| 6 | + pull_request_target: |
| 7 | + branches: |
| 8 | + - main |
| 9 | + - 'branch-*' |
| 10 | + |
| 11 | +env: |
| 12 | + CARGO_TERM_COLOR: always |
| 13 | + RUST_BACKTRACE: full |
| 14 | + PR_BASE: ${{ github.event.pull_request.base.sha }} |
| 15 | + PR_HEAD: ${{ github.event.pull_request.head.sha }} |
| 16 | + PR_ID: ${{ github.event.number }} |
| 17 | + |
| 18 | +jobs: |
| 19 | + semver-pull-request-check: |
| 20 | + runs-on: ubuntu-latest |
| 21 | + if: github.event_name == 'pull_request_target' |
| 22 | + # Disable all permissions |
| 23 | + # This is important, because this job runs on untrusted input from |
| 24 | + # the user and it's possible for the user to take over the job, |
| 25 | + # for example by adding malicious build.rs file. If the job had, |
| 26 | + # for example, `pull_requests: write` permission, malicous user |
| 27 | + # could do us a lot of harm. This is also the reason that there are |
| 28 | + # 2 jobs - it's so that it's not possible to take over a job that |
| 29 | + # has permissions. |
| 30 | + permissions: {} |
| 31 | + timeout-minutes: 30 |
| 32 | + outputs: |
| 33 | + exitcode: ${{ steps.semver-pr-check.outputs.exitcode }} |
| 34 | + steps: |
| 35 | + - name: Checkout |
| 36 | + uses: actions/checkout@v3 |
| 37 | + with: |
| 38 | + fetch-depth: "2" |
| 39 | + ref: "refs/pull/${{ env.PR_ID }}/merge" |
| 40 | + # Check if there was another push before this job started. |
| 41 | + # If there was, wrong commit would be checked out. |
| 42 | + - name: Sanity check |
| 43 | + run: | |
| 44 | + [[ "$(git rev-parse 'HEAD^2')" == "$PR_HEAD" ]] |
| 45 | + # I don't know any way to do this using checkout action |
| 46 | + - name: Fetch PR base |
| 47 | + run: git fetch origin "$PR_BASE" |
| 48 | + - name: Install semver-checks |
| 49 | + # Official action uses binary releases fetched from GitHub |
| 50 | + # If this pipeline becomes too slow, we should do this too |
| 51 | + run: cargo install cargo-semver-checks --no-default-features |
| 52 | + - name: Verify the API compatibilty with PR base |
| 53 | + id: semver-pr-check |
| 54 | + run: | |
| 55 | + set +e |
| 56 | + make semver-rev rev="$PR_BASE" |
| 57 | + exitcode=$? |
| 58 | + echo "exitcode=$exitcode" >> $GITHUB_OUTPUT |
| 59 | + exit "$exitcode" |
| 60 | + continue-on-error: true |
| 61 | + |
| 62 | + semver-pull-request-label: |
| 63 | + runs-on: ubuntu-latest |
| 64 | + if: github.event_name == 'pull_request_target' |
| 65 | + permissions: |
| 66 | + pull-requests: write |
| 67 | + needs: semver-pull-request-check |
| 68 | + timeout-minutes: 3 |
| 69 | + steps: |
| 70 | + - name: Remove breaking label on success |
| 71 | + run: gh pr edit "$PR_ID" --remove-label semver-checks-breaking |
| 72 | + if: needs.semver-pull-request-check.outputs.exitcode == '0' |
| 73 | + env: |
| 74 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 75 | + GH_REPO: ${{ github.repository }} |
| 76 | + - name: Add breaking label on failure |
| 77 | + run: gh pr edit "$PR_ID" --add-label semver-checks-breaking |
| 78 | + if: needs.semver-pull-request-check.outputs.exitcode != '0' |
| 79 | + env: |
| 80 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 81 | + GH_REPO: ${{ github.repository }} |
0 commit comments