diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml-bak similarity index 100% rename from .gitea/workflows/ci.yml rename to .gitea/workflows/ci.yml-bak diff --git a/.gitea/workflows/deploy.yaml b/.gitea/workflows/deploy.yaml new file mode 100644 index 0000000..c4b5ee8 --- /dev/null +++ b/.gitea/workflows/deploy.yaml @@ -0,0 +1,126 @@ +name: Deploy to Production + +on: + push: + tags: + - 'v*' + +jobs: + test: + runs-on: splendid-bear + + services: + postgres: + image: postgres:18-alpine + env: + POSTGRES_USER: mineseeker_test + POSTGRES_PASSWORD: test_password + POSTGRES_DB: mineseeker_test + options: >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 5 + ports: + - 5432:5432 + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Setup PHP 8.3 + uses: shivammathur/setup-php@v2 + with: + php-version: '8.3' + extensions: pdo_pgsql, gd, intl, zip, sodium + coverage: none + tools: composer:v2 + + - name: Install PHP dependencies + run: composer install --prefer-dist --no-progress --no-interaction + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: '20' + + - name: Install Node dependencies + run: npm ci + + - name: Build assets + run: npm run build + + - name: Create .env.test file + run: | + cat > .env.test << 'ENVEOF' + APP_ENV=test + APP_SECRET=test-secret-key-for-ci-testing-only + DATABASE_URL="postgresql://mineseeker_test:test_password@localhost:5432/mineseeker_test?serverVersion=18&charset=utf8" + KERNEL_CLASS='App\Kernel' + SYMFONY_DEPRECATIONS_HELPER=999999 + ENVEOF + + - name: Setup test database + run: make test-db-setup + + - name: Run PHPUnit tests + run: vendor/bin/phpunit --testdox --colors=always --stop-on-failure + + deploy: + needs: test + runs-on: splendid-bear + steps: + - name: Checkout tag + env: + GITEA_TOKEN: ${{ gitea.token }} + run: | + set -e + export HOME=/tmp + git config --global credential.helper '!f() { echo "username=oauth2"; echo "password=$GITEA_TOKEN"; }; f' + git config --global --add safe.directory "${{ vars.PROD_APP_DIR }}" + cd "${{ vars.PROD_APP_DIR }}" + git remote set-url origin "${{ gitea.server_url }}/${{ gitea.repository }}.git" + git fetch --tags --force + git checkout "${{ gitea.ref_name }}" + + - name: Write .env + env: + PROD_ENV_FILE: ${{ secrets.PROD_ENV_FILE }} + run: | + printf '%s' "$PROD_ENV_FILE" > "${{ vars.PROD_APP_DIR }}/.env" + + - name: Build image + run: | + cd "${{ vars.PROD_APP_DIR }}" + docker compose build + + - name: Run database migrations + run: | + cd "${{ vars.PROD_APP_DIR }}" + docker compose run --rm app php bin/console doctrine:migrations:migrate --no-interaction + + - name: Clear cache + run: | + cd "${{ vars.PROD_APP_DIR }}" + docker compose run --rm app php bin/console cache:clear --env=prod + + - name: Start services + run: | + cd "${{ vars.PROD_APP_DIR }}" + docker compose up -d + + - name: Health check + run: | + sleep 5 + curl -f http://localhost:10080/ || exit 1 + + - name: Notify deployment success + if: success() + run: | + echo "✅ Deployment successful for tag ${{ gitea.ref_name }}" + + - name: Notify deployment failure + if: failure() + run: | + echo "❌ Deployment failed for tag ${{ gitea.ref_name }}" + exit 1 diff --git a/.gitea/workflows/deploy.yml b/.gitea/workflows/deploy.yml index e2bc250..400b87c 100644 --- a/.gitea/workflows/deploy.yml +++ b/.gitea/workflows/deploy.yml @@ -6,68 +6,7 @@ on: - 'v*' jobs: - test: - runs-on: splendid-bear - - services: - postgres: - image: postgres:18-alpine - env: - POSTGRES_USER: mineseeker_test - POSTGRES_PASSWORD: test_password - POSTGRES_DB: mineseeker_test - options: >- - --health-cmd pg_isready - --health-interval 10s - --health-timeout 5s - --health-retries 5 - ports: - - 5432:5432 - - steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: Setup PHP 8.3 - uses: shivammathur/setup-php@v2 - with: - php-version: '8.3' - extensions: pdo_pgsql, gd, intl, zip, sodium - coverage: none - tools: composer:v2 - - - name: Install PHP dependencies - run: composer install --prefer-dist --no-progress --no-interaction - - - name: Setup Node.js - uses: actions/setup-node@v4 - with: - node-version: '20' - - - name: Install Node dependencies - run: npm ci - - - name: Build assets - run: npm run build - - - name: Create .env.test file - run: | - cat > .env.test << 'ENVEOF' - APP_ENV=test - APP_SECRET=test-secret-key-for-ci-testing-only - DATABASE_URL="postgresql://mineseeker_test:test_password@localhost:5432/mineseeker_test?serverVersion=18&charset=utf8" - KERNEL_CLASS='App\Kernel' - SYMFONY_DEPRECATIONS_HELPER=999999 - ENVEOF - - - name: Setup test database - run: make test-db-setup - - - name: Run PHPUnit tests - run: vendor/bin/phpunit --testdox --colors=always --stop-on-failure - deploy: - needs: test runs-on: splendid-bear steps: - name: Checkout tag @@ -94,33 +33,7 @@ jobs: cd "${{ vars.PROD_APP_DIR }}" docker compose build - - name: Run database migrations - run: | - cd "${{ vars.PROD_APP_DIR }}" - docker compose run --rm app php bin/console doctrine:migrations:migrate --no-interaction - - - name: Clear cache - run: | - cd "${{ vars.PROD_APP_DIR }}" - docker compose run --rm app php bin/console cache:clear --env=prod - - name: Start services run: | cd "${{ vars.PROD_APP_DIR }}" docker compose up -d - - - name: Health check - run: | - sleep 5 - curl -f http://localhost:10080/ || exit 1 - - - name: Notify deployment success - if: success() - run: | - echo "✅ Deployment successful for tag ${{ gitea.ref_name }}" - - - name: Notify deployment failure - if: failure() - run: | - echo "❌ Deployment failed for tag ${{ gitea.ref_name }}" - exit 1 diff --git a/README.md b/README.md index 8e85640..052a93b 100644 --- a/README.md +++ b/README.md @@ -340,7 +340,7 @@ vendor/bin/phpunit --testdox **Automated testing** runs on every push/pull request: ```yaml -# .gitea/workflows/ci.yml +# .gitea/workflows/ci.yml-bak ✓ PHP 8.3 setup with all extensions ✓ PostgreSQL 18 service container ✓ Composer and npm dependency installation