161 lines
4.2 KiB
YAML
161 lines
4.2 KiB
YAML
name: CI/CD
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- master
|
|
|
|
jobs:
|
|
test:
|
|
name: Test
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Setup PHP
|
|
uses: shivammathur/setup-php@v2
|
|
with:
|
|
php-version: '8.5'
|
|
extensions: mbstring, dom, curl, sqlite3, pdo_sqlite
|
|
coverage: none
|
|
|
|
- name: Cache Composer packages
|
|
uses: actions/cache@v4
|
|
with:
|
|
path: vendor
|
|
key: composer-${{ hashFiles('composer.lock') }}
|
|
restore-keys: composer-
|
|
|
|
- name: Install Composer dependencies
|
|
run: composer install --no-interaction --prefer-dist --optimize-autoloader
|
|
|
|
- name: Copy environment file
|
|
run: cp .env.example .env
|
|
|
|
- name: Generate application key
|
|
run: php artisan key:generate
|
|
|
|
- name: Create SQLite database file
|
|
run: touch database/database.sqlite
|
|
|
|
- name: Run tests
|
|
run: php artisan test --compact
|
|
|
|
build:
|
|
name: Build
|
|
needs: test
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Setup PHP
|
|
uses: shivammathur/setup-php@v2
|
|
with:
|
|
php-version: '8.5'
|
|
extensions: mbstring, dom, curl, sqlite3, pdo_sqlite
|
|
coverage: none
|
|
|
|
- name: Cache Composer packages
|
|
uses: actions/cache@v4
|
|
with:
|
|
path: vendor
|
|
key: composer-prod-${{ hashFiles('composer.lock') }}
|
|
restore-keys: composer-prod-
|
|
|
|
- name: Install Composer dependencies (production)
|
|
run: composer install --no-interaction --prefer-dist --optimize-autoloader --no-dev
|
|
|
|
- name: Setup Node.js
|
|
uses: actions/setup-node@v4
|
|
with:
|
|
node-version: '22'
|
|
|
|
- name: Cache Node modules
|
|
uses: actions/cache@v4
|
|
with:
|
|
path: node_modules
|
|
key: node-${{ hashFiles('package-lock.json') }}
|
|
restore-keys: node-
|
|
|
|
- name: Install Node dependencies
|
|
run: npm ci
|
|
|
|
- name: Build frontend assets
|
|
run: npm run build
|
|
|
|
- name: Create deployment archive
|
|
run: |
|
|
tar --exclude='.git' \
|
|
--exclude='.gitea' \
|
|
--exclude='node_modules' \
|
|
--exclude='tests' \
|
|
--exclude='.env' \
|
|
--exclude='*.md' \
|
|
-czf /tmp/deploy.tar.gz .
|
|
|
|
- name: Upload deployment artifact
|
|
uses: actions/upload-artifact@v4
|
|
with:
|
|
name: deploy-${{ github.sha }}
|
|
path: /tmp/deploy.tar.gz
|
|
retention-days: 7
|
|
|
|
deploy:
|
|
name: Deploy
|
|
needs: build
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
- name: Download deployment artifact
|
|
uses: actions/download-artifact@v4
|
|
with:
|
|
name: deploy-${{ github.sha }}
|
|
path: /tmp
|
|
|
|
- name: Setup SSH known hosts
|
|
run: |
|
|
mkdir -p ~/.ssh
|
|
ssh-keyscan -p ${{ secrets.SSH_PORT || 22 }} ${{ secrets.SSH_HOST }} >> ~/.ssh/known_hosts
|
|
|
|
- name: Install sshpass
|
|
run: sudo apt-get install -y sshpass
|
|
|
|
- name: Upload archive to server
|
|
run: |
|
|
sshpass -p "${{ secrets.SSH_PASSWORD }}" \
|
|
rsync -az --no-perms \
|
|
-e "ssh -p ${{ secrets.SSH_PORT || 22 }}" \
|
|
/tmp/deploy.tar.gz \
|
|
${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }}:${{ secrets.DEPLOY_PATH }}/deploy.tar.gz
|
|
|
|
- name: Extract and deploy on server
|
|
run: |
|
|
sshpass -p "${{ secrets.SSH_PASSWORD }}" \
|
|
ssh -p ${{ secrets.SSH_PORT || 22 }} \
|
|
${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }} << 'ENDSSH'
|
|
|
|
set -e
|
|
DEPLOY_PATH="${{ secrets.DEPLOY_PATH }}"
|
|
|
|
cd "$DEPLOY_PATH"
|
|
|
|
# Extract archive
|
|
tar -xzf deploy.tar.gz
|
|
rm deploy.tar.gz
|
|
|
|
# Write .env from secret
|
|
echo "${{ secrets.ENV_FILE }}" > .env
|
|
|
|
# Run post-deploy commands
|
|
php artisan config:cache
|
|
php artisan route:cache
|
|
php artisan view:cache
|
|
php artisan migrate --force --no-interaction
|
|
php artisan queue:restart
|
|
|
|
ENDSSH
|