mirror of
https://github.com/webstudio-is/webstudio.git
synced 2026-12-03 05:45:55 +09:00
129 lines
4.2 KiB
YAML
129 lines
4.2 KiB
YAML
name: "VERCEL BUILD AND DEPLOY"
|
|
description: "Builds and deploy vercel project"
|
|
|
|
inputs:
|
|
vercel-token:
|
|
description: "Vercel token"
|
|
required: true
|
|
vercel-org-id:
|
|
description: "Vercel Organization ID"
|
|
required: true
|
|
vercel-project-id:
|
|
description: "Vercel Project ID"
|
|
required: true
|
|
ref-name:
|
|
description: "Branch"
|
|
required: true
|
|
sha:
|
|
description: "Sha"
|
|
required: true
|
|
environment:
|
|
description: "Sha"
|
|
required: true
|
|
|
|
outputs:
|
|
domain:
|
|
description: "Domain"
|
|
value: ${{ steps.deploy.outputs.domain }}
|
|
inspect-url:
|
|
description: "Inspect URL"
|
|
value: ${{ steps.deploy.outputs.inspect-url }}
|
|
alias:
|
|
description: "Alias"
|
|
value: ${{ steps.alias.outputs.value }}
|
|
|
|
runs:
|
|
using: "composite"
|
|
steps:
|
|
- id: branch
|
|
run: |
|
|
CLEAN_NAME="${REF_NAME/.staging/}"
|
|
CLEAN_NAME=$( echo "${CLEAN_NAME}" | sed 's/[^a-zA-Z0-9_-]//g' | tr A-Z a-z | tr _ - | sed 's/-\{2,\}/-/g' )
|
|
echo "value=${CLEAN_NAME}" >> $GITHUB_OUTPUT
|
|
shell: bash
|
|
env:
|
|
REF_NAME: ${{ inputs.ref-name }}
|
|
|
|
- id: short_sha
|
|
run: |
|
|
SHORT_SHA=$( echo "value=$(echo ${{ inputs.sha }} | cut -c1-7)" )
|
|
echo "value=${SHORT_SHA}" >> $GITHUB_OUTPUT
|
|
shell: bash
|
|
|
|
- name: CREATE VERCEL PROJECT FILE
|
|
run: |
|
|
mkdir -p .vercel
|
|
cat <<"EOF" > .vercel/project.json
|
|
{
|
|
"projectId": "${{ inputs.vercel-project-id }}",
|
|
"orgId": "${{ inputs.vercel-org-id }}",
|
|
"settings": {
|
|
"framework": "remix",
|
|
"devCommand": "pnpm dev",
|
|
"installCommand": "pnpm install",
|
|
"buildCommand": "pnpm --filter=@webstudio-is/http-client build && pnpm --filter=@webstudio-is/builder build",
|
|
"outputDirectory": null,
|
|
"rootDirectory": "apps/builder",
|
|
"directoryListing": false,
|
|
"nodeVersion": "20.x"
|
|
}
|
|
}
|
|
EOF
|
|
shell: bash
|
|
|
|
- name: Build
|
|
run: |
|
|
export GITHUB_SHA=${{ inputs.sha }}
|
|
export GITHUB_REF_NAME=${{ inputs.ref-name }}
|
|
|
|
pnpx vercel build
|
|
shell: bash
|
|
|
|
- name: Patch
|
|
run: |
|
|
# When we deploy on Vercel, it generates a URL like webstudio-saas-mahqcavgo-getwebstudio.vercel.app.
|
|
# We use the alias oauth-wstd-00-staging.vercel.app for routing, which maps to oauth.staging.webstudio.is on the worker.
|
|
# Issue: Vercel proxies also set x-forwarded-host, which overrides our header.
|
|
# We are adding x-forwarded-ws-host on the worker as a workaround, but issues with request.url persist.
|
|
# Remix and the Vercel adapter lack support for header selection https://github.com/vercel/vercel/blob/9d4d4b6deb6294506016106f78e71f1984adcc7f/packages/remix/defaults/server-node.mjs#L44
|
|
# Patching server-node.mjs directly without installing Vercel CLI was unsuccessful, so we are using string replacement instead.
|
|
|
|
mapfile -t matching_files < <(grep -rl "req\.headers\['x-forwarded-host'\] || req\.headers\.host" "./apps/builder/build")
|
|
if [ ${#matching_files[@]} -eq 0 ]; then
|
|
echo "No files found containing the specified string."
|
|
exit 1
|
|
fi
|
|
|
|
echo "Files containing 'req.headers['x-forwarded-host'] || req.headers.host':"
|
|
printf '%s\n' "${matching_files[@]}"
|
|
|
|
find ./apps/builder/build -type f -exec sed -i "s/req\.headers\['x-forwarded-host'\] || req\.headers\.host/req.headers['x-forwarded-ws-host'] || req.headers['x-forwarded-host'] || req.headers.host/g" {} +
|
|
shell: bash
|
|
|
|
- name: Deploy
|
|
id: deploy
|
|
run: |
|
|
pnpx vercel deploy \
|
|
--prebuilt \
|
|
--token ${{ inputs.vercel-token }} \
|
|
2> >(tee info.txt >&2) | tee domain.txt
|
|
|
|
echo "domain=$(cat ./domain.txt)" >> $GITHUB_OUTPUT
|
|
echo "inspect-url=$(cat info.txt | grep 'Inspect:' | awk '{print $2}')" >> $GITHUB_OUTPUT
|
|
|
|
shell: bash
|
|
|
|
- name: Set Alias
|
|
id: alias
|
|
run: |
|
|
ALIAS="${{ steps.branch.outputs.value }}"
|
|
|
|
pnpx vercel alias set \
|
|
"${{ steps.deploy.outputs.domain }}" \
|
|
"${ALIAS}-wstd-00-${{ inputs.environment }}" \
|
|
--token ${{ inputs.vercel-token }} \
|
|
--scope getwebstudio
|
|
|
|
echo "value=${ALIAS}" >> $GITHUB_OUTPUT
|
|
shell: bash
|