[go: nahoru, domu]

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

Return version in hosting:channel:deploy #3157

Merged
merged 14 commits into from
May 19, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Return version in hosting:channel:deploy
  • Loading branch information
slam committed Feb 22, 2021
commit b2ef2fccb3c0042cd486505753ae341126c77511
30 changes: 26 additions & 4 deletions src/commands/hosting-channel-deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,18 @@ interface ChannelInfo {
target: string | null;
site: string;
url: string;
version: string;
expireTime: string;
}

interface DeployResult {
hosting: {
[site: string]: {
[key: string]: string;
};
Copy link
Contributor

Choose a reason for hiding this comment

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

Might the value of this map be the Release interface in hosting/api.ts? (I don't know off hand, but it would make for stronger typing)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a great idea. It would require a bit more code changes to capture the payload returned by the hosting release api, but it makes more sense to me. Let me give it a try.

};
}

export default new Command("hosting:channel:deploy [channelId]")
.description("deploy to a specific Firebase Hosting channel")
.option(
Expand Down Expand Up @@ -91,7 +100,13 @@ export default new Command("hosting:channel:deploy [channelId]")

const sites: ChannelInfo[] = normalizedHostingConfigs(options, {
resolveTargets: true,
}).map((cfg) => ({ site: cfg.site, target: cfg.target, url: "", expireTime: "" }));
}).map((cfg) => ({
site: cfg.site,
target: cfg.target,
url: "",
version: "",
expireTime: "",
}));

await Promise.all(
sites.map(async (siteInfo) => {
Expand Down Expand Up @@ -127,20 +142,27 @@ export default new Command("hosting:channel:deploy [channelId]")
})
);

await deploy(["hosting"], options, { hostingChannel: channelId });
const results = (await deploy(["hosting"], options, {
hostingChannel: channelId,
})) as DeployResult;
Copy link
Contributor

Choose a reason for hiding this comment

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

My TS-brain is rusty: could this be const results: DeployResult = await deploy() rather than using as?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The method deploy() returns any since it is implemented in js. Without the as cast, eslint issues this warning: Unsafe assignment of an any value..

I'm fine with either construct. Please advise.


logger.info();
await syncAuthState(projectId, sites);
const deploys: { [key: string]: ChannelInfo } = {};
const siteDetails = results.hosting;
sites.forEach((d) => {
deploys[d.target || d.site] = d;
const siteKey = d.target || d.site;
if (siteDetails && siteKey in siteDetails) {
d.version = siteDetails[siteKey]["version"];
}
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the case where siteDetails is not defined?

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 point. Removed.

deploys[siteKey] = d;
let expires = "";
if (d.expireTime) {
expires = `[expires ${bold(datetimeString(new Date(d.expireTime)))}]`;
}
logLabeledSuccess(
LOG_TAG,
`Channel URL (${bold(d.site || d.target)}): ${d.url} ${expires}`
`Channel URL (${bold(siteKey)}): ${d.url} ${expires} ${d.version}`
);
});
return deploys;
Expand Down
8 changes: 6 additions & 2 deletions src/deploy/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,12 @@ var deploy = function (targetNames, options, customContext = {}) {
_.each(context.hosting.deploys, function (deploy) {
logger.info(clc.bold("Hosting URL:"), utils.addSubdomain(api.hostingOrigin, deploy.site));
});
const versionNames = context.hosting.deploys.map((deploy) => deploy.version);
return { hosting: versionNames.length === 1 ? versionNames[0] : versionNames };
var siteDetails = {};
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
var siteDetails = {};
const siteDetails = {};

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 had const initially, but then noticed that this js file is using var everywhere else. I'd like to leave it as var if it is okay with you.

context.hosting.deploys.forEach((deploy) => {
var version = deploy.version.replace(`sites/${deploy.site}/versions/`, "");
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not actually sure we want to truncate the full name to just the version ID. If we wanted to only display that later, we can manipulate the name at that location.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's a good point. Will move that logic into host-channel-deploy.ts.

siteDetails[deploy.site] = { version };
});
return { hosting: siteDetails };
Copy link
Contributor

Choose a reason for hiding this comment

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

This change may also have an effect on the output of deploy --json. Could you check the before/after of the behavior there?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It looks compatible. The only new field is version.

Before:

{
  "status": "success",
  "result": {
    "<site>": {
      "site": "<site>",
      "url": "https://<site>--slam-test-6161efgc.web.app",
      "expireTime": "2021-03-02T19:40:07.615661137Z"
    }
  }
}

After:

{
  "status": "success",
  "result": {
    "<site>": {
      "site": "<site>",
      "url": "https://<site>--slam-test-6161efgc.web.app",
      "version": "09ef5462c91e2bba",
      "expireTime": "2021-03-02T19:39:05.793378023Z"
    }
  }
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This makes sense to me because before this PR the return value of deploy() was not used anywhere:

https://github.com/firebase/firebase-tools/pull/3157/files#diff-90fa65dc2e075506e4e87cc1c6bee0c8a1e769440908e956179ad0fa4a79d999L130

}
});
};
Expand Down