Skip to content

Commit

Permalink
feat: ci script (#218)
Browse files Browse the repository at this point in the history
* ci: create test script
  • Loading branch information
Yordan-Ramchev authored Mar 6, 2024
1 parent 4e5980a commit 3177231
Show file tree
Hide file tree
Showing 4 changed files with 1,154 additions and 4,827 deletions.
191 changes: 191 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
name: 'ci'
on:
push:
branches:
- '**'
- '!renovate/**'
paths-ignore:
- README.md
- CONTRIBUTING.md
pull_request:
branches:
- '**'
jobs:
build:
runs-on: ubuntu-latest
name: Build the package
steps:
- uses: actions/checkout@v4
# Setup .npmrc file to publish to npm
- uses: actions/setup-node@v4
with:
node-version: '18.x'
registry-url: 'https://registry.npmjs.org'
- run: npm ci
env:
CYPRESS_INSTALL_BINARY: 0
- run: npm run build
- run: npm run test:unit

# Use cache to share the output across different jobs
# No need to cache node_modules because they are all bundled
- uses: actions/cache/save@v4
id: cache
with:
path: outfile.cjs
key: ${{ github.sha }}-${{ hashFiles('package-lock.json') }}
test:
needs: build
strategy:
matrix:
node-version: [18]
os: [ubuntu-latest]
flag-for-ts: ['', '--typescript']
flag-for-jsx: ['', '--jsx']
flag-for-router: ['', '--router']
flag-for-pinia: ['', '--pinia']
flag-for-vitest: ['', '--vitest']

# It's quite costly to install Cypress & Playwright even with cache.
# Maybe we can split them into another job so that all the projects
# can share the same binary installation.
flag-for-e2e: ['', '--cypress', '--playwright']

# Skip ESLint/Prettier tests as we've reached the limit of job numbers
# TODO: Find a way to test them without adding new jobs

# Run a few tests on other systems and Node.js versions
include:
- node-version: 18
os: windows-latest
flag-for-ts: '--typescript'
flag-for-jsx: '--jsx'
flag-for-router: '--router'
flag-for-pinia: '--pinia'
flag-for-vitest: '--vitest'
flag-for-e2e: '--playwright'
flag-for-tanStackQuery: '--tanStackQuery'
flag-for-tailwind: '--tailwind'
flag-for-vueUse: '--vueUse'
flag-for-i18n: '--i18n'
flag-for-sonarQube: '--sonarQube'

- node-version: 18
os: macos-latest
flag-for-ts: '--typescript'
flag-for-jsx: '--jsx'
flag-for-router: '--router'
flag-for-pinia: '--pinia'
flag-for-vitest: '--vitest'
flag-for-e2e: '--playwright'
flag-for-tanStackQuery: '--tanStackQuery'
flag-for-tailwind: '--tailwind'
flag-for-vueUse: '--vueUse'
flag-for-i18n: '--i18n'
flag-for-sonarQube: '--sonarQube'

- node-version: 20
os: ubuntu-latest
flag-for-ts: '--typescript'
flag-for-jsx: '--jsx'
flag-for-router: '--router'
flag-for-pinia: '--pinia'
flag-for-vitest: '--vitest'
flag-for-e2e: '--playwright'
flag-for-tanStackQuery: '--tanStackQuery'
flag-for-tailwind: '--tailwind'
flag-for-vueUse: '--vueUse'
flag-for-i18n: '--i18n'
flag-for-sonarQube: '--sonarQube'

runs-on: ${{ matrix.os }}
continue-on-error: ${{ matrix.os == 'windows-latest' }}
env:
FEATURE_FLAGS: ${{ matrix.flag-for-ts }} ${{ matrix.flag-for-jsx }} ${{ matrix.flag-for-router }} ${{ matrix.flag-for-pinia }} ${{ matrix.flag-for-vitest }} ${{ matrix.flag-for-e2e }}
# Sometimes the Linux runner can't verify Cypress in 30s
CYPRESS_VERIFY_TIMEOUT: 60000
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- uses: actions/cache/restore@v4
id: cache-restore
with:
path: outfile.cjs
key: ${{ github.sha }}-${{ hashFiles('npm-lock.yaml') }}
- name: Build the package on cache miss
if: steps.cache-restore.outputs.cache-hit != 'true'
run: npm install && npm run build

# https://github.com/vitejs/vite/blob/main/.github/workflows/ci.yml#L62
# Install playwright's binary under custom directory to cache
- name: Set Playwright & Cypress path
if: runner.os != 'Windows'
run: |
echo "PLAYWRIGHT_BROWSERS_PATH=$HOME/.cache/playwright-bin" >> $GITHUB_ENV
echo "CYPRESS_CACHE_FOLDER=$HOME/.cache/cypress-bin" >> $GITHUB_ENV
- name: Set Playwright & Cypress path (windows)
if: runner.os == 'Windows'
run: |
echo "PLAYWRIGHT_BROWSERS_PATH=$HOME\.cache\playwright-bin" >> $env:GITHUB_ENV
echo "CYPRESS_CACHE_FOLDER=$HOME\.cache\cypress-bin" >> $env:GITHUB_ENV
- if: ${{ contains(matrix.flag-for-e2e, '--cypress') }}
name: Cache Cypress binaries
id: cache-cypress
uses: actions/cache@v4
with:
# TODO: avoid snowballing by adding version
key: ${{ runner.os }}-cypress-bin
path: ${{ env.CYPRESS_CACHE_FOLDER }}

- if: ${{ contains(matrix.flag-for-e2e, '--playwright') }}
name: Cache Playwright's binary
uses: actions/cache@v4
with:
# Playwright removes unused browsers automatically
# So does not need to add playwright version to key
key: ${{ runner.os }}-playwright-bin-v1
path: ${{ env.PLAYWRIGHT_BROWSERS_PATH }}

- if: ${{ (contains(env.FEATURE_FLAGS, '--')) }}
name: Create the sample project with feature flags
working-directory: ../
run: node ./create-vue/outfile.cjs sample-project ${{ env.FEATURE_FLAGS }}

- if: ${{ !(contains(env.FEATURE_FLAGS, '--')) }}
name: Create the sample project with default options
working-directory: ../
run: node ./create-vue/outfile.cjs sample-project --default

- name: Install dependencies in the sample project
working-directory: ../sample-project
run: npm install

- if: ${{ contains(matrix.flag-for-vitest, '--') }}
name: Run unit test script
working-directory: ../sample-project
run: npm run test:unit

- name: Run build script
working-directory: ../sample-project
run: npm run build

- name: Download Cypress
if: ${{ contains(matrix.flag-for-e2e, '--cypress') }}
working-directory: ../sample-project
run: |
npm exec cypress cache list
npm exec cypress install
- if: ${{ contains(matrix.flag-for-e2e, '--playwright') }}
name: Install Playwright dependencies
working-directory: ../sample-project
run: npx playwright install --with-deps

- if: ${{ contains(matrix.flag-for-e2e, '--') }}
name: Run e2e test script
working-directory: ../sample-project
run: npm run test:e2e
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<a href="http://commitizen.github.io/cz-cli/"><img src="https://img.shields.io/badge/commitizen-friendly-brightgreen.svg" alt="Commitizen friendly"></a>
<a href="https://github.com/MentorMate/create-vue/actions/workflows/github-code-scanning/codeql"><img src="https://github.com/MentorMate/create-vue/actions/workflows/github-code-scanning/codeql/badge.svg" alt="CodeQL friendly"></a>
<a href="https://github.com/MentorMate/create-vue/actions/workflows/npm-publish-package.yml"><img src="https://github.com/MentorMate/create-vue/actions/workflows/npm-publish-package.yml/badge.svg" alt="Publish Package"></a>
<a href="https://github.com/MentorMate/create-vue/actions/workflows/ci.yml"><img src="https://github.com/MentorMate/create-vue/actions/workflows/ci.yml/badge.svg" alt="CI Badge"/></a>
</p>

<img width="794" alt="Screenshot 2023-12-20 at 17 04 59" src="https://github.com/MentorMate/create-vue/assets/69005114/645aca7c-af75-4d05-b959-916ec9d7e1d1">
Expand Down
Loading

0 comments on commit 3177231

Please sign in to comment.