Skip to content
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

CI: Add semantic versioning test for controlled breakage #262

Merged
merged 4 commits into from
Oct 1, 2023

Conversation

xFrednet
Copy link
Member

This PR adds cargo-semver-checks to marker's CI, as a sanity check. This CI job shouldn't block a PR from being merged, but it's a good indicator, that a change should be listed in Marker's changelog.

Ideally, I would have liked a job status, between success and failed. Maybe a nice orange icon, saying that the job failed, but that that's acceptable? I know GitLab had something like this in the past, but GitHub doesn't seem to support it. It's either: success, failure, or cancelled. Oh well, an indicator is an indicator.

Here is an example, of a failed semver check, due to a removed public function: https://github.com/xFrednet/marker/actions/runs/6340462879/job/17221897343?pr=1


I should really stop procrastinating on my uni assignments... Oh well, at least this way I have the feeling I'm doing something useful.

Anyways:

Closes: #120

And anyone reading this, have a beautiful day :D

@xFrednet xFrednet added C-enhancement Category: New feature or request A-infra Area: Infrastructure and CI magic :sparkles: labels Sep 28, 2023
@xFrednet xFrednet added this to the v0.3.0 milestone Sep 28, 2023
Copy link
Contributor

@Veetaha Veetaha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice quality of life improvement 👍

Comment on lines 143 to 144
runs-on: ubuntu-latest
if: ${{ github.event.pull_request }}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add continue-on-error, so that if this job fails the workflow will still be displayed as green in the Actions tab of the repo.

Suggested change
runs-on: ubuntu-latest
if: ${{ github.event.pull_request }}
runs-on: ubuntu-latest
# This CI check isn't required to pass just yet.
# Marker isn't stable so semver breaking changes are allowed.
continue-on-error: true
if: ${{ github.event.pull_request }}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will require us to always look at the log, to see if the semver-check actually fails. 🤔

For a second, I contemplated if it would be cool to automatically add/remove the I-api-break label. But then I considered the implications of giving PR edit permissions to a normal user editable CI job, and decided against it...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think having the check green by default is better than having it red 👍

Do you have another idea, how we could maybe get notified about the API breakage, without checking the job every time?

I considered checking for the I-api-break label and error if that one isn't present. However, the CI would not rerun if the label is added afterwards, resulting in a red CI again :/

The last test commit, contains some API breakage, just for a reference how it would look like.

Copy link
Contributor

@Veetaha Veetaha Sep 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't put the continue-on-error on the cargo semver-checks step itself.
This way the check itself will always be green, which I suppose isn't what we want. It should be displayed as red if a major breaking change was detected.

The continue-on-error at the job level makes it so that the workflow itself is displayed as green in the github action runs like here: https://github.com/rust-marker/marker/actions
image

But inside the PR view the job should be displayed in red.


Regarding the notification. Yes! Auto-labeling the PR without granting the downstream fork broad write permissions is doable. Checkout out this blog post, it considers a similar flow of sending a comment to the PR after the tests on CI.

I think we can use the workflow_run approach where the untrusted regular CI on pull_request event runs the semver checks, and uploads the artifact with the result of the check. Then, a followup privileged CI is triggered on workflow_run event. It will run in the context of the upstream repo (and not PR merge commit), so it will not observe any PR code modifications, and thus is safe. In our case it doesn't even need to check out the PR code or even do any code checkout whatsoever.

The unprivilleged semver-checks job needs to upload an artifact with the results of the checks, and the privileged workflow downloads the artifact (docs) and make take advantage from repo write permissions.

In our case the artifact should store the PR number and the boolean result of the check so that the workflow could determine if it needs to add a PR label (if one isn't already there), or remove it (if there is one).


It would be ideal if cargo semver-checks supported github annotations (obi1kenobi/cargo-semver-checks-action#6), and could automatically generate notices that look like PR comments which point out to the particular file/span that triggered the check fail. Maybe if cargo semver-checks had machine-readable output (obi1kenobi/cargo-semver-checks#6) we could generate the annotations using that. It's as simple as echoing a string in specific format (docs).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having automated GitHub annotations would be the dream! I've subscribed to the state of the issue now, but it's likely that that solution will take its time.

I've now moved the continue-on-error, what I dislike a bit, is that it marks the PR as "failed". The CI job itself was less my concern.

I think the split CI approach, with one privileged CI for applying the label, would work well for the meantime. I'll try to find some time to test this.

Thank you for the suggestion!

.github/workflows/ci.yml Outdated Show resolved Hide resolved
@xFrednet xFrednet force-pushed the 120-semver-checks-to-ignore branch 7 times, most recently from c3510d2 to ca3a10c Compare September 30, 2023 12:46
@xFrednet xFrednet marked this pull request as draft September 30, 2023 22:15
@Veetaha
Copy link
Contributor

Veetaha commented Oct 1, 2023

I think we may just merge this as is, and implement the auto-tagging workflow separately. It's better to have something than nothing, right?

@xFrednet
Copy link
Member Author

xFrednet commented Oct 1, 2023

You're right, I have to learn to get a better balance of what to merge or what to perfect first :)

@xFrednet xFrednet marked this pull request as ready for review October 1, 2023 13:37
@xFrednet xFrednet added this pull request to the merge queue Oct 1, 2023
Merged via the queue into rust-marker:master with commit f64849c Oct 1, 2023
15 of 16 checks passed
@xFrednet xFrednet deleted the 120-semver-checks-to-ignore branch October 1, 2023 13:43
@xFrednet xFrednet mentioned this pull request Oct 1, 2023
@xFrednet
Copy link
Member Author

xFrednet commented Oct 1, 2023

I accidentally committed the breaking change as well 🤦

github-merge-queue bot pushed a commit that referenced this pull request Oct 1, 2023
API: Undo accidental API break from #262
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-infra Area: Infrastructure and CI magic :sparkles: C-enhancement Category: New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Test for API breaking changes in CI
2 participants