mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2026-01-18 10:51:28 +00:00
246 lines
7.9 KiB
YAML
246 lines
7.9 KiB
YAML
name: CI Cache Verification
|
||
on:
|
||
push:
|
||
paths:
|
||
- '.github/workflows/cache-verify.yml'
|
||
workflow_dispatch:
|
||
jobs:
|
||
build-images:
|
||
runs-on: ubuntu-latest
|
||
strategy:
|
||
matrix:
|
||
include:
|
||
- name: backend
|
||
context: ./backend
|
||
dockerfile: ./backend/Dockerfile
|
||
target: build
|
||
- name: webapp
|
||
context: ./webapp
|
||
dockerfile: ./webapp/Dockerfile
|
||
target: build
|
||
- name: neo4j
|
||
context: ./neo4j
|
||
dockerfile: ./neo4j/Dockerfile
|
||
target: community
|
||
steps:
|
||
- uses: actions/checkout@v4
|
||
- uses: docker/setup-buildx-action@v3
|
||
- name: Build ${{ matrix.name }} image
|
||
uses: docker/build-push-action@v5
|
||
with:
|
||
context: ${{ matrix.context }}
|
||
file: ${{ matrix.dockerfile }}
|
||
target: ${{ matrix.target }}
|
||
push: false
|
||
outputs: type=docker,dest=/tmp/${{ matrix.name }}.tar
|
||
- name: Upload ${{ matrix.name }} image
|
||
uses: actions/upload-artifact@v4
|
||
with:
|
||
name: ${{ matrix.name }}-image
|
||
path: /tmp/${{ matrix.name }}.tar
|
||
|
||
cache-environment:
|
||
runs-on: ubuntu-latest
|
||
outputs:
|
||
cache-key: ${{ steps.cache-key.outputs.key }}
|
||
steps:
|
||
- name: Checkout repository
|
||
uses: actions/checkout@v4
|
||
|
||
- name: Setup Node.js
|
||
uses: actions/setup-node@v4
|
||
with:
|
||
node-version: '20'
|
||
|
||
- name: Compute cache key (unique per run)
|
||
id: cache-key
|
||
run: |
|
||
BACKEND_HASH=$(sha256sum backend/yarn.lock | cut -d' ' -f1)
|
||
WEBAPP_HASH=$(sha256sum webapp/yarn.lock | cut -d' ' -f1)
|
||
CYPRESS_HASH=$(sha256sum cypress/yarn.lock | cut -d' ' -f1 2>/dev/null || echo "none")
|
||
KEY="ci-all-cache-${{ runner.os }}-${BACKEND_HASH}-${WEBAPP_HASH}-${CYPRESS_HASH}-run${{ github.run_id }}"
|
||
echo "key=$KEY"
|
||
echo "key=$KEY" >> $GITHUB_OUTPUT
|
||
|
||
- name: Restore CI cache
|
||
id: restore-cache
|
||
uses: actions/cache/restore@v4
|
||
with:
|
||
path: |
|
||
backend/node_modules
|
||
webapp/node_modules
|
||
cypress/node_modules
|
||
~/.cache/Cypress
|
||
/opt/cucumber-json-formatter
|
||
key: ${{ steps.cache-key.outputs.key }}
|
||
restore-keys: |
|
||
ci-all-cache-${{ runner.os }}-
|
||
|
||
- name: Install backend dependencies if needed
|
||
run: |
|
||
if [ ! -d backend/node_modules ] || [ -z "$(ls -A backend/node_modules)" ]; then
|
||
cd backend && yarn install
|
||
fi
|
||
|
||
- name: Install webapp dependencies if needed
|
||
run: |
|
||
if [ ! -d webapp/node_modules ] || [ -z "$(ls -A webapp/node_modules)" ]; then
|
||
cd webapp && yarn install
|
||
fi
|
||
|
||
- name: Install Cypress dependencies locally
|
||
run: |
|
||
if [ ! -d cypress/node_modules ] || [ -z "$(ls -A cypress/node_modules)" ]; then
|
||
cd cypress && yarn install
|
||
fi
|
||
|
||
- name: Install cucumber-json-formatter if missing
|
||
run: |
|
||
if [ ! -f /opt/cucumber-json-formatter ]; then
|
||
wget --no-verbose -O /opt/cucumber-json-formatter "https://github.com/cucumber/json-formatter/releases/download/v19.0.0/cucumber-json-formatter-linux-386"
|
||
chmod +x /opt/cucumber-json-formatter
|
||
fi
|
||
|
||
- name: Save updated CI cache
|
||
uses: actions/cache/save@v4
|
||
if: always()
|
||
with:
|
||
path: |
|
||
backend/node_modules
|
||
webapp/node_modules
|
||
cypress/node_modules
|
||
~/.cache/Cypress
|
||
/opt/cucumber-json-formatter
|
||
key: ${{ steps.cache-key.outputs.key }}
|
||
|
||
verify-environment:
|
||
runs-on: ubuntu-latest
|
||
needs: [cache-environment]
|
||
steps:
|
||
- name: Checkout repository
|
||
uses: actions/checkout@v4
|
||
|
||
- name: Restore CI cache
|
||
uses: actions/cache/restore@v4
|
||
with:
|
||
path: |
|
||
backend/node_modules
|
||
webapp/node_modules
|
||
cypress/node_modules
|
||
~/.cache/Cypress
|
||
/opt/cucumber-json-formatter
|
||
key: ${{ needs.cache-environment.outputs.cache-key }}
|
||
restore-keys: |
|
||
ci-all-cache-${{ runner.os }}-
|
||
|
||
# --- Checks ---
|
||
- name: Check backend/node_modules
|
||
run: |
|
||
[ -d backend/node_modules ] && [ -n "$(ls -A backend/node_modules)" ] || (echo "❌ backend/node_modules missing" && exit 1)
|
||
|
||
- name: Check webapp/node_modules
|
||
run: |
|
||
[ -d webapp/node_modules ] && [ -n "$(ls -A webapp/node_modules)" ] || (echo "❌ webapp/node_modules missing" && exit 1)
|
||
|
||
- name: Check cypress/node_modules
|
||
run: |
|
||
[ -d cypress/node_modules ] && [ -n "$(ls -A cypress/node_modules)" ] || (echo "❌ cypress/node_modules missing" && exit 1)
|
||
|
||
- name: Check Cypress binary cache
|
||
run: |
|
||
[ -d ~/.cache/Cypress ] || (echo "❌ Cypress binary cache missing" && exit 1)
|
||
|
||
- name: Check Cypress CLI (from local install)
|
||
run: |
|
||
cd cypress
|
||
npx --yes cypress --version
|
||
npx --yes cypress verify
|
||
|
||
- name: Check cucumber-json-formatter
|
||
run: |
|
||
[ -x /opt/cucumber-json-formatter ] && /opt/cucumber-json-formatter --help || (echo "❌ Formatter missing" && exit 1)
|
||
|
||
# --- Summary ---
|
||
- name: CI Cache Health Summary
|
||
run: |
|
||
echo "📦 CI Cache Health Summary:"
|
||
echo
|
||
|
||
check() {
|
||
if [ -d "$1" ] && [ -n "$(ls -A $1)" ]; then
|
||
echo "✅ $1 OK"
|
||
else
|
||
echo "❌ $1 missing or empty"
|
||
fi
|
||
}
|
||
|
||
check backend/node_modules
|
||
check webapp/node_modules
|
||
check cypress/node_modules
|
||
[ -d ~/.cache/Cypress ] && echo "✅ Cypress binary cache OK" || echo "❌ Cypress binary cache missing"
|
||
[ -x /opt/cucumber-json-formatter ] && echo "✅ Formatter executable OK" || echo "❌ Formatter missing"
|
||
|
||
echo
|
||
|
||
if [ -d backend/node_modules ] && [ -d webapp/node_modules ] && \
|
||
[ -d cypress/node_modules ] && [ -d ~/.cache/Cypress ] && \
|
||
[ -x /opt/cucumber-json-formatter ]; then
|
||
echo "🎉 ✅ All dependencies loaded from cache – ready to test"
|
||
else
|
||
echo "⚠️ Partial cache – some installs might have been required"
|
||
fi
|
||
|
||
|
||
consolidate-environment:
|
||
runs-on: ubuntu-latest
|
||
needs: [build-images, cache-environment]
|
||
steps:
|
||
|
||
# install images
|
||
- name: Download Docker image artifacts
|
||
uses: actions/download-artifact@v4
|
||
with:
|
||
path: /tmp
|
||
|
||
- name: Load Docker images
|
||
run: |
|
||
docker load < /tmp/backend-image/backend.tar
|
||
docker load < /tmp/webapp-image/webapp.tar
|
||
docker load < /tmp/neo4j-image/neo4j.tar
|
||
|
||
- name: Setup .env files
|
||
run: |
|
||
cp webapp/.env.template webapp/.env || touch webapp/.env
|
||
cp backend/.env.test_e2e backend/.env || touch backend/.env
|
||
|
||
# load environment
|
||
- name: Checkout repository
|
||
uses: actions/checkout@v4
|
||
|
||
- name: Restore full CI cache
|
||
id: restore-cache
|
||
uses: actions/cache@v4
|
||
with:
|
||
path: |
|
||
backend/node_modules
|
||
webapp/node_modules
|
||
~/.cache/Cypress
|
||
/opt/cucumber-json-formatter
|
||
key: ${{ needs.cache-environment.outputs.cache-key }}
|
||
restore-keys: |
|
||
ci-all-cache-${{ runner.os }}-
|
||
ci-all-cache-
|
||
|
||
# start full system
|
||
- name: Start system
|
||
run: |
|
||
docker compose -f docker-compose.yml -f docker-compose.test.yml up --detach
|
||
|
||
- name: Wait for webapp
|
||
run: |
|
||
echo "Waiting for http://localhost:3000..."
|
||
for i in {1..15}; do
|
||
curl -sf http://localhost:3000 && echo "✅ Ready" && exit 0
|
||
echo "$i..." && sleep 2
|
||
done
|
||
echo "❌ Webapp did not respond in time" && exit 1 |