Refactor CI workflows to streamline dependency installation and improve cache handling. Removed redundant install job, fixed pnpm store permissions, and optimized production dependency preparation in Docker build workflow.

This commit is contained in:
dal 2025-08-19 13:58:18 -06:00
parent f5f4dc7fca
commit 1ef508bb32
No known key found for this signature in database
GPG Key ID: 16F4B0E1E9F61122
2 changed files with 42 additions and 107 deletions

View File

@ -12,16 +12,14 @@ env:
CI: true CI: true
jobs: jobs:
# First, install dependencies once and cache them # Build job - runs in parallel
install: build:
name: Install Dependencies name: Build
runs-on: blacksmith-2vcpu-ubuntu-2404 runs-on: blacksmith-4vcpu-ubuntu-2404
timeout-minutes: 5 timeout-minutes: 10
steps: steps:
- name: Checkout code - name: Checkout code
uses: actions/checkout@v4 uses: actions/checkout@v4
with:
fetch-depth: 2
- name: Install pnpm - name: Install pnpm
uses: pnpm/action-setup@v2 uses: pnpm/action-setup@v2
@ -38,57 +36,14 @@ jobs:
run: | run: |
STORE_PATH=$(pnpm store path --silent) STORE_PATH=$(pnpm store path --silent)
if [ -d "$STORE_PATH" ]; then if [ -d "$STORE_PATH" ]; then
# Clear corrupted cache entries
find "$STORE_PATH" -type f ! -perm -u+r -delete 2>/dev/null || true
find "$STORE_PATH" -type d ! -perm -u+rx -delete 2>/dev/null || true
# Fix permissions on remaining files
sudo chown -R $(whoami):$(whoami) "$STORE_PATH" || true sudo chown -R $(whoami):$(whoami) "$STORE_PATH" || true
chmod -R u+rw "$STORE_PATH" || true chmod -R u+rw "$STORE_PATH" || true
fi fi
- name: Check if lockfile changed
id: lockfile-check
run: |
if git diff HEAD~1 HEAD --name-only | grep -q "pnpm-lock.yaml"; then
echo "changed=true" >> $GITHUB_OUTPUT
else
echo "changed=false" >> $GITHUB_OUTPUT
fi
- name: Fetch dependencies (if lockfile changed)
if: steps.lockfile-check.outputs.changed == 'true'
run: pnpm fetch --frozen-lockfile
- name: Install dependencies
run: pnpm install --frozen-lockfile --prefer-offline
# Build job - runs in parallel
build:
name: Build
needs: install
runs-on: blacksmith-4vcpu-ubuntu-2404
timeout-minutes: 10
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install pnpm
uses: pnpm/action-setup@v2
with:
version: 9.15.0
- name: Setup Node.js
uses: useblacksmith/setup-node@v5
with:
node-version: 22
- name: Get pnpm store directory
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
- name: Mount pnpm store sticky disk
uses: useblacksmith/stickydisk@v1
with:
key: ${{ github.repository }}-pnpm-store
path: ${{ env.STORE_PATH }}
- name: Mount Turbo cache sticky disk - name: Mount Turbo cache sticky disk
uses: useblacksmith/stickydisk@v1 uses: useblacksmith/stickydisk@v1
with: with:
@ -96,9 +51,7 @@ jobs:
path: ./.turbo path: ./.turbo
- name: Install dependencies - name: Install dependencies
run: | run: pnpm install --frozen-lockfile --prefer-offline
rm -rf node_modules
pnpm install --frozen-lockfile --prefer-offline
- name: Build all packages (excluding web) - name: Build all packages (excluding web)
run: pnpm build --filter='!@buster-app/web' run: pnpm build --filter='!@buster-app/web'
@ -108,7 +61,6 @@ jobs:
# Lint job - runs in parallel # Lint job - runs in parallel
lint: lint:
name: Lint name: Lint
needs: install
runs-on: blacksmith-2vcpu-ubuntu-2404 runs-on: blacksmith-2vcpu-ubuntu-2404
timeout-minutes: 5 timeout-minutes: 5
steps: steps:
@ -124,17 +76,19 @@ jobs:
uses: useblacksmith/setup-node@v5 uses: useblacksmith/setup-node@v5
with: with:
node-version: 22 node-version: 22
cache: 'pnpm'
- name: Get pnpm store directory
shell: bash - name: Fix pnpm store permissions
run: | run: |
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV STORE_PATH=$(pnpm store path --silent)
if [ -d "$STORE_PATH" ]; then
- name: Mount pnpm store sticky disk # Clear corrupted cache entries
uses: useblacksmith/stickydisk@v1 find "$STORE_PATH" -type f ! -perm -u+r -delete 2>/dev/null || true
with: find "$STORE_PATH" -type d ! -perm -u+rx -delete 2>/dev/null || true
key: ${{ github.repository }}-pnpm-store # Fix permissions on remaining files
path: ${{ env.STORE_PATH }} sudo chown -R $(whoami):$(whoami) "$STORE_PATH" || true
chmod -R u+rw "$STORE_PATH" || true
fi
- name: Mount Turbo cache sticky disk - name: Mount Turbo cache sticky disk
uses: useblacksmith/stickydisk@v1 uses: useblacksmith/stickydisk@v1
@ -143,9 +97,7 @@ jobs:
path: ./.turbo path: ./.turbo
- name: Install dependencies - name: Install dependencies
run: | run: pnpm install --frozen-lockfile --prefer-offline
rm -rf node_modules
pnpm install --frozen-lockfile --prefer-offline
- name: Lint all packages (excluding web) - name: Lint all packages (excluding web)
run: pnpm lint --filter='!@buster-app/web' run: pnpm lint --filter='!@buster-app/web'
@ -153,7 +105,6 @@ jobs:
# Test job - runs in parallel # Test job - runs in parallel
test: test:
name: Test name: Test
needs: install
runs-on: blacksmith-4vcpu-ubuntu-2404 runs-on: blacksmith-4vcpu-ubuntu-2404
timeout-minutes: 15 timeout-minutes: 15
steps: steps:
@ -169,17 +120,19 @@ jobs:
uses: useblacksmith/setup-node@v5 uses: useblacksmith/setup-node@v5
with: with:
node-version: 22 node-version: 22
cache: 'pnpm'
- name: Get pnpm store directory
shell: bash - name: Fix pnpm store permissions
run: | run: |
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV STORE_PATH=$(pnpm store path --silent)
if [ -d "$STORE_PATH" ]; then
- name: Mount pnpm store sticky disk # Clear corrupted cache entries
uses: useblacksmith/stickydisk@v1 find "$STORE_PATH" -type f ! -perm -u+r -delete 2>/dev/null || true
with: find "$STORE_PATH" -type d ! -perm -u+rx -delete 2>/dev/null || true
key: ${{ github.repository }}-pnpm-store # Fix permissions on remaining files
path: ${{ env.STORE_PATH }} sudo chown -R $(whoami):$(whoami) "$STORE_PATH" || true
chmod -R u+rw "$STORE_PATH" || true
fi
- name: Mount Turbo cache sticky disk - name: Mount Turbo cache sticky disk
uses: useblacksmith/stickydisk@v1 uses: useblacksmith/stickydisk@v1
@ -188,9 +141,7 @@ jobs:
path: ./.turbo path: ./.turbo
- name: Install dependencies - name: Install dependencies
run: | run: pnpm install --frozen-lockfile --prefer-offline
rm -rf node_modules
pnpm install --frozen-lockfile --prefer-offline
- name: Run all unit tests (excluding web) - name: Run all unit tests (excluding web)
run: pnpm test:unit --filter='!@buster-app/web' run: pnpm test:unit --filter='!@buster-app/web'

