runner
This commit is contained in:
@@ -1,14 +1,19 @@
|
|||||||
name: CI
|
name: Test Build Deploy
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches: ['**']
|
branches:
|
||||||
pull_request:
|
- master
|
||||||
branches: ['**']
|
|
||||||
|
env:
|
||||||
|
PHP_VERSION: '8.4'
|
||||||
|
NODE_VERSION: '22'
|
||||||
|
ARTIFACT_NAME: laravel-release
|
||||||
|
RELEASE_FILE: laravel-release.tar.gz
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
test:
|
test:
|
||||||
name: Run Tests
|
name: Test
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
@@ -18,21 +23,138 @@ jobs:
|
|||||||
- name: Setup PHP
|
- name: Setup PHP
|
||||||
uses: shivammathur/setup-php@v2
|
uses: shivammathur/setup-php@v2
|
||||||
with:
|
with:
|
||||||
php-version: '8.4'
|
php-version: ${{ env.PHP_VERSION }}
|
||||||
extensions: pdo, pdo_sqlite, sqlite3
|
extensions: pdo, pdo_sqlite, sqlite3
|
||||||
coverage: none
|
coverage: none
|
||||||
|
|
||||||
- name: Copy .env
|
- name: Copy environment file
|
||||||
run: cp .env.example .env
|
run: cp .env.example .env
|
||||||
|
|
||||||
- name: Install Composer dependencies
|
- name: Install Composer dependencies
|
||||||
run: composer install --no-interaction --prefer-dist --optimize-autoloader
|
run: composer install --no-interaction --prefer-dist --optimize-autoloader
|
||||||
|
|
||||||
- name: Generate app key
|
- name: Generate application key
|
||||||
run: php artisan key:generate
|
run: php artisan key:generate --ansi
|
||||||
|
|
||||||
- name: Run migrations
|
- name: Run migrations
|
||||||
run: php artisan migrate --no-interaction --force
|
run: php artisan migrate --no-interaction --force
|
||||||
|
|
||||||
- name: Run tests
|
- name: Run Laravel tests
|
||||||
run: php artisan test --compact
|
run: composer run test
|
||||||
|
|
||||||
|
build:
|
||||||
|
name: Build
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
needs: test
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Setup PHP
|
||||||
|
uses: shivammathur/setup-php@v2
|
||||||
|
with:
|
||||||
|
php-version: ${{ env.PHP_VERSION }}
|
||||||
|
extensions: pdo, pdo_sqlite, sqlite3
|
||||||
|
coverage: none
|
||||||
|
|
||||||
|
- name: Setup Node
|
||||||
|
uses: actions/setup-node@v4
|
||||||
|
with:
|
||||||
|
node-version: ${{ env.NODE_VERSION }}
|
||||||
|
cache: npm
|
||||||
|
|
||||||
|
- name: Install production Composer dependencies
|
||||||
|
run: composer install --no-dev --no-interaction --prefer-dist --optimize-autoloader
|
||||||
|
|
||||||
|
- name: Install Node dependencies
|
||||||
|
run: npm ci
|
||||||
|
|
||||||
|
- name: Build frontend assets
|
||||||
|
run: npm run build
|
||||||
|
|
||||||
|
- name: Create release artifact
|
||||||
|
run: |
|
||||||
|
tar \
|
||||||
|
--exclude='.git' \
|
||||||
|
--exclude='.gitea' \
|
||||||
|
--exclude='.env' \
|
||||||
|
--exclude='node_modules' \
|
||||||
|
--exclude='tests' \
|
||||||
|
--exclude='storage/logs/*' \
|
||||||
|
--exclude='storage/framework/cache/*' \
|
||||||
|
--exclude='storage/framework/sessions/*' \
|
||||||
|
--exclude='storage/framework/views/*' \
|
||||||
|
-czf "${RELEASE_FILE}" .
|
||||||
|
|
||||||
|
- name: Upload release artifact
|
||||||
|
uses: actions/upload-artifact@v4
|
||||||
|
with:
|
||||||
|
name: ${{ env.ARTIFACT_NAME }}
|
||||||
|
path: ${{ env.RELEASE_FILE }}
|
||||||
|
if-no-files-found: error
|
||||||
|
|
||||||
|
deploy:
|
||||||
|
name: Deploy
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
needs: build
|
||||||
|
|
||||||
|
env:
|
||||||
|
# Required Gitea secrets:
|
||||||
|
# - SSH_HOST: server hostname or IP address
|
||||||
|
# - SSH_PORT: SSH port, usually 22
|
||||||
|
# - SSH_USER: SSH username for deployment
|
||||||
|
# - SSH_PASSWORD: SSH password for deployment
|
||||||
|
# - DEPLOY_PATH: absolute path on the server where the app will be deployed
|
||||||
|
# - APP_ENV_FILE: full production .env file content, including APP_KEY and DB credentials
|
||||||
|
SSH_HOST: ${{ secrets.SSH_HOST }}
|
||||||
|
SSH_PORT: ${{ secrets.SSH_PORT }}
|
||||||
|
SSH_USER: ${{ secrets.SSH_USER }}
|
||||||
|
SSH_PASSWORD: ${{ secrets.SSH_PASSWORD }}
|
||||||
|
DEPLOY_PATH: ${{ secrets.DEPLOY_PATH }}
|
||||||
|
APP_ENV_FILE: ${{ secrets.APP_ENV_FILE }}
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Download release artifact
|
||||||
|
uses: actions/download-artifact@v4
|
||||||
|
with:
|
||||||
|
name: ${{ env.ARTIFACT_NAME }}
|
||||||
|
|
||||||
|
- name: Install SSH password helper
|
||||||
|
run: sudo apt-get update && sudo apt-get install -y sshpass
|
||||||
|
|
||||||
|
- name: Configure SSH known hosts
|
||||||
|
run: |
|
||||||
|
mkdir -p ~/.ssh
|
||||||
|
chmod 700 ~/.ssh
|
||||||
|
ssh-keyscan -p "${SSH_PORT:-22}" "${SSH_HOST}" >> ~/.ssh/known_hosts
|
||||||
|
|
||||||
|
- name: Create deployment environment file
|
||||||
|
if: env.APP_ENV_FILE != ''
|
||||||
|
run: printf '%s\n' "${APP_ENV_FILE}" > .env.deploy
|
||||||
|
|
||||||
|
- name: Upload release to server
|
||||||
|
run: |
|
||||||
|
SSHPASS="${SSH_PASSWORD}" sshpass -e rsync -avz -e "ssh -p ${SSH_PORT:-22}" "${RELEASE_FILE}" "${SSH_USER}@${SSH_HOST}:/tmp/${RELEASE_FILE}"
|
||||||
|
|
||||||
|
- name: Upload environment file to server
|
||||||
|
if: env.APP_ENV_FILE != ''
|
||||||
|
run: |
|
||||||
|
SSHPASS="${SSH_PASSWORD}" sshpass -e rsync -avz -e "ssh -p ${SSH_PORT:-22}" .env.deploy "${SSH_USER}@${SSH_HOST}:/tmp/.env.deploy"
|
||||||
|
|
||||||
|
- name: Extract release and finalize deployment
|
||||||
|
run: |
|
||||||
|
SSHPASS="${SSH_PASSWORD}" sshpass -e ssh -p "${SSH_PORT:-22}" "${SSH_USER}@${SSH_HOST}" << EOF
|
||||||
|
set -e
|
||||||
|
mkdir -p "${DEPLOY_PATH}"
|
||||||
|
tar -xzf "/tmp/${RELEASE_FILE}" -C "${DEPLOY_PATH}"
|
||||||
|
rm -f "/tmp/${RELEASE_FILE}"
|
||||||
|
cd "${DEPLOY_PATH}"
|
||||||
|
if [ -f /tmp/.env.deploy ]; then
|
||||||
|
mv /tmp/.env.deploy .env
|
||||||
|
chmod 600 .env
|
||||||
|
fi
|
||||||
|
php artisan storage:link || true
|
||||||
|
php artisan migrate --force
|
||||||
|
php artisan optimize
|
||||||
|
EOF
|
||||||
|
|||||||
Reference in New Issue
Block a user