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

Improve handling of bad versions during ext:install #5305

Merged
merged 5 commits into from Dec 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -6,3 +6,4 @@
- Support the x-goog-api-key header in auth emulator. (#5249)
- Fix bug in deploying web frameworks when a predeploy hook was configured in firebase.json (#5199)
- Fix bug where function deployments using --only filter sometimes failed deployments. (#5280)
- Fix bug where `ext:install` would sometimes fail if no version was specified. (#5305)
1 change: 1 addition & 0 deletions src/deploy/extensions/planner.ts
Expand Up @@ -215,6 +215,7 @@ export async function resolveVersion(ref: refs.Ref): Promise<string> {
}
if (!ref.version || ref.version === "latest") {
return versions
.filter((ev) => ev.spec.version !== undefined)
.map((ev) => ev.spec.version)
.sort(semver.compare)
.pop()!;
Expand Down
16 changes: 10 additions & 6 deletions src/extensions/extensionsHelper.ts
Expand Up @@ -833,14 +833,18 @@ export async function diagnoseAndFixProject(options: any): Promise<void> {
* 1. Infer firebase publisher if not provided
* 2. Infer "latest" as the version if not provided
*/
export async function canonicalizeRefInput(extensionName: string): Promise<string> {
// Infer firebase if publisher ID not provided.
if (extensionName.split("/").length < 2) {
const [extensionID, version] = extensionName.split("@");
extensionName = `firebase/${extensionID}@${version || "latest"}`;
export async function canonicalizeRefInput(refInput: string): Promise<string> {
let inferredRef = refInput;
// Infer 'firebase' if publisher ID not provided.
if (refInput.split("/").length < 2) {
inferredRef = `firebase/${inferredRef}`;
}
// Infer 'latest' if no version provided.
if (refInput.split("@").length < 2) {
inferredRef = `${inferredRef}@latest`;
}
// Get the correct version for a given extension reference from the Registry API.
const ref = refs.parse(extensionName);
const ref = refs.parse(inferredRef);
ref.version = await resolveVersion(ref);
return refs.toExtensionVersionRef(ref);
}
17 changes: 8 additions & 9 deletions src/test/deploy/extensions/planner.spec.ts
Expand Up @@ -3,9 +3,9 @@ import * as sinon from "sinon";

import * as planner from "../../../deploy/extensions/planner";
import * as extensionsApi from "../../../extensions/extensionsApi";
import { ExtensionInstance, ExtensionVersion } from "../../../extensions/types";
import { ExtensionInstance } from "../../../extensions/types";

function extensionVersion(version: string): ExtensionVersion {
function extensionVersion(version?: string): any {
return {
name: `publishers/test/extensions/test/versions/${version}`,
ref: `test/test@${version}`,
Expand All @@ -26,13 +26,12 @@ describe("Extensions Deployment Planner", () => {
let listExtensionVersionsStub: sinon.SinonStub;

before(() => {
listExtensionVersionsStub = sinon
.stub(extensionsApi, "listExtensionVersions")
.resolves([
extensionVersion("0.1.0"),
extensionVersion("0.1.1"),
extensionVersion("0.2.0"),
]);
listExtensionVersionsStub = sinon.stub(extensionsApi, "listExtensionVersions").resolves([
extensionVersion("0.1.0"),
extensionVersion("0.1.1"),
extensionVersion("0.2.0"),
extensionVersion(), // Explicitly test that this doesn't break on bad data
Copy link
Contributor

Choose a reason for hiding this comment

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

👍 👍

]);
});

after(() => {
Expand Down