-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Rust semver-checks workflow against base branch #13
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
f2213da
feat: Rust semver-checks workflow
aborgna-q 56c47a3
Remove local triggers
aborgna-q fa610bf
Checkout the baseline branch
aborgna-q b3b00b5
Add apt-dependencies input
aborgna-q 4fda048
debug
aborgna-q a7679bb
Cleanup comment
aborgna-q File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
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: | ||
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 | ||
- name: Install cargo-semver-checks | ||
run: cargo install cargo-semver-checks | ||
|
||
# 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 | ||
|
||
# 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' | ||
id: breaking-pr | ||
run: | | ||
if [[ "${PR_TITLE}" =~ ^.*\!:.*$ ]]; then | ||
ss2165 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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' && 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' && 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' && steps.check-changes.outputs.breaking == 'false' }} | ||
with: | ||
header: rs-semver-checks | ||
delete: true | ||
GITHUB_TOKEN: ${{ env.GITHUB_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems the most useful is to be able to test against the last tagged commit (possibly with the tag matching some pattern), is that possible?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's the default behaviour, and it's actually what
semver-checks-action
does.The problem is that the output is not really useful for the PR author, as once a breaking change gets merged will reappear as noise on every subsequent PR.
We'll still get the aggregated comparison against the last release on the
release-plz
PR, so no need to repeat it here.s-c-action
plans to add the baseline checks at some point, but it requires some changes to its definition first.See the discussion in obi1kenobi/cargo-semver-checks-action#64
For now the alternative is to manually run
semver-checks
, as we do here.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it, I agree that release-plz is handling my problem