Skip to content

Open source website builder and Webflow alternative. Webstudio is an advanced visual builder that connects to any headless CMS, supports all CSS properties, and can be hosted anywhere, including with us.

chore: Load fixtures by build id, use current deplyment for sync (#3890)

Ivan Starkov749d56920f83
diff --git a/.github/workflows/fixtures-test.yaml b/.github/workflows/fixtures-test.yaml
deleted file mode 100644
index 372d42fc47..0000000000
--- a/.github/workflows/fixtures-test.yaml
+++ /dev/null
@@ -1,33 +0,0 @@
-name: Fixtures Test
-
-on:
- workflow_run:
- workflows: ["Vercel Deploy Staging"]
- types:
- - completed
-
-# cancel in-progress runs on new commits to same PR (gitub.event.number)
-concurrency:
- group: fixtures-${{ github.workflow }}-${{ github.event.number || github.sha }}
- cancel-in-progress: true
-
-permissions:
- contents: read # to fetch code (actions/checkout)
-
-jobs:
- checks-2:
- timeout-minutes: 20
- runs-on: ubuntu-latest
- steps:
- - uses: actions/checkout@v4
- with:
- ref: ${{ github.event.pull_request.head.sha || github.sha }} # HEAD commit instead of merge commit
-
- - uses: ./.github/actions/ci-setup
-
- - id: branch
- run: |
- echo "EEEE${{ github.event.pull_request.head.sha || github.sha }}EEEE"
- echo "AAAA${{ github.ref_name }}AAAA"
- echo GITHUB_SHA=${GITHUB_SHA}
- echo GITHUB_REF=${GITHUB_REF}
diff --git a/.github/workflows/cli-test.yml b/.github/workflows/fixtures-test.yml
similarity index 83%
rename from .github/workflows/cli-test.yml
rename to .github/workflows/fixtures-test.yml
index 3c436cce0c..5448599c29 100644
--- a/.github/workflows/cli-test.yml
+++ b/.github/workflows/fixtures-test.yml
@@ -1,15 +1,11 @@
-name: Cli tests
+name: Fixtures tests
on:
- push:
- branches:
- - main
- pull_request:
-
-# cancel in-progress runs on new commits to same PR (gitub.event.number)
-concurrency:
- group: cli-${{ github.workflow }}-${{ github.event.number || github.sha }}
- cancel-in-progress: true
+ workflow_call:
+ inputs:
+ builder-url:
+ required: true
+ type: string
permissions:
contents: read # to fetch code (actions/checkout)
@@ -27,6 +23,7 @@ jobs:
env:
DATABASE_URL: postgres://
AUTH_SECRET: test
+ BUILDER_URL: ${{ inputs.builder-url }}
steps:
- uses: actions/checkout@v4
diff --git a/.github/workflows/vercel-deploy-staging.yml b/.github/workflows/vercel-deploy-staging.yml
index e5bf79d739..334330cb28 100644
--- a/.github/workflows/vercel-deploy-staging.yml
+++ b/.github/workflows/vercel-deploy-staging.yml
@@ -73,3 +73,12 @@ jobs:
title: "⭐ [${{ matrix.environment }}] Apps Webstudio URL"
description: "[${{ matrix.environment }}] Site url"
url: "https://${{ steps.vercel.outputs.alias }}.${{ matrix.environment }}.webstudio.is"
+
+ outputs:
+ builder-url: "https://${{ steps.vercel.outputs.alias }}.${{ matrix.environment }}.webstudio.is"
+
+ fixtures-test:
+ needs: deployment
+ uses: ./.github/workflows/fixtures-test.yml
+ with:
+ builder-url: ${{ needs.deployment.outputs.builder-url }}
diff --git a/fixtures/ssg/package.json b/fixtures/ssg/package.json
index d84176e988..cc83543923 100644
--- a/fixtures/ssg/package.json
+++ b/fixtures/ssg/package.json
@@ -8,8 +8,8 @@
"dev": "vite dev",
"typecheck": "tsc",
"cli": "NODE_OPTIONS='--conditions=webstudio --import=tsx' webstudio",
- "fixtures:link": "pnpm cli link --link \"https://main.development.webstudio.is/builder/d845c167-ea07-4875-b08d-83e97c09dcce?authToken=e9d1343f-9298-4fd3-a66e-f89a5af2dd93\"",
- "fixtures:sync": "pnpm cli sync && pnpm prettier --write ./.webstudio/",
+ "fixtures:link": "pnpm cli link --link ${BUILDER_URL:-https://main.development.webstudio.is}'/builder/d845c167-ea07-4875-b08d-83e97c09dcce?authToken=e9d1343f-9298-4fd3-a66e-f89a5af2dd93'",
+ "fixtures:sync": "pnpm cli sync --buildId a2e8de30-03d5-4514-a3a6-406b3266a3af && pnpm prettier --write ./.webstudio/",
"fixtures:build": "rm -rf pages && pnpm cli build --template ssg --template internal --preview && prettier --write ."
},
"engines": {
diff --git a/fixtures/webstudio-cloudflare-template/package.json b/fixtures/webstudio-cloudflare-template/package.json
index af0670e6ef..98804d59b7 100644
--- a/fixtures/webstudio-cloudflare-template/package.json
+++ b/fixtures/webstudio-cloudflare-template/package.json
@@ -2,8 +2,8 @@
"type": "module",
"scripts": {
"cli": "NODE_OPTIONS='--conditions=webstudio --import=tsx' webstudio",
- "fixtures:link": "pnpm cli link --link \"https://main.development.webstudio.is/builder/d845c167-ea07-4875-b08d-83e97c09dcce?authToken=e9d1343f-9298-4fd3-a66e-f89a5af2dd93&\"",
- "fixtures:sync": "pnpm cli sync && pnpm prettier --write ./.webstudio/",
+ "fixtures:link": "pnpm cli link --link ${BUILDER_URL:-https://main.development.webstudio.is}'/builder/d845c167-ea07-4875-b08d-83e97c09dcce?authToken=e9d1343f-9298-4fd3-a66e-f89a5af2dd93'",
+ "fixtures:sync": "pnpm cli sync --buildId a2e8de30-03d5-4514-a3a6-406b3266a3af && pnpm prettier --write ./.webstudio/",
"fixtures:build": "pnpm cli build --template cloudflare --template saas-helpers --template internal --preview && pnpm prettier --write ./app/ ./package.json ./tsconfig.json",
"build": "remix vite:build",
"dev": "remix vite:dev",
diff --git a/fixtures/webstudio-custom-template/package.json b/fixtures/webstudio-custom-template/package.json
index da53efc2ee..3d464db70f 100644
--- a/fixtures/webstudio-custom-template/package.json
+++ b/fixtures/webstudio-custom-template/package.json
@@ -5,8 +5,8 @@
"dev": "remix vite:dev",
"typecheck": "tsc",
"cli": "NODE_OPTIONS='--conditions=webstudio --import=tsx' webstudio",
- "fixtures:link": "pnpm cli link --link \"https://main.development.webstudio.is/builder/0d856812-61d8-4014-a20a-82e01c0eb8ee?authToken=d225fafb-4f20-4340-9359-c21df7c49a3f\"",
- "fixtures:sync": "pnpm cli sync && pnpm prettier --write ./.webstudio/",
+ "fixtures:link": "pnpm cli link --link ${BUILDER_URL:-https://main.development.webstudio.is}'/builder/0d856812-61d8-4014-a20a-82e01c0eb8ee?authToken=d225fafb-4f20-4340-9359-c21df7c49a3f'",
+ "fixtures:sync": "pnpm cli sync --buildId d48c7c5e-fdd3-4ef6-9173-ff2eaaf851d9 && pnpm prettier --write ./.webstudio/",
"fixtures:build": "pnpm cli build --template defaults --template ./custom-template --template ./custom-template-stage --template internal --preview --assets false && pnpm prettier --write ./app/ ./package.json ./tsconfig.json"
},
"private": true,
diff --git a/fixtures/webstudio-remix-netlify-edge-functions/package.json b/fixtures/webstudio-remix-netlify-edge-functions/package.json
index 94ac39d352..f4e9af8570 100644
--- a/fixtures/webstudio-remix-netlify-edge-functions/package.json
+++ b/fixtures/webstudio-remix-netlify-edge-functions/package.json
@@ -6,8 +6,8 @@
"dev": "remix vite:dev",
"typecheck": "tsc",
"cli": "NODE_OPTIONS='--conditions=webstudio --import=tsx' webstudio",
- "fixtures:link": "pnpm cli link --link \"https://main.development.webstudio.is/builder/d845c167-ea07-4875-b08d-83e97c09dcce?authToken=e9d1343f-9298-4fd3-a66e-f89a5af2dd93&\"",
- "fixtures:sync": "pnpm cli sync && pnpm prettier --write ./.webstudio/",
+ "fixtures:link": "pnpm cli link --link ${BUILDER_URL:-https://main.development.webstudio.is}'/builder/d845c167-ea07-4875-b08d-83e97c09dcce?authToken=e9d1343f-9298-4fd3-a66e-f89a5af2dd93'",
+ "fixtures:sync": "pnpm cli sync --buildId a2e8de30-03d5-4514-a3a6-406b3266a3af && pnpm prettier --write ./.webstudio/",
"fixtures:build": "pnpm cli build --template netlify-edge-functions --template internal --preview && pnpm prettier --write ./app/ ./package.json ./tsconfig.json"
},
"dependencies": {
diff --git a/fixtures/webstudio-remix-netlify-functions/package.json b/fixtures/webstudio-remix-netlify-functions/package.json
index 7f6fdc9601..51ad1ddbbb 100644
--- a/fixtures/webstudio-remix-netlify-functions/package.json
+++ b/fixtures/webstudio-remix-netlify-functions/package.json
@@ -5,8 +5,8 @@
"start": "netlify serve",
"typecheck": "tsc",
"cli": "NODE_OPTIONS='--conditions=webstudio --import=tsx' webstudio",
- "fixtures:link": "pnpm cli link --link \"https://main.development.webstudio.is/builder/d845c167-ea07-4875-b08d-83e97c09dcce?authToken=e9d1343f-9298-4fd3-a66e-f89a5af2dd93\"",
- "fixtures:sync": "pnpm cli sync && pnpm prettier --write ./.webstudio/",
+ "fixtures:link": "pnpm cli link --link ${BUILDER_URL:-https://main.development.webstudio.is}'/builder/d845c167-ea07-4875-b08d-83e97c09dcce?authToken=e9d1343f-9298-4fd3-a66e-f89a5af2dd93'",
+ "fixtures:sync": "pnpm cli sync --buildId a2e8de30-03d5-4514-a3a6-406b3266a3af && pnpm prettier --write ./.webstudio/",
"fixtures:build": "pnpm cli build --template netlify-functions --template internal --preview && pnpm prettier --write ./app/ ./package.json ./tsconfig.json"
},
"dependencies": {
diff --git a/fixtures/webstudio-remix-vercel/package.json b/fixtures/webstudio-remix-vercel/package.json
index d72469897c..8bc89bb604 100644
--- a/fixtures/webstudio-remix-vercel/package.json
+++ b/fixtures/webstudio-remix-vercel/package.json
@@ -5,8 +5,8 @@
"dev": "remix vite:dev",
"typecheck": "tsc",
"cli": "NODE_OPTIONS='--conditions=webstudio --import=tsx' webstudio",
- "fixtures:link": "pnpm cli link --link \"https://main.development.webstudio.is/builder/cddc1d44-af37-4cb6-a430-d300cf6f932d?authToken=1cdc6026-dd5b-4624-b89b-9bd45e9bcc3d&mode=preview\"",
- "fixtures:sync": "pnpm cli sync && pnpm prettier --write ./.webstudio/",
+ "fixtures:link": "pnpm cli link --link ${BUILDER_URL:-https://main.development.webstudio.is}'/builder/cddc1d44-af37-4cb6-a430-d300cf6f932d?authToken=1cdc6026-dd5b-4624-b89b-9bd45e9bcc3d'",
+ "fixtures:sync": "pnpm cli sync --buildId 3dce3f4f-3c20-46e5-a885-d1b543db6237 && pnpm prettier --write ./.webstudio/",
"fixtures:build": "pnpm cli build --template vercel --template internal --preview && pnpm prettier --write ./app/ ./package.json ./tsconfig.json"
},
"private": true,
diff --git a/packages/cli/src/commands/sync.ts b/packages/cli/src/commands/sync.ts
index 6158b6d4a6..8779ddbc7e 100644
--- a/packages/cli/src/commands/sync.ts
+++ b/packages/cli/src/commands/sync.ts
@@ -5,7 +5,7 @@ import pc from "picocolors";
import { spinner } from "@clack/prompts";
import {
loadProjectDataByBuildId,
- loadProjectDataById,
+ loadProjectDataByProjectId,
type Data,
} from "@webstudio-is/http-client";
import { createFileIfNotExists, isFileExists } from "../fs-utils";
@@ -40,29 +40,19 @@ export const sync = async (
options: StrictYargsOptionsToInterface<typeof syncOptions>
) => {
const syncing = spinner();
- syncing.start("Synchronizing project data");
-
- const definedOptionValues = [
- options.buildId,
- options.origin,
- options.authToken,
- ].filter(Boolean);
-
- if (definedOptionValues.length > 0 && definedOptionValues.length < 3) {
- syncing.stop(`Please provide buildId, origin and authToken`, 2);
- return;
- }
let project: Data | undefined;
+ syncing.start(`Synchronizing project data`);
if (
options.buildId !== undefined &&
options.origin !== undefined &&
options.authToken !== undefined
) {
+ syncing.message(`Synchronizing project data from ${options.origin}`);
project = await loadProjectDataByBuildId({
buildId: options.buildId,
- authToken: options.authToken,
+ seviceToken: options.authToken,
origin: options.origin,
});
} else {
@@ -95,13 +85,21 @@ export const sync = async (
}
const { origin, token } = projectConfig;
+ syncing.message(`Synchronizing project data from ${origin}`);
try {
- project = await loadProjectDataById({
- projectId: localConfig.projectId,
- authToken: token,
- origin,
- });
+ project =
+ options.buildId !== undefined
+ ? await loadProjectDataByBuildId({
+ buildId: options.buildId,
+ authToken: token,
+ origin,
+ })
+ : await loadProjectDataByProjectId({
+ projectId: localConfig.projectId,
+ authToken: token,
+ origin,
+ });
} catch (error) {
// catch errors about unpublished project
syncing.stop((error as Error).message, 2);
diff --git a/packages/http-client/src/index.ts b/packages/http-client/src/index.ts
index 0b3a8c7389..1660a42918 100644
--- a/packages/http-client/src/index.ts
+++ b/packages/http-client/src/index.ts
@@ -37,7 +37,7 @@ export type Data = {
assets: Array<Asset>;
};
-export const loadProjectDataById = async (params: {
+export const loadProjectDataByProjectId = async (params: {
projectId: string;
origin: string;
authToken?: string;
@@ -64,18 +64,29 @@ export const loadProjectDataById = async (params: {
throw new Error(message.slice(0, 1000));
};
-export const loadProjectDataByBuildId = async (params: {
- buildId: string;
- origin: string;
- authToken: string;
-}): Promise<Data> => {
+export const loadProjectDataByBuildId = async (
+ params: {
+ buildId: string;
+ origin: string;
+ } & (
+ | {
+ seviceToken: string;
+ }
+ | { authToken: string }
+ )
+): Promise<Data> => {
const url = new URL(params.origin);
url.pathname = `/rest/build/${params.buildId}`;
+ const headers: Record<string, string> = {};
+ if ("seviceToken" in params) {
+ headers.Authorization = params.seviceToken;
+ } else {
+ headers["x-auth-token"] = params.authToken;
+ }
+
const response = await fetch(url.href, {
- headers: {
- Authorization: params.authToken,
- },
+ headers,
});
if (response.ok) {