diff --git a/.github/actions/setup-node-pnpm/README.md b/.github/actions/setup-node-pnpm/README.md new file mode 100644 index 0000000..b180050 --- /dev/null +++ b/.github/actions/setup-node-pnpm/README.md @@ -0,0 +1,72 @@ +# Setup Node.js and pnpm Action + +A reusable composite action that consolidates Node.js and pnpm installation steps for the Vibe Dashboard project. + +## Features + +- ✅ Sets up Node.js with configurable version (defaults to LTS) +- ✅ Sets up pnpm using the project's configured version +- ✅ Optional pnpm store caching for faster builds +- ✅ Automatic dependency installation with configurable lockfile mode +- ✅ Environment variable handling for GitHub tokens + +## Usage + +```yaml +steps: + - name: Checkout code + uses: actions/checkout@v5 + + - name: Setup Node.js and pnpm + uses: ./.github/actions/setup-node-pnpm + with: + # Optional inputs + node-version: 'lts/*' # Default: 'lts/*' + enable-cache: true # Default: 'true' + frozen-lockfile: true # Default: 'true' +``` + +## Inputs + +| Input | Description | Required | Default | +|-------|-------------|----------|---------| +| `node-version` | Node.js version to install | No | `'lts/*'` | +| `enable-cache` | Enable pnpm store caching | No | `'true'` | +| `frozen-lockfile` | Use frozen lockfile for pnpm install | No | `'true'` | + +## What it does + +1. **Setup Node.js**: Installs the specified Node.js version +2. **Setup pnpm**: Installs pnpm using the project's configured version (from `packageManager` field) +3. **Cache pnpm store** (optional): Sets up caching for pnpm store to speed up subsequent runs +4. **Install dependencies**: Runs `pnpm install` with optional `--frozen-lockfile` flag + +## Examples + +### CI/CD with caching and frozen lockfile +```yaml +- name: Setup Node.js and pnpm + uses: ./.github/actions/setup-node-pnpm + with: + enable-cache: true + frozen-lockfile: true +``` + +### Deployment without strict lockfile requirements +```yaml +- name: Setup Node.js and pnpm + uses: ./.github/actions/setup-node-pnpm + with: + enable-cache: false + frozen-lockfile: false +``` + +### Custom Node.js version +```yaml +- name: Setup Node.js and pnpm + uses: ./.github/actions/setup-node-pnpm + with: + node-version: '20' + enable-cache: true + frozen-lockfile: true +``` \ No newline at end of file diff --git a/.github/actions/setup-node-pnpm/action.yml b/.github/actions/setup-node-pnpm/action.yml new file mode 100644 index 0000000..24c465b --- /dev/null +++ b/.github/actions/setup-node-pnpm/action.yml @@ -0,0 +1,50 @@ +name: 'Setup Node.js and pnpm' +description: 'Reusable action to setup Node.js and pnpm with caching' + +inputs: + node-version: + description: 'Node.js version to install' + required: false + default: 'lts/*' + enable-cache: + description: 'Enable pnpm store caching' + required: false + default: 'true' + frozen-lockfile: + description: 'Use frozen lockfile for pnpm install' + required: false + default: 'true' + +runs: + using: 'composite' + steps: + - name: Setup Node.js ${{ inputs.node-version }} + uses: actions/setup-node@v4 + with: + node-version: ${{ inputs.node-version }} + env: + GITHUB_TOKEN: ${{ github.token }} + + - name: Setup pnpm + uses: pnpm/action-setup@v4 + + - name: Get pnpm store directory + if: inputs.enable-cache == 'true' + shell: bash + run: | + echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV + + - name: Setup pnpm cache + if: inputs.enable-cache == 'true' + uses: actions/cache@v4 + with: + path: ${{ env.STORE_PATH }} + key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }} + restore-keys: | + ${{ runner.os }}-pnpm-store- + + - name: Install dependencies + shell: bash + run: pnpm install${{ inputs.frozen-lockfile == 'true' && ' --frozen-lockfile' || '' }} + env: + GITHUB_TOKEN: ${{ github.token }} \ No newline at end of file diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6727f3b..243991a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -20,33 +20,11 @@ jobs: - name: Checkout code uses: actions/checkout@v5 - - name: Setup Node.js LTS - uses: actions/setup-node@v4 + - name: Setup Node.js and pnpm + uses: ./.github/actions/setup-node-pnpm with: - node-version: 'lts/*' - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - - name: Setup pnpm - uses: pnpm/action-setup@v4 - - - name: Get pnpm store directory - shell: bash - run: | - echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV - - - name: Setup pnpm cache - uses: actions/cache@v4 - with: - path: ${{ env.STORE_PATH }} - key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }} - restore-keys: | - ${{ runner.os }}-pnpm-store- - - - name: Install dependencies - run: pnpm install --frozen-lockfile - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + enable-cache: true + frozen-lockfile: true - name: Lint code run: pnpm lint diff --git a/.github/workflows/copilot-setup-steps.yml b/.github/workflows/copilot-setup-steps.yml index 34e9bbf..e2e8506 100644 --- a/.github/workflows/copilot-setup-steps.yml +++ b/.github/workflows/copilot-setup-steps.yml @@ -28,20 +28,11 @@ jobs: steps: - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 - - name: Setup Node.js - uses: actions/setup-node@v4 + - name: Setup Node.js and pnpm + uses: ./.github/actions/setup-node-pnpm with: - node-version: 'lts/*' - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - - name: Setup pnpm - uses: pnpm/action-setup@v4 - - - name: Install dependencies - run: pnpm install - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + enable-cache: false + frozen-lockfile: false - name: Run lint run: pnpm lint diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index c191368..c94c027 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -23,20 +23,11 @@ jobs: - name: Checkout uses: actions/checkout@v5 - - name: Setup Node.js - uses: actions/setup-node@v4 + - name: Setup Node.js and pnpm + uses: ./.github/actions/setup-node-pnpm with: - node-version: 'lts/*' - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - - name: Setup pnpm - uses: pnpm/action-setup@v4 - - - name: Install dependencies - run: pnpm install - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + enable-cache: false + frozen-lockfile: false - name: Lint run: pnpm lint