Skip to content

Conversation

@rayangler
Copy link
Contributor

Proposed changes

Jira ticket: DOP-5448

The main goal of this PR is to follow Bump.sh's recommendation for a GH action that deploys changes to an OpenAPI spec to Bump, to be uploaded to the DOP team's Bump account.

Checklist

  • I have signed the MongoDB CLA
  • I have added tests that prove my fix is effective or that my feature works

Changes to Spectral

  • I have read the README file for Spectral Updates

Further comments

Some implementation details to note:

  • Each spec is separated into its own document on Bump under the same hub.
  • I've tested this out on a fork, in case you're curious about uploads.
  • I have a scoped Bump API token that must be added as a secret to allow the GH action to work properly. I can reach out on Slack about getting this added!
  • For Atlas Admin API v2, we're trying to follow the current setup where each of its resource versions are separate versions (Bump calls these branches). This makes the assumption that the latest resource version will always be at the end of the versions.json array. Right now, the generateSpecMapping script is mostly for the Atlas Admin API, but hopefully the array/script can be extended to handle any future OpenAPI specs that may be added to this repo.

@rayangler rayangler requested a review from a team as a code owner March 12, 2025 18:58
@rayangler rayangler requested a review from caesarbell March 12, 2025 21:32
file: ${{matrix.spec-mapping.file}}
branch: ${{matrix.spec-mapping.branch}}

api-preview:
Copy link
Collaborator

Choose a reason for hiding this comment

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

what is the experience to access the preview spec on bump once the job is completed? I am wondering if we should add a step here to add a comment to the PR with the link to the spec

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right now, each matrix job will result in a separate preview link in the GH action logs (example). Would you like me to file a separate ticket to investigate the best way to comment on the PR (probably without spamming a comment for each one) or is this sufficient for now?

Copy link
Member

Choose a reason for hiding this comment

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

Right now, each matrix job will result in a separate preview link in the GH action logs

SGTM. Feel free to introduce it in separate PR and spec out how to get access to preview urls.

const __dirname = path.dirname(__filename);

// Add new specs to be deployed to Bump here
const SPEC_MAPPING = [
Copy link
Member

@wtrocki wtrocki Mar 13, 2025

Choose a reason for hiding this comment

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

Can we document how this array will grow over time?
I'm trying to establish how many matrix jobs this PR will render after we merge and how this will grow over time. Short explanation would do the job

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I updated the comment to be more explicit, but let me know if you need that written out elsewhere or if you need a better explanation!

Right now, it'll create a separate job for each major spec version of the Atlas Admin API, and for each resource version. Docs currently supports 1-2 more additional public OpenAPI specs, which means we may add them to this repo, leading to more jobs, but I wasn't sure if this repo is intended for all OpenAPI specs, or if the preference is to only have this repo be for Atlas Admin API exclusively.

If the number of jobs becomes a concern, what we could potentially do is explore creating a custom action that can accept the entire array as a single input and bulk deploy/preview everything instead of relying on Bump's action that only accepts 1 at a time.

Copy link
Member

@wtrocki wtrocki Mar 17, 2025

Choose a reason for hiding this comment

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

SGTM. It is not about how many jobs but how many minutes are used.
I see that in current scenario this new job will use less than 10 minutes of run time monthly which seems fine.

Copy link
Member

@wtrocki wtrocki left a comment

Choose a reason for hiding this comment

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

LGTM for approach.
Let's remove the ability to trigger this action for now before we merge PR.
Alternatively please comment out part that depends on the secret.

Copy link
Collaborator

@caesarbell caesarbell left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Collaborator

@andreaangiolillo andreaangiolillo left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks for all the changes

},
];

function handleAdminAPIv2() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: can we please have unit tests?

Copy link
Collaborator

Choose a reason for hiding this comment

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

(ok to add in a follow-up PR)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay, I can file a follow-up DOP ticket. Is there an ideal location within the repo to add this test? I didn't see a test directory for existing action scripts, but maybe I missed it 😅

Copy link
Collaborator

Choose a reason for hiding this comment

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

good point! I am not sure, in our case, we have scripts but they call some of the tools we built under the tools folder, which is where we have the most logic, if you think you'll build more on top of this script you can look into https://github.com/mongodb/openapi/tree/main/tools/spectral/ipa and create a tool folder for docs and have tests there, otherwise we can look into GH best practices on how to add coverage for the scripts!

const versions = JSON.parse(fs.readFileSync(filePath, 'utf8'));

if (!versions || !Array.isArray(versions)) {
return;
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: add logs for troubleshooting in the future, if file changes and we fail to parse

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good call. Added

const openapiFilename = `openapi-${version}.json`;
const openapiFilePath = path.join(path.dirname(filePath), openapiFilename);

if (!fs.existsSync(openapiFilePath)) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: add logs if we find a version but not a file

@rayangler rayangler merged commit e2f1076 into main Mar 19, 2025
4 checks passed
@rayangler rayangler deleted the DOP-5448-bump branch March 19, 2025 14:54
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.

5 participants