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 7 commits
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
34 changes: 30 additions & 4 deletions src/commands/hosting-channel-deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
addAuthDomains,
cleanAuthState,
normalizeName,
Release,
} from "../hosting/api";
import { normalizedHostingConfigs } from "../hosting/normalizedHostingConfigs";
import { requirePermissions } from "../requirePermissions";
Expand All @@ -28,9 +29,18 @@ interface ChannelInfo {
target: string | null;
site: string;
url: string;
version: string;
expireTime: string;
}

interface DeployResult {
hosting: {
[site: string]: {
release: Release;
};
};
}

export default new Command("hosting:channel:deploy [channelId]")
.description("deploy to a specific Firebase Hosting channel")
.option(
Expand Down Expand Up @@ -91,7 +101,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 @@ -126,20 +142,30 @@ 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 } = {};
sites.forEach((d) => {
deploys[d.target || d.site] = d;
const siteKey = d.target || d.site;
deploys[siteKey] = d;
let expires = "";
if (d.expireTime) {
expires = `[expires ${bold(datetimeString(new Date(d.expireTime)))}]`;
}
const siteResult = results.hosting[siteKey];
let version = "";
if (siteResult) {
const versionName: string = siteResult.release.version.name;
d.version = versionName.replace(`sites/${d.site}/versions/`, "");
version = `[version ${bold(d.version)}]`;
}
logLabeledSuccess(
LOG_TAG,
`Channel URL (${bold(d.site || d.target)}): ${d.url} ${expires}`
`Channel URL (${bold(siteKey)}): ${d.url} ${expires} ${version}`
);
});
return deploys;
Expand Down
1 change: 1 addition & 0 deletions src/deploy/hosting/release.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ module.exports = function (context, options) {
);
logger.debug("[hosting] release:", releaseResult.body);
utils.logLabeledSuccess("hosting[" + deploy.site + "]", "release complete");
deploy.release = releaseResult.body;
})
);
};
7 changes: 5 additions & 2 deletions src/deploy/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,11 @@ 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) => {
siteDetails[deploy.site] = { release: deploy.release };
});
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
2 changes: 1 addition & 1 deletion src/hosting/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ enum ReleaseType {
SITE_DISABLE = "SITE_DISABLE",
}

interface Release {
export interface Release {
// The unique identifier for the release, in the format:
// <code>sites/<var>site-name</var>/releases/<var>releaseID</var></code>
readonly name: string;
Expand Down