name: Build and Deploy to Production # Configuration env: SOURCE_BRANCH: v2 # Change this to your desired trigger branch PRODUCTION_BRANCH: production # Change this to your desired output branch NODE_VERSION: "20" # Specify Node version for consistency on: push: branches: - v2 # Update this if you change SOURCE_BRANCH above jobs: build-and-deploy: runs-on: ubuntu-latest permissions: contents: write # Required to push to the production branch steps: - name: Checkout code uses: actions/checkout@v4 with: fetch-depth: 0 # Full history for better git operations - name: Setup Node.js uses: actions/setup-node@v4 with: node-version: ${{ env.NODE_VERSION }} cache: npm - name: Install dependencies run: npm ci - name: Build project run: npm run build - name: Prepare for deployment run: | # Remove source files, keep only dist rm -rf src public package.json node_modules vite.config.js svelte.config.js tailwind.config.js README.md # Move build output to root mv dist/* . rmdir dist - name: Deploy to production branch run: | git config user.name "github-actions[bot]" git config user.email "github-actions[bot]@users.noreply.github.com" git add -A # Check if there are changes if git diff --quiet --cached; then echo "No changes to commit" else git commit -m "Build from ${{ github.sha }}" git push origin HEAD:${{ env.PRODUCTION_BRANCH }} --force fi