-
Notifications
You must be signed in to change notification settings - Fork 11
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: add validity check to Electron Archaeologist runs #42
Open
alicelovescake
wants to merge
6
commits into
electron:main
Choose a base branch
from
alicelovescake:alice-add-valid-check
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+2,244
−13
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
a6e9631
feat: update validity check based on labels
alicelovescake 9aa8a20
feat: add test packages
alicelovescake c76a29a
feat: add test config
alicelovescake ab78aa9
test: add test for getCheckStatusItems
alicelovescake 3dfe6df
chore: add test github workflow
alicelovescake 8caf915
chore: update job name
alicelovescake 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,27 @@ | ||
name: Test | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
branches: | ||
- main | ||
|
||
permissions: | ||
contents: read | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 | ||
- name: Setup Node.js | ||
uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 | ||
with: | ||
node-version: lts/-1 | ||
- name: Install | ||
run: yarn install | ||
- name: Test | ||
run: yarn test | ||
|
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,20 @@ | ||
process.env.SPEC_RUNNING = '1'; | ||
|
||
module.exports = { | ||
roots: [ | ||
'<rootDir>/spec' | ||
], | ||
transform: { | ||
'^.+\\.tsx?$': 'ts-jest' | ||
}, | ||
clearMocks: true, | ||
testRegex: '(/spec/.*|(\\.|/)(test|spec))\\.tsx?$', | ||
moduleFileExtensions: [ | ||
'ts', | ||
'tsx', | ||
'js', | ||
'jsx', | ||
'json', | ||
'node' | ||
], | ||
} |
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
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,39 @@ | ||
{ | ||
"name": "pull_request", | ||
"payload": { | ||
"action": "opened", | ||
"number": 7, | ||
"pull_request": { | ||
"url": "my_cool_url", | ||
"title": "CHANGE README", | ||
"merged": true, | ||
"user": { | ||
"login": "codebytere" | ||
}, | ||
"body": "New cool stuff \nNotes: new cool stuff added", | ||
"labels": [], | ||
"head": { | ||
"sha": "ABC" | ||
}, | ||
"base": { | ||
"ref": "main", | ||
"repo": { | ||
"default_branch": "main" | ||
} | ||
} | ||
}, | ||
"label": { | ||
"name": "todo", | ||
"color": "8cb728" | ||
}, | ||
"repository": { | ||
"name": "probot-test", | ||
"owner": { | ||
"login": "codebytere" | ||
} | ||
}, | ||
"installation": { | ||
"id": 103619 | ||
} | ||
} | ||
} |
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,57 @@ | ||
import { SEMVER_LABELS } from '../src/constants'; | ||
import {getCheckStatusItems, checkStatuses} from '../src/utils/check-utils' | ||
const PROpenedEvent = require('./fixtures/pull_request.opened.json'); | ||
|
||
const semverNoneLabel = { | ||
name: SEMVER_LABELS.NONE, | ||
color: '000' | ||
}; | ||
const semverMinorLabel = { | ||
name: SEMVER_LABELS.MINOR, | ||
color: '000' | ||
}; | ||
const semverMajorLabel = { | ||
name: SEMVER_LABELS.MAJOR, | ||
color: '000' | ||
}; | ||
|
||
describe('utils', () => { | ||
describe('getCheckStatusItems()', () => { | ||
|
||
const context = { | ||
octokit: {}, | ||
repo: jest.fn(), | ||
...PROpenedEvent, | ||
}; | ||
|
||
it('should return the valid changes status when changes are detected with a semver/minor label', () => { | ||
context.payload.pull_request.labels = [semverMinorLabel] | ||
const result = getCheckStatusItems({context, hasChanges: true}); | ||
expect(result).toEqual(checkStatuses.validChanges); | ||
}); | ||
|
||
it('should return the invalid changes status when changes are detected with a semver/none label', () => { | ||
context.payload.pull_request.labels = [semverNoneLabel] | ||
const result = getCheckStatusItems({context, hasChanges: true}); | ||
expect(result).toEqual(checkStatuses.invalidChanges); | ||
}); | ||
|
||
it('should return the invalid changes status when changes are detected with no semver labels', () => { | ||
context.payload.pull_request.labels = [] | ||
const result = getCheckStatusItems({context, hasChanges: true}); | ||
expect(result).toEqual(checkStatuses.invalidChanges); | ||
}); | ||
|
||
it('should return the valid status when no changes are detected with a semver/none label', () => { | ||
context.payload.pull_request.labels = [semverNoneLabel] | ||
const result = getCheckStatusItems({context, hasChanges: false}); | ||
expect(result).toEqual(checkStatuses.validNoChanges); | ||
}); | ||
|
||
it('should return the invalid status when no changes are detected with a semver/major label', () => { | ||
context.payload.pull_request.labels = [semverMajorLabel] | ||
const result = getCheckStatusItems({context, hasChanges: false}); | ||
expect(result).toEqual(checkStatuses.invalidNoChanges); | ||
}); | ||
}) | ||
}) |
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,8 @@ | ||
export const SEMVER_PREFIX = 'semver/'; | ||
|
||
export const SEMVER_LABELS = { | ||
NONE: 'semver/none', | ||
PATCH: 'semver/patch', | ||
MINOR: 'semver/minor', | ||
MAJOR: 'semver/major', | ||
}; |
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
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
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,62 @@ | ||
import { SEMVER_LABELS } from '../constants'; | ||
import { CheckRunStatus, CheckStatus, PRContext } from '../types'; | ||
import { getSemverLabel } from './label-utils'; | ||
|
||
// Define the possible check statuses | ||
export const checkStatuses = { | ||
validNoChanges: { | ||
conclusion: CheckRunStatus.SUCCESS, | ||
title: 'No Changes', | ||
summary: "We couldn't see any changes in the `electron.d.ts` artifact", | ||
}, | ||
invalidNoChanges: { | ||
conclusion: CheckRunStatus.FAILURE, | ||
title: 'Label Mismatch with No Changes', | ||
summary: "No changes detected despite the presence of 'semver/minor' or 'semver/major' labels.", | ||
}, | ||
validChanges: { | ||
conclusion: CheckRunStatus.NEUTRAL, | ||
title: 'Changes Detected', | ||
summary: '', | ||
}, | ||
invalidChanges: { | ||
conclusion: CheckRunStatus.FAILURE, | ||
title: 'Label Mismatch with Changes Detected', | ||
summary: "Changes detected despite the presence of 'semver/none' label. ", | ||
Comment on lines
+23
to
+25
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There needs to be a way of overriding this |
||
}, | ||
}; | ||
|
||
// Helper function to check if a semver label is valid for if `electron.d.ts` changes detected | ||
function isSemverLabelValidForChanges(semverLabel: string | undefined) { | ||
if (!semverLabel) { | ||
return false; | ||
} | ||
|
||
return new Set([SEMVER_LABELS.PATCH, SEMVER_LABELS.MINOR, SEMVER_LABELS.MAJOR]).has(semverLabel); | ||
} | ||
|
||
function isSemverLabelValidForNoChanges(semverLabel: string | undefined) { | ||
return !semverLabel || semverLabel === SEMVER_LABELS.NONE; | ||
} | ||
|
||
// Function to get the appropriate check status | ||
export function getCheckStatusItems({ | ||
context, | ||
hasChanges, | ||
}: { | ||
context: PRContext; | ||
hasChanges: boolean; | ||
}) { | ||
const semverLabel = getSemverLabel(context.payload.pull_request); | ||
|
||
if (hasChanges) { | ||
// If changes are detected | ||
return isSemverLabelValidForChanges(semverLabel?.name) | ||
? checkStatuses.validChanges | ||
: checkStatuses.invalidChanges; | ||
} | ||
// If no changes are detected | ||
return isSemverLabelValidForNoChanges(semverLabel?.name) | ||
? checkStatuses.validNoChanges | ||
: checkStatuses.invalidNoChanges; | ||
} |
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,6 @@ | ||
import { SEMVER_PREFIX } from '../constants'; | ||
import { PR } from '../types'; | ||
|
||
export const getSemverLabel = (pr: Pick<PR, 'labels'>) => { | ||
return pr.labels.find((l: any) => l.name.startsWith(SEMVER_PREFIX)); | ||
}; |
Oops, something went wrong.
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.
There needs to be a way of overriding this, something like like our
fast-track
orskip-backport-check
labels to bypass trop / cation checks.This isn't 100% provably correct, for instance:
semver/major
change with 0 API surface changing, for instance enabling a feature by default (Cooke Encryption comes to mind as a semver/major with 0 API)semver/none
change that modifies the API surface. For instance docs fixes commonly "modify" theelectron.d.ts
file but don't actually change the API surface. So unless this check gets smarter around diffing actual API surface rather than just theelectron.d.ts
file we need a way to say "in this case we're all good"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.
Thanks for pointing out the edge cases that I haven't considered!
I can add a new label that's
skip-type-diff-check
but do you think it adds unnecessary complexity to the process? After all, the primary purpose of these checks is to provide informational cues to users.What if for expected
valid
changes, we set the status toCheckRunStatus.SUCCESS
and for suspectedinvalid
changes, we set the status toCheckRunStatus.NEUTRAL
with a summary that gives a warning that unexpected changes exist but feel free to skip if it's intentional.This way, it serves the purpose of providing information without adding process overhead. If we feel like the override tag is better, happy to add it!!