Skip to content

Add GitHub Actions CI/CD pipeline with automated deployment - #2

Open
guissepm wants to merge 3 commits into
masterfrom
claude/blood-bank-deploy-3k1du8
Open

Add GitHub Actions CI/CD pipeline with automated deployment#2
guissepm wants to merge 3 commits into
masterfrom
claude/blood-bank-deploy-3k1du8

Conversation

@guissepm

Copy link
Copy Markdown
Owner

Summary

This PR introduces a complete GitHub Actions CI/CD pipeline for automated testing and production deployment. The pipeline consists of two workflows that ensure code quality before releasing to production.

Key Changes

  • CI Workflow (.github/workflows/ci.yml): Runs on every push and pull request

    • Tests PHP 7.2 and 7.3 compatibility in parallel
    • Spins up a MySQL 5.7 service for integration testing
    • Runs PHPUnit test suite against a real database
    • Compiles and validates front-end assets with Node.js
    • Caches dependencies (Composer and npm) for faster builds
  • Deploy Workflow (.github/workflows/deploy.yml): Runs automatically after CI succeeds on master (or manually via workflow dispatch)

    • Builds production-optimized PHP and Node.js assets
    • Creates a compressed deployment archive excluding unnecessary files
    • Transfers archive to production server via SSH
    • Implements zero-downtime deployment using timestamped releases and atomic symlink switching
    • Runs database migrations and Laravel cache warming
    • Automatically prunes old releases, keeping the 5 most recent
    • Reloads PHP-FPM to serve new code
  • Deployment Documentation (DEPLOYMENT.md): Comprehensive guide covering

    • Workflow overview and triggers
    • Step-by-step deployment process explanation
    • Required GitHub secrets configuration
    • One-time server setup instructions
    • Manual and automatic deployment procedures

Notable Implementation Details

  • Deploy only runs when CI passes, preventing broken code from reaching production
  • Concurrency control prevents simultaneous deployments
  • Shared persistent state (.env and storage/) survives across deployments via symlinks
  • SSH-based deployment with configurable host, user, port, and path via GitHub secrets
  • Graceful error handling with set -euo pipefail in deployment scripts
  • PHP-FPM reload is optional (silently skipped if not permitted)

https://claude.ai/code/session_01Tfc1nqw5KBG6fJdKbJhyc1

claude added 2 commits July 11, 2026 13:00
CI workflow: install Composer/Node deps, run migrations against a MySQL
service, execute PHPUnit on PHP 7.2/7.3, and compile production assets.

Deploy workflow: on successful CI on master (or manual dispatch), build a
production bundle and release it over SSH with timestamped, symlink-based
zero-downtime releases, migrations, config/route caching, and old-release
pruning.

Includes DEPLOYMENT.md documenting required secrets and server layout.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Tfc1nqw5KBG6fJdKbJhyc1
package:discover failed with 'Undefined index: name' because Laravel 5.6's
PackageManifest can't read Composer 2's installed.json format; pin composer:v1.

The assets build failed because node-sass 4.9.4 has no prebuilt binary for
Node 14 and the source build errors; drop to Node 10 which has a prebuilt.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Tfc1nqw5KBG6fJdKbJhyc1

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0b46f58d7c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread .github/workflows/deploy.yml Outdated
cd "$RELEASE"
php artisan migrate --force
php artisan config:cache
php artisan route:cache

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Do not cache routes while closure routes remain

This repo still has the default closure route in routes/api.php:16; in Laravel 5.6, php artisan route:cache fails when any route is a Closure, and because this SSH script is running under set -euo pipefail, every production deploy will abort here before the current symlink is switched. Convert/remove the closure route or skip route caching until the route table is cacheable.

Useful? React with 👍 / 👎.

Comment on lines +24 to +25
- name: Checkout
uses: actions/checkout@v4

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Pin deploy checkout to the tested CI SHA

For workflow_run, GitHub documents GITHUB_SHA as the last commit on the default branch (https://docs.github.com/en/actions/reference/workflows-and-actions/events-that-trigger-workflows#workflow_run), so this default checkout is not tied to github.event.workflow_run.head_sha. If a second push reaches master before an older CI run finishes, the older successful run can deploy the newer, unverified commit; set the checkout ref to the triggering run's head_sha for workflow-run deploys.

Useful? React with 👍 / 👎.

Address two review findings on the deploy workflow:

- workflow_run checks out the default-branch tip, which can be a newer,
  unverified commit than the one CI validated. Pin the checkout ref to
  github.event.workflow_run.head_sha (falling back to github.sha for
  manual dispatch) so only the tested commit is deployed.

- Laravel 5.6's route:cache aborts when any route uses a Closure (the
  default routes/api.php /user route does), which under set -euo pipefail
  would fail every deploy before the release symlink is switched. Fall
  back to route:clear so a non-cacheable route table can't break deploys.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Tfc1nqw5KBG6fJdKbJhyc1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants