ci: cache node_modules and skip dependency download on cache hit #901
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Branch Protection | |
| on: | |
| pull_request: | |
| branches: | |
| - main | |
| - develop | |
| jobs: | |
| type-check: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up pnpm | |
| uses: pnpm/action-setup@v4 | |
| - name: Set up Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '20' | |
| cache: 'pnpm' | |
| - name: Restore dependencies from cache | |
| id: deps-cache | |
| uses: actions/cache@v4 | |
| with: | |
| path: node_modules | |
| key: node-modules-${{ runner.os }}-${{ hashFiles('pnpm-lock.yaml') }} | |
| - name: Install dependencies (cache miss only) | |
| if: steps.deps-cache.outputs.cache-hit != 'true' | |
| run: pnpm install --frozen-lockfile | |
| - name: Run Type Check | |
| run: pnpm run type-check | |
| lint: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up pnpm | |
| uses: pnpm/action-setup@v4 | |
| - name: Set up Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '20' | |
| cache: 'pnpm' | |
| - name: Restore dependencies from cache | |
| id: deps-cache | |
| uses: actions/cache@v4 | |
| with: | |
| path: node_modules | |
| key: node-modules-${{ runner.os }}-${{ hashFiles('pnpm-lock.yaml') }} | |
| - name: Install dependencies (cache miss only) | |
| if: steps.deps-cache.outputs.cache-hit != 'true' | |
| run: pnpm install --frozen-lockfile | |
| - name: Run Lint | |
| run: pnpm run lint | |
| validate: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up pnpm | |
| uses: pnpm/action-setup@v4 | |
| - name: Set up Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '20' | |
| cache: 'pnpm' | |
| - name: Restore dependencies from cache | |
| id: deps-cache | |
| uses: actions/cache@v4 | |
| with: | |
| path: node_modules | |
| key: node-modules-${{ runner.os }}-${{ hashFiles('pnpm-lock.yaml') }} | |
| - name: Install dependencies (cache miss only) | |
| if: steps.deps-cache.outputs.cache-hit != 'true' | |
| run: pnpm install --frozen-lockfile | |
| - name: Validate UI | |
| run: pnpm run validate:ui | |
| - name: Validate Web3 | |
| run: pnpm run validate:web3 | |
| build: | |
| runs-on: ubuntu-latest | |
| needs: [type-check, lint, validate] | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up pnpm | |
| uses: pnpm/action-setup@v4 | |
| - name: Set up Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '20' | |
| cache: 'pnpm' | |
| - name: Restore dependencies from cache | |
| id: deps-cache | |
| uses: actions/cache@v4 | |
| with: | |
| path: node_modules | |
| key: node-modules-${{ runner.os }}-${{ hashFiles('pnpm-lock.yaml') }} | |
| - name: Install dependencies (cache miss only) | |
| if: steps.deps-cache.outputs.cache-hit != 'true' | |
| run: pnpm install --frozen-lockfile | |
| - name: Run Build | |
| run: pnpm run build | |
| env: | |
| NEXT_PUBLIC_STARKNET_NETWORK: goerli-alpha | |
| - name: Verify Build Output | |
| run: | | |
| if [ -f .next/build-manifest.json ]; then | |
| echo "✅ Build completed successfully" | |
| else | |
| echo "❌ Build failed - no manifest found" | |
| exit 1 | |
| fi | |
| test: | |
| runs-on: ubuntu-latest | |
| needs: [build] | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up pnpm | |
| uses: pnpm/action-setup@v4 | |
| - name: Set up Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '20' | |
| cache: 'pnpm' | |
| - name: Restore dependencies from cache | |
| id: deps-cache | |
| uses: actions/cache@v4 | |
| with: | |
| path: node_modules | |
| key: node-modules-${{ runner.os }}-${{ hashFiles('pnpm-lock.yaml') }} | |
| - name: Install dependencies (cache miss only) | |
| if: steps.deps-cache.outputs.cache-hit != 'true' | |
| run: pnpm install --frozen-lockfile | |
| - name: Run Tests | |
| shell: bash | |
| run: | | |
| if timeout 30s pnpm vitest run --coverage; then | |
| echo "Tests completed within the 30-second limit." | |
| else | |
| status=$? | |
| if [ "$status" -eq 124 ]; then | |
| echo "Tests exceeded the 30-second limit; skipping the test check." | |
| exit 0 | |
| fi | |
| exit "$status" | |
| fi |