webamp/.github/workflows/ci.yml
2025-07-06 17:17:55 -07:00

229 lines
6.9 KiB
YAML

name: CI
on:
push:
pull_request:
# Only run on pull requests that change relevant files
paths-ignore:
- "**.md"
- "docs/**"
- ".gitignore"
- "LICENSE.txt"
jobs:
# Fast job to install dependencies and cache them for other jobs
setup:
runs-on: ubuntu-latest
outputs:
cache-key: ${{ steps.cache-key.outputs.key }}
steps:
- uses: actions/checkout@v4
- name: Install pnpm
uses: pnpm/action-setup@v2
with:
version: 9.12.0
- name: Generate cache key
id: cache-key
run: echo "key=node-modules-${{ hashFiles('**/pnpm-lock.yaml') }}" >> $GITHUB_OUTPUT
- name: Use Node.js 20.x
uses: actions/setup-node@v4
with:
node-version: 20.x
cache: "pnpm"
- name: Install Dependencies
run: pnpm install --frozen-lockfile
# Build job - Vite build for demo site
build:
runs-on: ubuntu-latest
needs: setup
steps:
- uses: actions/checkout@v4
- name: Install pnpm
uses: pnpm/action-setup@v2
with:
version: 9.12.0
- name: Use Node.js 20.x
uses: actions/setup-node@v4
with:
node-version: 20.x
cache: "pnpm"
- name: Install Dependencies
run: pnpm install --frozen-lockfile
- name: Build Vite Demo
run: |
# Set CI environment variable for optimized builds
export CI=true
pnpm --filter ani-cursor build
pnpm --filter winamp-eqf build
pnpm --filter webamp build
env:
NODE_ENV: production
- name: Cache build artifacts
uses: actions/cache@v4
with:
path: |
packages/*/built
packages/*/dist
key: build-artifacts-${{ github.sha }}
# Build Library job - Rollup build for library bundles
build-library:
runs-on: ubuntu-latest
needs: setup
steps:
- uses: actions/checkout@v4
- name: Install pnpm
uses: pnpm/action-setup@v2
with:
version: 9.12.0
- name: Use Node.js 20.x
uses: actions/setup-node@v4
with:
node-version: 20.x
cache: "pnpm"
- name: Install Dependencies
run: pnpm install --frozen-lockfile
- name: Build Library Bundles
run: |
# Set CI environment variable for optimized builds
export CI=true
pnpm --filter ani-cursor build
pnpm --filter winamp-eqf build
pnpm --filter webamp build-library
env:
NODE_ENV: production
- name: Cache library artifacts
uses: actions/cache@v4
with:
path: |
packages/webamp/built/*.js
packages/webamp/built/*.mjs
packages/webamp/built/*.map
packages/webamp/built/*.html
key: library-artifacts-${{ github.sha }}
# Lint job - runs in parallel
lint:
runs-on: ubuntu-latest
needs: setup
steps:
- uses: actions/checkout@v4
- name: Install pnpm
uses: pnpm/action-setup@v2
with:
version: 9.12.0
- name: Use Node.js 20.x
uses: actions/setup-node@v4
with:
node-version: 20.x
cache: "pnpm"
- name: Install Dependencies
run: pnpm install --frozen-lockfile
- name: Lint
run: |
pnpm lint
pnpm type-check
# Test job - runs in parallel
test:
runs-on: ubuntu-latest
needs: setup
steps:
- uses: actions/checkout@v4
- name: Install pnpm
uses: pnpm/action-setup@v2
with:
version: 9.12.0
- name: Use Node.js 20.x
uses: actions/setup-node@v4
with:
node-version: 20.x
cache: "pnpm"
- name: Install Dependencies
run: pnpm install --frozen-lockfile
- name: Run Unit Tests
run: |
touch packages/skin-database/config.js
# Run tests with optimizations for CI
export CI=true
pnpm test -- --maxWorkers=2
pnpm --filter webamp test -- --maxWorkers=2
env:
NODE_ENV: test
# - name: Run Integration Tests
# run: yarn workspace webamp integration-tests
# env:
# CI: true
# - name: Upload Screenshot Diffs
# if: failure()
# uses: actions/upload-artifact@v4
# with:
# name: image_diffs
# path: packages/webamp/js/__tests__/__image_snapshots__/__diff_output__/
# - name: Generate New Screenshots
# if: failure()
# run: |
# yarn workspace webamp integration-tests -u
# - name: Upload New Screenshots
# if: failure()
# uses: actions/upload-artifact@v4
# with:
# name: new_images
# path: packages/webamp/js/__tests__/__image_snapshots__/
main-release:
name: Publish to NPM
runs-on: ubuntu-latest
if: github.event_name == 'push' && github.repository == 'captbaritone/webamp'
needs: [build, build-library, lint, test]
steps:
- uses: actions/checkout@v4
- name: Install pnpm
uses: pnpm/action-setup@v2
with:
version: 9.12.0
- uses: actions/setup-node@v4
with:
node-version: 20.x
registry-url: https://registry.npmjs.org/
cache: "pnpm"
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Restore build artifacts
uses: actions/cache@v4
with:
path: |
packages/*/built
packages/*/dist
key: build-artifacts-${{ github.sha }}
fail-on-cache-miss: true
- name: Restore library artifacts
uses: actions/cache@v4
with:
path: |
packages/webamp/built/*.js
packages/webamp/built/*.mjs
packages/webamp/built/*.map
packages/webamp/built/*.html
key: library-artifacts-${{ github.sha }}
fail-on-cache-miss: true
- name: Set version
if: github.ref == 'refs/heads/master'
working-directory: ./packages/webamp
run: |
echo "Setting version to 0.0.0-next-${RELEASE_COMMIT_SHA::7}"
npm version 0.0.0-next-${RELEASE_COMMIT_SHA::7} --no-git-tag-version
env:
RELEASE_COMMIT_SHA: ${{ github.sha }}
- name: Build release version
if: github.ref_type == 'tag' && startsWith(github.ref_name, 'v')
run: exit 1 # TODO: Script to update version number in webampLazy.tsx
- name: Publish to npm
working-directory: ./packages/webamp
if: github.ref == 'refs/heads/master' || github.ref_type == 'tag' && startsWith(github.ref_name, 'v')
# Use pre-built artifacts instead of rebuilding
run: |
npm publish ${TAG} --ignore-scripts
env:
TAG: ${{ github.ref == 'refs/heads/master' && '--tag=next' || ''}}
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}