128 lines
3.7 KiB
YAML
128 lines
3.7 KiB
YAML
name: CI
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- main
|
|
- develop
|
|
|
|
pull_request:
|
|
branches:
|
|
- main
|
|
- develop
|
|
jobs:
|
|
test:
|
|
name: 🧪 Tests Laravel
|
|
runs-on: ubuntu-latest
|
|
container: shivammathur/node:php-8.4-24.04-amd64
|
|
env:
|
|
DB_CONNECTION: sqlite
|
|
DB_DATABASE: database/database.sqlite
|
|
COMPOSER_MAX_PARALLEL_HTTP: 4
|
|
steps:
|
|
- name: 📥 Checkout
|
|
uses: actions/checkout@v4
|
|
|
|
- name: 🐘 Setup PHP
|
|
uses: shivammathur/setup-php@v2
|
|
env:
|
|
fail-fast: true
|
|
with:
|
|
php-version: '8.4'
|
|
extensions: bcmath,ctype,curl,dom,fileinfo,intl,mbstring,openssl,pdo,tokenizer,xml,zip
|
|
coverage: none
|
|
|
|
- name: Configure Composer authentication
|
|
env:
|
|
COMPOSER_GITHUB_TOKEN: ${{ secrets.COMPOSER_GITHUB_TOKEN }}
|
|
run: |
|
|
if [ -n "$COMPOSER_GITHUB_TOKEN" ]; then
|
|
composer config \
|
|
--global \
|
|
--auth github-oauth.github.com \
|
|
"$COMPOSER_GITHUB_TOKEN"
|
|
fi
|
|
|
|
- name: Get Composer cache directory
|
|
id: composer-cache
|
|
run: echo "dir=$(composer config cache-files-dir)" >> "$GITHUB_OUTPUT"
|
|
|
|
- name: Cache Composer
|
|
uses: actions/cache@v4
|
|
with:
|
|
path: ${{ steps.composer-cache.outputs.dir }}
|
|
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
|
|
restore-keys: ${{ runner.os }}-composer-
|
|
|
|
- name: Install Composer dependencies
|
|
run: |
|
|
attempt=1
|
|
|
|
until composer install \
|
|
--no-interaction \
|
|
--prefer-dist \
|
|
--no-progress; do
|
|
if [ "$attempt" -ge 4 ]; then
|
|
exit 1
|
|
fi
|
|
|
|
delay=$((attempt * 15))
|
|
echo "Composer install failed (attempt $attempt/4), retrying in ${delay}s..."
|
|
sleep "$delay"
|
|
attempt=$((attempt + 1))
|
|
done
|
|
|
|
- name: ⚙️ Prepare Laravel
|
|
run: |
|
|
cp .env.example .env
|
|
php artisan key:generate
|
|
touch database/database.sqlite
|
|
php artisan migrate --force
|
|
|
|
|
|
- name: 🧪 Run PHPUnit
|
|
run: |
|
|
php artisan test
|
|
|
|
|
|
|
|
docker:
|
|
name: 🐳 Build & Push Images
|
|
needs: test
|
|
if: ${{ github.ref == 'refs/heads/main' }}
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: 📥 Checkout
|
|
uses: actions/checkout@v4
|
|
|
|
- name: 🔐 Login Registry Gitea
|
|
run: |
|
|
docker login git.leonmorival.xyz \
|
|
-u "${{ secrets.REGISTRY_USER }}" \
|
|
-p "${{ secrets.REGISTRY_PASSWORD }}"
|
|
|
|
- name: 🏗️ Build image
|
|
env:
|
|
COMPOSER_GITHUB_TOKEN: ${{ secrets.COMPOSER_GITHUB_TOKEN }}
|
|
run: |
|
|
docker build \
|
|
--secret id=composer_github_token,env=COMPOSER_GITHUB_TOKEN \
|
|
-t git.leonmorival.xyz/leonm/daily-meal-api:latest \
|
|
-t git.leonmorival.xyz/leonm/daily-meal-api:${{ github.sha }} \
|
|
.
|
|
|
|
- name: 🏗️ Build database backup image
|
|
run: |
|
|
docker build \
|
|
-f docker/database-backup/Dockerfile \
|
|
-t git.leonmorival.xyz/leonm/daily-meal-postgres-tools:latest \
|
|
-t git.leonmorival.xyz/leonm/daily-meal-postgres-tools:${{ github.sha }} \
|
|
docker/database-backup
|
|
|
|
- name: 📤 Push images
|
|
run: |
|
|
docker push git.leonmorival.xyz/leonm/daily-meal-api:latest
|
|
docker push git.leonmorival.xyz/leonm/daily-meal-api:${{ github.sha }}
|
|
docker push git.leonmorival.xyz/leonm/daily-meal-postgres-tools:latest
|
|
docker push git.leonmorival.xyz/leonm/daily-meal-postgres-tools:${{ github.sha }}
|