Skip to content

Commit

Permalink
Add: sdk danger check (#10010)
Browse files Browse the repository at this point in the history
  • Loading branch information
Fraggle authored Jan 16, 2025
1 parent 46b0ccc commit 33339f9
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
16 changes: 14 additions & 2 deletions .github/workflows/run-dangerjs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,24 @@ jobs:
echo "Checking for changed files..."
CHANGED_FILES=$(git diff --name-only origin/main ${{ github.sha }} -- 'front/lib/models/' 'front/lib/resources/storage/models/' 'connectors/src/lib/models/' 'connectors/src/resources/storage/models/' 'front/pages/api/v1/')
# Define monitored paths
MONITORED_PATHS=(
'front/lib/models/'
'front/lib/resources/storage/models/'
'connectors/src/lib/models/'
'connectors/src/resources/storage/models/'
'front/pages/api/v1/'
'sdks/js/'
)
PATHS_STRING="${MONITORED_PATHS[*]}"
CHANGED_FILES=$(git diff --name-only origin/main ${{ github.sha }} -- ${MONITORED_PATHS[@]})
if [ -n "$CHANGED_FILES" ]; then
echo "Changed files found:"
echo "$CHANGED_FILES"
echo "run_danger=true" >> $GITHUB_OUTPUT
echo "::warning ::Files in 'front/lib/models/', 'connectors/src/lib/models/', or 'front/pages/api/v1/' have been modified."
echo "::warning ::Files in ${PATHS_STRING} have been modified."
else
echo "No changed files found."
echo "run_danger=false" >> $GITHUB_OUTPUT
Expand Down
25 changes: 25 additions & 0 deletions front/dangerfile.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { danger, fail, warn } from "danger";

const sdkAckLabel = "sdk-ack";
const migrationAckLabel = "migration-ack";
const documentationAckLabel = "documentation-ack";
const auth0UpdateLabelAck = "auth0-update-ack";
Expand Down Expand Up @@ -35,6 +36,22 @@ function checkMigrationLabel() {
}
}

function failSDKAck() {
fail(
"Files in `**/sdks/js/` have been modified. " +
`Changing the types defined in the SDK could break existing client.\n` +
`Additions (new types, new values) are generally fine but **removals are NOT OK** : it would break the contract of the Public API.\n` +
`Please add the \`${sdkAckLabel}\` label to acknowledge ` +
`that your are not breaking the existing Public API contract.`
);
}

function checkSDKLabel() {
if (!hasLabel(sdkAckLabel)) {
failSDKAck();
}
}

function checkDeployPlanSection() {
const PRDescription = danger.github.pr.body;

Expand Down Expand Up @@ -128,6 +145,14 @@ function checkModifiedFiles() {
if (modifiedAuth0Files.length > 0) {
checkAuth0UpdateLabel();
}

const modifiedSdksFiles = danger.git.modified_files.filter((path) => {
return path.startsWith("sdks/js/");
});

if (modifiedSdksFiles.length > 0) {
checkSDKLabel();
}
}

checkModifiedFiles();

0 comments on commit 33339f9

Please sign in to comment.