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

Add "observable deploy" command. #187

Merged
merged 24 commits into from
Nov 29, 2023
Merged

Add "observable deploy" command. #187

merged 24 commits into from
Nov 29, 2023

Conversation

mcglincy
Copy link
Contributor

@mcglincy mcglincy commented Nov 16, 2023

Description

Add a new "yarn deploy" command that talks to our new API endpoints.

Resolves https://github.com/observablehq/observablehq/issues/15128 and https://github.com/observablehq/observablehq/issues/15134

Internal workflow:

  • Requires api key to be found in .observablehq dot-file.
  • Creates a project if one doesn't exist. The user will be prompted for a slug and their choice of workspace (if they have more than one workspace). The new project id is then stashed in a .project file.
  • Creates a new deploy.
  • Recurses the ./dist directory, uploading each file within it.
  • Marks the deploy as "uploaded".

Review notes

To test locally, you'll need the feature flag enabled in your local db:

INSERT INTO user_features (feature, canary) VALUES ('cli_project', true);

Then you can login from the CLI:
NODE_TLS_REJECT_UNAUTHORIZED=0 OBSERVABLEHQ_HOST=https://observable.test:5000/ yarn tsx bin/observable.ts login

And then do a deploy from the CLI:
NODE_TLS_REJECT_UNAUTHORIZED=0 OBSERVABLEHQ_HOST=https://observable.test:5000/ yarn deploy

Tests

Adds to ObservableApiMock introduced in #39.

Risk

Low.

bin/observable.ts Outdated Show resolved Hide resolved
src/deploy.ts Outdated Show resolved Hide resolved
src/deploy.ts Outdated Show resolved Hide resolved
src/toolConfig.ts Outdated Show resolved Hide resolved
@mcglincy mcglincy changed the title Add deploy command. Add "observable deploy" command. Nov 17, 2023
src/apiClient.ts Outdated Show resolved Hide resolved
src/apiClient.ts Outdated Show resolved Hide resolved
@mcglincy
Copy link
Contributor Author

Now that Michael's auth PR is merged and we've chosen our testing strategy (undici mocking), I'll get this PR properly integrated with his code and ready for non-draft review.

@mcglincy mcglincy force-pushed the mcglincy/observable-deploy branch from 92bee89 to f656fd7 Compare November 21, 2023 21:12
@mcglincy mcglincy marked this pull request as ready for review November 21, 2023 21:14
@mcglincy mcglincy requested review from mythmon, Fil and cinxmo November 21, 2023 21:23
@mcglincy
Copy link
Contributor Author

PR updated and now ready for actual review. Thanks all!

src/deploy.ts Outdated Show resolved Hide resolved
src/auth.ts Show resolved Hide resolved
src/auth.ts Outdated Show resolved Hide resolved
src/deploy.ts Outdated Show resolved Hide resolved
src/deploy.ts Show resolved Hide resolved
src/deploy.ts Outdated Show resolved Hide resolved
src/deploy.ts Outdated Show resolved Hide resolved
src/deploy.ts Outdated Show resolved Hide resolved
src/deploy.ts Outdated Show resolved Hide resolved
src/deploy.ts Outdated Show resolved Hide resolved
src/deploy.ts Outdated Show resolved Hide resolved
src/toolConfig.ts Outdated Show resolved Hide resolved
test/deploy-test.ts Outdated Show resolved Hide resolved
test/deploy-test.ts Show resolved Hide resolved
test/mocks/observableApi.ts Outdated Show resolved Hide resolved
test/mocks/observableApi.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@cinxmo cinxmo left a comment

Choose a reason for hiding this comment

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

some concerns around error handling - will review the test cases later! (I also needed the OBSERVABLEHQ_API_HOST env var for testing locally 😆)

src/observableApiClient.ts Outdated Show resolved Hide resolved
src/toolConfig.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@cinxmo cinxmo left a comment

Choose a reason for hiding this comment

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

some minor suggestions but it worked well from testing locally! will approve after the small changes and increasing test coverage

@mythmon mythmon mentioned this pull request Nov 28, 2023
@mcglincy mcglincy requested a review from cinxmo November 28, 2023 16:37
src/auth.ts Outdated Show resolved Hide resolved
@mcglincy mcglincy merged commit 8cb5afb into main Nov 29, 2023
1 check passed
@mcglincy mcglincy deleted the mcglincy/observable-deploy branch November 29, 2023 02:31

// Mark the deploy as uploaded.
await apiClient.postDeployUploaded(deployId);
logger.log(`Deployed project now visible at ${getObservableUiHost()}/p/${projectId}`);
Copy link
Member

Choose a reason for hiding this comment

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

Is the projectId the hexadecimal identifier? We should try to never show that to the user, especially for the URL that they are likely to copy-paste and share.

We might also have the API return the URL for the project, so that we can change the logic more easily on the API side without needing clients to update.

Copy link
Contributor Author

@mcglincy mcglincy Nov 29, 2023

Choose a reason for hiding this comment

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

@mythmon also raised the possibility of replacing projectId in any visible URLs with workspace + slug.

We're about to hammer out the PR for project serving on the server side, so can finalize the visible URL format there, and then fix the CLI deploy messaging accordingly. #270 on me for that.

headers: [...this._apiHeaders, ["Content-Type", "application/json"]],
body: JSON.stringify({})
});
if (response.status !== 200) {
Copy link
Member

@mbostock mbostock Nov 29, 2023

Choose a reason for hiding this comment

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

Use response.ok here? (And below.)


interface Config {
const observableConfigName = ".observablehq";
interface ObservableConfig {
Copy link
Member

Choose a reason for hiding this comment

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

“ObservableConfig” sounds a little ambiguous. Should we call this “UserConfig” (since it typically lives in the user’s home directory)?

Copy link
Member

@mbostock mbostock left a comment

Choose a reason for hiding this comment

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

Nice job with the tests! 👏

@mcglincy
Copy link
Contributor Author

Will address comments in a followup PR. Thanks!

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