@backifydev/cli 0.3.5 → 0.3.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +19 -4
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -22776,6 +22776,21 @@ function localReport(runChecks, root = process.cwd()) {
|
|
|
22776
22776
|
function matchesSource(release, commit) {
|
|
22777
22777
|
return release?.commitSha === commit || release?.sourceCommitSha === commit;
|
|
22778
22778
|
}
|
|
22779
|
+
function pushSource(appId, commit, branch, destination, root, environment) {
|
|
22780
|
+
const remoteHead = git2(["ls-remote", "--", destination, "refs/heads/" + branch], root, environment).split(/\s+/)[0];
|
|
22781
|
+
if (remoteHead === commit) return true;
|
|
22782
|
+
if (remoteHead) {
|
|
22783
|
+
git2(["fetch", "--no-tags", "--", destination, "refs/heads/" + branch], root, environment);
|
|
22784
|
+
const fetchedHead = git2(["rev-parse", "FETCH_HEAD"], root);
|
|
22785
|
+
if (fetchedHead === commit) return true;
|
|
22786
|
+
const parent = git2(["show", "-s", "--format=%P", fetchedHead], root);
|
|
22787
|
+
const message = git2(["show", "-s", "--format=%B", fetchedHead], root);
|
|
22788
|
+
if (parent === commit && message === "Backify build " + applicationGuid(appId).replaceAll("-", "") + ": " + commit) return true;
|
|
22789
|
+
if (git2(["merge-base", commit, fetchedHead], root) !== fetchedHead) throw new Error("Remote history contains other changes. Run backify pull and reconcile them before shipping; nothing was pushed or overwritten.");
|
|
22790
|
+
}
|
|
22791
|
+
git2(["push", "--", destination, commit + ":refs/heads/" + branch], root, environment);
|
|
22792
|
+
return false;
|
|
22793
|
+
}
|
|
22779
22794
|
async function waitForPreview(call2, prefix, commit, options = {}) {
|
|
22780
22795
|
const deadline = Date.now() + (options.timeoutMs ?? 20 * 6e4);
|
|
22781
22796
|
const sleep = options.sleep ?? ((delay) => new Promise((resolve24) => setTimeout(resolve24, delay)));
|
|
@@ -22817,10 +22832,10 @@ async function ship(call2, appId, options = {}) {
|
|
|
22817
22832
|
if (credential.repository.toLowerCase() !== status.repository.toLowerCase()) throw new Error("Repository changed; reconnect before shipping.");
|
|
22818
22833
|
const environment = gitEnvironment(status.repository, credential.token);
|
|
22819
22834
|
const destination = "https://github.com/" + status.repository + ".git";
|
|
22820
|
-
const
|
|
22821
|
-
|
|
22822
|
-
if (
|
|
22823
|
-
const overview = await waitForPreview(call2, prefix, commit, { timeoutMs: options.timeoutMs, previousDeploymentIds: previousDeployments.map((deployment) => deployment.id), previousBuildRunId: previousBuild.runId ?? null });
|
|
22835
|
+
const alreadyPushed = pushSource(appId, commit, status.branch, destination, root, environment);
|
|
22836
|
+
const currentPreview = previousDeployments.find((release) => release.kind === "preview" && matchesSource(release, commit));
|
|
22837
|
+
if (alreadyPushed && (!currentPreview || currentPreview.status === "failed") && !(matchesSource(status.releases.preview, commit) && status.releases.preview?.status === "succeeded")) await call2(prefix + "/deployments/preview", { method: "POST", body: JSON.stringify({ sourceRevision: "latest" }) });
|
|
22838
|
+
const overview = await waitForPreview(call2, prefix, commit, { timeoutMs: options.timeoutMs, previousDeploymentIds: previousDeployments.filter((deployment) => deployment.status === "failed").map((deployment) => deployment.id), previousBuildRunId: previousBuild.runId ?? null });
|
|
22824
22839
|
if (overview.preview.commitSha !== commit) {
|
|
22825
22840
|
if (git2(["status", "--porcelain"], root) || git2(["rev-parse", "HEAD"], root) !== commit) throw new Error("Local work changed while the preview built. Review it before synchronizing the build commit.");
|
|
22826
22841
|
const refreshed = await call2(prefix + "/developer/git-credential", { method: "POST" });
|