Skip to content

Commit

Permalink
Github actions to create dist in server
Browse files Browse the repository at this point in the history
  • Loading branch information
karlosvas committed Jan 12, 2025
1 parent fb18f19 commit 5457c01
Show file tree
Hide file tree
Showing 9 changed files with 109 additions and 26 deletions.
73 changes: 73 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
name: Build and Deploy
on:
push:
branches:
- main

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: "21.2.0"

- name: Install dependencies
run: |
echo -e "\e[34mInstalling dependencies...\e[0m"
cd server
npm install
- name: Build project
run: |
echo -e "\e[34mBuilding project...\e[0m"
cd server
npm run build
ls
if [ ! -d "public" ]; then
echo -e "\e[31mBuild failed: 'public' directory not found.\e[0m"
exit 1
else
echo -e "\e[32mBuild succeeded.\e[0m"
fi
- name: Upload build artifacts
uses: actions/upload-artifact@v3
with:
name: public
path: server/public

deploy:
runs-on: ubuntu-latest
needs: build

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Download build artifacts
uses: actions/download-artifact@v3
with:
name: public
path: server/public/

- name: Deploy server to Vercel
run: |
cd server
npm install --g vercel@latest
vercel pull --yes --environment=preview --token=${{ secrets.VERCEL_TOKEN }} --cwd server
vercel build --token=${{ secrets.VERCEL_TOKEN }} --cwd server
vercel deploy --prebuilt --token=${{ secrets.VERCEL_TOKEN }} --cwd server
- name: Deploy client to Vercel
run: |
echo -e "\e[34mDeploying client to Vercel...\e[0m"
npm install -g vercel
cd client
npm install
npm run build
npx vercel --token ${{ secrets.VERCEL_TOKEN }} --yes --cwd client
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ dev
dist-ssr
client/dist
*.local
dist

# Editor directories and files
.vscode/*
Expand Down
1 change: 1 addition & 0 deletions client/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.vercel
7 changes: 0 additions & 7 deletions client/vercel.json

This file was deleted.

1 change: 1 addition & 0 deletions server/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.vercel
2 changes: 1 addition & 1 deletion server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"main": "index.ts",
"scripts": {
"start": "npm run build && node dist/index.js",
"dev": "node --loader ts-node/esm src/index.js",
"dev": "node --loader ts-node/esm index.js",
"test": "npm run build && playwright test",
"build": "tsc"
},
Expand Down
2 changes: 1 addition & 1 deletion server/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"rootDir": "./" /* Specify the root folder within your source files. */,
"moduleResolution": "node" /* Specify how TypeScript looks up a file from a given module specifier. */,
"baseUrl": "./" /* Specify the base directory to resolve non-relative module names. */,
"outDir": "dist" /* Specify an output folder for all emitted files. */,
"outDir": "public" /* Specify an output folder for all emitted files. */,
"paths": {
"types/*": ["types/*"]
} /* Specify a set of entries that re-map imports to additional lookup locations. */,
Expand Down
16 changes: 0 additions & 16 deletions server/vercel.json

This file was deleted.

32 changes: 32 additions & 0 deletions vercel.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"version": 2,
"builds": [
{
"src": "server/package.json",
"use": "@vercel/node"
},
{
"src": "client/package.json",
"use": "@vercel/static-build",
"config": {
"distDir": "build"
}
}
],
"routes": [
{
"src": "/api/(.*)",
"dest": "/server/$1"
},
{
"src": "/(.*)",
"dest": "/client/$1"
}
],
"rewrites": [
{ "source": "/robots.txt", "destination": "/public/robots.txt" },
{ "source": "/sitemap.xml", "destination": "/public/sitemap.xml" },
{ "source": "/api/(.*)", "destination": "/server/api/$1" },
{ "source": "/(.*)", "destination": "/client/$1" }
]
}

0 comments on commit 5457c01

Please sign in to comment.