# .github/workflows/deploy-wasp-to-railway.yml name: Deploy Wasp app to Railway (template) on: push: branches: - main # production branch - staging # staging branch env: WASP_APP_DIR: app NODE_VERSION: "22" SERVER_NODE_OPTIONS: "--max-old-space-size=8192" CLIENT_NODE_OPTIONS: "--max-old-space-size=4096" jobs: deploy: runs-on: ubuntu-latest strategy: matrix: include: - environment: staging branch: staging api_base_url: https://api-staging.example.com server_service: your-stg-server client_service: your-stg-client - environment: production branch: main api_base_url: https://api.example.com server_service: your-prod-server client_service: your-prod-client if: github.ref == format('refs/heads/{0}', matrix.branch) environment: ${{ matrix.environment }} steps: - name: Checkout uses: actions/checkout@v4 - name: Set up Node.js uses: actions/setup-node@v4 with: node-version: ${{ env.NODE_VERSION }} - name: Install Wasp CLI run: | curl -sSL https://get.wasp.sh/installer.sh | sh echo "$HOME/.local/bin" >> "$GITHUB_PATH" - name: Build Wasp project (server + client scaffolding) working-directory: ${{ env.WASP_APP_DIR }} env: NODE_OPTIONS: ${{ env.SERVER_NODE_OPTIONS }} run: wasp build # Optional: remove dotenv preload if not needed by your runtime - name: Remove dotenv preload from generated server (optional) working-directory: ${{ env.WASP_APP_DIR }}/.wasp/build/server run: sed -i 's/-r dotenv\/config //g' package.json || true - name: Install client dependencies working-directory: ${{ env.WASP_APP_DIR }}/.wasp/build/web-app run: npm install - name: Build client (per-environment) working-directory: ${{ env.WASP_APP_DIR }}/.wasp/build/web-app env: NODE_OPTIONS: ${{ env.CLIENT_NODE_OPTIONS }} # Keep VITE_* (for Vite) and/or REACT_APP_* (for CRA/legacy) as needed VITE_API_BASE_URL: ${{ matrix.api_base_url }} REACT_APP_API_URL: ${{ matrix.api_base_url }} REACT_APP_API_BASE_URL: ${{ matrix.api_base_url }} run: npm run build - name: Install Railway CLI run: npm install -g @railway/cli - name: Deploy server to Railway working-directory: ${{ env.WASP_APP_DIR }}/.wasp/build run: railway up --service ${{ matrix.server_service }} --ci --path-as-root . env: # Add this secret in each GitHub Environment (staging/production) RAILWAY_TOKEN: ${{ secrets.RAILWAY_TOKEN }} - name: Deploy client to Railway working-directory: ${{ env.WASP_APP_DIR }}/.wasp/build/web-app/build run: railway up --service ${{ matrix.client_service }} --ci env: RAILWAY_TOKEN: ${{ secrets.RAILWAY_TOKEN }}