Files
lapikud.github.io/.github/workflows/build-deploy.yml
2026-04-08 00:39:29 +03:00

59 lines
1.7 KiB
YAML

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: "24" # 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: |
# Keep only the build output and git metadata
find . -mindepth 1 -maxdepth 1 ! -name .git ! -name dist -exec rm -rf {} +
# Copy build output to repo root (includes files from public/)
cp -a dist/. .
rm -rf 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