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

RUM-7285 Add api-surface step to Lint stage #2112

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

mariedm
Copy link
Member

@mariedm mariedm commented Nov 15, 2024

What and why?

To ensure public API changes are properly updated, I previously added a reminder in our GitHub PR template checklist to run make api-surface. However, this has proven insufficient 🙃 To address this, I am adding an automated step to the CI Lint phase to enforce this check.

How?

  • Add CI Validation:
    • A step is added to the Lint phase that runs make api-surface.
    • The generated API surface files are written to temporary files (api-surface-swift-generated and api-surface-objc-generated).
    • These temporary files are compared with the committed reference files (api-surface-swift and api-surface-objc).
  • CI Behavior:
    • If differences are detected, the CI step exits with an error, prompting contributors to run make api-surface locally and commit the updated reference files.
  • Updated Reference Files:
    • The reference files are updated as needed to reflect recent changes to the public API.

Review checklist

  • Feature or bugfix MUST have appropriate tests (unit, integration)
  • Make sure each commit and the PR mention the Issue number or JIRA reference
  • Add CHANGELOG entry for user facing changes
  • Add Objective-C interface for public APIs (see our guidelines [internal]) and run make api-surface)

@mariedm mariedm force-pushed the rum-7285-add-api-surface-step-to-ci branch 6 times, most recently from 510cd2c to 7626f46 Compare November 15, 2024 16:12
@datadog-datadog-prod-us1
Copy link

datadog-datadog-prod-us1 bot commented Nov 15, 2024

Datadog Report

Branch report: rum-7285-add-api-surface-step-to-ci
Commit report: 4aa62a9
Test service: dd-sdk-ios

✅ 0 Failed, 3570 Passed, 0 Skipped, 2m 19.07s Total Time
🔻 Test Sessions change in coverage: 4 decreased, 3 increased, 7 no change

🔻 Code Coverage Decreases vs Default Branch (4)

  • test DatadogTraceTests iOS 54.11% (-0.11%) - Details
  • test DatadogInternalTests iOS 80.32% (-0.08%) - Details
  • test DatadogInternalTests tvOS 80.41% (-0.02%) - Details
  • test DatadogCrashReportingTests iOS 26.63% (-0.02%) - Details

@mariedm mariedm marked this pull request as ready for review November 15, 2024 16:38
@mariedm mariedm requested review from a team as code owners November 15, 2024 16:38
ncreated
ncreated previously approved these changes Nov 15, 2024
Copy link
Member

@ncreated ncreated left a comment

Choose a reason for hiding this comment

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

This is great 🤩! I left two feedbacks on conventions, but well done overall 💪

.gitlab-ci.yml Outdated
Comment on lines 95 to 104
- if ! diff api-surface-swift api-surface-swift-generated; then
echo "❌ Swift API surface mismatch";
echo "👉 Run \`make api-surface\` locally to update \`api-surface-swift\` and commit the changes.";
exit 1;
fi
- if ! diff api-surface-objc api-surface-objc-generated; then
echo "❌ Objective-C API surface mismatch";
echo "👉 Run \`make api-surface\` locally to update \`api-surface-objc\` and commit the changes.";
exit 1;
fi
Copy link
Member

Choose a reason for hiding this comment

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

suggestion/ Could we move these checks to separate script in tools/ directory? The convention we started for .gitlab-ci.yml is to avoid bare scripts in yml as they are very inconvenient to reproduce in local shell.

Ideally, we could get inspired by make rum-models-verfy:

  • make api-surface - to generate API surface files; ran in local
  • make api-surface-verify - to verify API surface; ran on CI

Makefile Outdated
SWIFT_OUTPUT_PATH := api-surface-swift-generated
OBJC_OUTPUT_PATH := api-surface-objc-generated
endif

# Generate api-surface files for Datadog and DatadogObjc.
api-surface:
@echo "Generating api-surface-swift"
Copy link
Member

Choose a reason for hiding this comment

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

suggestion/ Let's follow the convention in of printing command's title before it is ran. This brings a lot of clarity to CI logs:

	@$(ECHO_TITLE) "make api-surface"

Also, let's fix the indentation for this command. It uses the old one, all new commands (after migration to GitLab) are indented with less whitespaces. See these examples.

@mariedm mariedm force-pushed the rum-7285-add-api-surface-step-to-ci branch from 7626f46 to 4aa62a9 Compare December 5, 2024 13:10
@mariedm
Copy link
Member Author

mariedm commented Dec 5, 2024

Update

  • Addressed comments:
    • Removed inline scripts from .gitlab-ci.yml and moved logic to tools/
    • Followed command title printing style
    • Corrected Makefile indentation
  • Split Commands:
    • Generate to create API surface files and Verify to compare with reference files
    • Added new tests for the new Verify command
  • Fixes:
    • Adjusted lint rule in SessionReplayConfiguration to fix api-surface file

Copy link
Member

@ncreated ncreated left a comment

Choose a reason for hiding this comment

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

Well done 🏅💪!

I did notice however, that integrating api-surface has increased the lint job duration from 30 seconds to around 3 minutes. This is a significant change, so before merging, it might be worth discussing with the team:

  • How do we feel about this increased duration?
  • How might this impact development or the feedback loop?
  • Are there any optimization opportunities?
  • When should we consider optimizing?

// Given
let command = try SPMLibrarySurfaceCommand.parse([
let temporaryFile = "/tmp/api-surface-test-output"
Copy link
Member

Choose a reason for hiding this comment

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

suggestion/ Using a dynamically created temp directory could bring some benefits:

  • Avoid conflicts between test runs and ensure isolation.
  • Automatically clean up after tests to prevent leftover files from affecting others.
  • More robust (in other environments) than using hardcoded paths.

Example:

let tempDirectory = FileManager.default.temporaryDirectory.appendingPathComponent("com.datadoghq.api-surface-" + UUID().uuidString)
try FileManager.default.createDirectory(at: tempDirectory, withIntermediateDirectories: true, attributes: nil)
        
let temporaryFile = tempDirectory.appendingPathComponent("api-surface-test-output").path

Copy link
Contributor

@simaoseica-dd simaoseica-dd left a comment

Choose a reason for hiding this comment

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

🏅
This will be very helpful

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants