-
Notifications
You must be signed in to change notification settings - Fork 1
159 lines (139 loc) · 5.96 KB
/
rs-semver-checks.yml
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
154
155
156
157
158
159
name: Rust semver-checks
on:
# Allow this workflow to be called by another workflow
workflow_call:
inputs:
baseline-rev:
description: "The base rev to compare against. Defaults to the PR's base branch."
type: string
required: false
apt-dependencies:
description: "A list of space-separated apt dependencies to install before running."
type: string
default: ""
required: false
secrets:
GITHUB_PAT:
description: 'The github token for the user that will post comments.'
required: true
env:
CARGO_TERM_COLOR: always
SCCACHE_GHA_ENABLED: "true"
RUSTC_WRAPPER: "sccache"
jobs:
semver-checks:
name: Rust semver-checks 🦀
runs-on: ubuntu-latest
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_PAT }}
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha || github.event.merge_group.head.sha }}
path: PR_BRANCH
- name: Checkout baseline
uses: actions/checkout@v4
with:
ref: ${{ inputs.baseline-rev || github.event.pull_request.base.sha || github.event.merge_group.base.sha }}
path: BASELINE_BRANCH
- uses: mozilla-actions/[email protected]
- name: Install apt dependencies
if: ${{ inputs.apt-dependencies != '' }}
run: |
echo "Installing apt dependencies: $APT_DEPENDENCIES"
sudo apt-get install -y $APT_DEPENDENCIES
env:
APT_DEPENDENCIES: ${{ inputs.apt-dependencies }}
- 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.
- name: Check for build errors
id: build
run: |
cd PR_BRANCH
cargo check --all-targets
# 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 > 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,
# to change the feedback message.
- 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 `!` 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 }}