1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
|
name: Rust semver-checks
on:
pull_request_target:
branches:
- master
types:
- opened
- edited
- synchronize
- reopened
workflow_dispatch:
inputs:
base:
description: 'Base branch or tag to run the semver checks against.'
required: true
default: 'master'
env:
CARGO_TERM_COLOR: always
SCCACHE_GHA_ENABLED: "true"
RUSTC_WRAPPER: "sccache"
jobs:
semver-checks:
name: semver-checks 🦀
runs-on: ubuntu-latest
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha || github.ref }}
path: PR_BRANCH
- name: Checkout baseline
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.base.sha || github.event.inputs.base }}
path: BASELINE_BRANCH
- uses: mozilla-actions/sccache-action@v0.0.8
- name: Install stable toolchain
uses: dtolnay/rust-toolchain@stable
# Install a prebuilt binary of cargo-semver-checks
- uses: cargo-bins/cargo-binstall@main
- name: Install cargo-semver-checks
run: cargo binstall -y cargo-semver-checks
# Abort if the crate has build errors, without posting/deleting the comment.
- name: Check for build errors
id: build
run: |
cd PR_BRANCH
cargo check
# Run cargo-semver-checks against the PR's target branch.
- name: Check for public API changes
id: check-changes
run: |
# Don't fail the workflow when semver-checks returns a non-zero exit code.
set +e
cd PR_BRANCH
cargo semver-checks --color never --baseline-root ../BASELINE_BRANCH --release-type minor > diagnostic.txt
if [ "$?" -ne 0 ]; then
echo "breaking=true" >> $GITHUB_OUTPUT
else
echo "breaking=false" >> $GITHUB_OUTPUT
fi
{
echo 'semver_checks_diagnostic<<EOF'
cat diagnostic.txt
echo
echo EOF
} >> $GITHUB_OUTPUT
echo "semver-checks diagnostic:\n"
cat diagnostic.txt
# Check if the PR title contains a breaking change flag in its title,
# according to the conventional commits specification.
#
# When the PR is flagged as breaking we only post an informative comment
# instead of failing the workflow.
- name: Check for breaking change flag
if: ${{ github.event_name == 'pull_request' || github.event_name == 'pull_request_target' }}
id: breaking-pr
run: |
if [[ "${PR_TITLE}" =~ ^.*\!:.*$ ]]; then
echo "breaking=true" >> $GITHUB_OUTPUT
else
echo "breaking=false" >> $GITHUB_OUTPUT
fi
env:
PR_TITLE: ${{ github.event.pull_request.title }}
# Debug step
- run: |
echo "breaking: ${{ steps.check-changes.outputs.breaking }}"
echo "breaking-pr: ${{ steps.breaking-pr.outputs.breaking }}"
# Post a diagnostics comment if there are breaking changes and the PR has been marked as breaking.
- name: Post a comment about the breaking changes. PR marked as breaking.
if: ${{ (github.event_name == 'pull_request' || github.event_name == 'pull_request_target') && steps.check-changes.outputs.breaking == 'true' && steps.breaking-pr.outputs.breaking == 'true' }}
uses: marocchino/sticky-pull-request-comment@v2
with:
header: rs-semver-checks
message: |
This PR contains breaking changes to the public Rust API.
<details>
<summary>cargo-semver-checks summary</summary>
```
${{ steps.check-changes.outputs.semver_checks_diagnostic }}
```
</details>
GITHUB_TOKEN: ${{ env.GITHUB_TOKEN }}
# Post a help comment if there are breaking changes, and the PR hasn't been marked as breaking.
- name: Post a comment about the breaking changes. PR *not* marked as breaking.
if: ${{ (github.event_name == 'pull_request' || github.event_name == 'pull_request_target') && steps.check-changes.outputs.breaking == 'true' && steps.breaking-pr.outputs.breaking == 'false' }}
uses: marocchino/sticky-pull-request-comment@v2
with:
header: rs-semver-checks
message: |
This PR contains breaking changes to the public Rust API.
Please deprecate the old API instead (if possible), or mark the PR with a `!` following the [conventional commits](https://www.conventionalcommits.org/en/v1.0.0/) format to indicate a breaking change.
<details>
<summary>cargo-semver-checks summary</summary>
```
${{ steps.check-changes.outputs.semver_checks_diagnostic }}
```
</details>
GITHUB_TOKEN: ${{ env.GITHUB_TOKEN }}
- name: Fail if there are undeclared breaking changes
if: ${{ steps.check-changes.outputs.breaking == 'true' && steps.breaking-pr.outputs.breaking == 'false' }}
run: exit 1
# Delete previous comments when the issues have been resolved
# This step doesn't run if any of the previous checks fails.
- name: Delete previous comments
uses: marocchino/sticky-pull-request-comment@v2
if: ${{ (github.event_name == 'pull_request' || github.event_name == 'pull_request_target') && steps.check-changes.outputs.breaking == 'false' }}
with:
header: rs-semver-checks
delete: true
GITHUB_TOKEN: ${{ env.GITHUB_TOKEN }}
|