View File

@ -88,35 +88,19 @@ jobs:
ls -la dist/ ls -la dist/
cd ../.. cd ../..
- name: Mount production deps sticky disk
uses: useblacksmith/stickydisk@v1
with:
key: ${{ github.repository }}-prod-deps-${{ github.ref_name }}
path: /tmp/prod-deps-cache
- name: Prepare production dependencies - name: Prepare production dependencies
run: | run: |
echo "🧹 Preparing production-only dependencies..." echo "🧹 Preparing production-only dependencies..."
# Use cached directory if it exists, otherwise create new # Create a temporary directory for production deps
if [ -d "/tmp/prod-deps-cache/node_modules" ]; then mkdir -p /tmp/prod-deps/apps/server
echo "Using cached production dependencies" cp package.json pnpm-lock.yaml pnpm-workspace.yaml /tmp/prod-deps/
mkdir -p /tmp/prod-deps cp -r packages /tmp/prod-deps/
cp -r /tmp/prod-deps-cache/* /tmp/prod-deps/ 2>/dev/null || true cp apps/server/package.json /tmp/prod-deps/apps/server/
else
echo "Building fresh production dependencies"
mkdir -p /tmp/prod-deps/apps/server
cp package.json pnpm-lock.yaml pnpm-workspace.yaml /tmp/prod-deps/
cp -r packages /tmp/prod-deps/
cp apps/server/package.json /tmp/prod-deps/apps/server/
fi
# Install/update production dependencies # Install production dependencies only
cd /tmp/prod-deps cd /tmp/prod-deps
pnpm install --frozen-lockfile --prod --ignore-scripts --no-optional pnpm install --frozen-lockfile --prod --ignore-scripts --no-optional
# Update cache
cp -r node_modules /tmp/prod-deps-cache/
# Copy back to workspace # Copy back to workspace
cd - cd -
mkdir -p docker-context mkdir -p docker-context