Skip to content

Commit

Permalink
Merge pull request #372 from brenoepics/ci-1
Browse files Browse the repository at this point in the history
ci: add workflows for running vue + nuxt integration tests
  • Loading branch information
rrd108 authored Oct 2, 2024
2 parents 305c19f + f75973e commit 4ed749a
Show file tree
Hide file tree
Showing 8 changed files with 309 additions and 7 deletions.
1 change: 1 addition & 0 deletions .github/workflows/autofix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ jobs:
- uses: actions/setup-node@v4
with:
node-version: 20
cache: 'yarn'

- name: Install dependencies
run: yarn install
Expand Down
42 changes: 42 additions & 0 deletions .github/workflows/check-dist.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# This workflow checks that the `dist/` directory is up-to-date with the source
name: Check Transpiled JavaScript

on:
push:
branches:
- main

permissions:
contents: read

jobs:
check-dist:
name: Check dist/
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set node version
uses: actions/setup-node@v4
with:
node-version: 20
cache: 'yarn'

- name: Build dist/ Directory
id: build
run: |
yarn install
yarn build
# This will fail the workflow if the `dist/` directory is different from
# expected.
- name: Compare Directories
id: diff
run: |
if [ "$(git diff --ignore-space-at-eol --text dist/ | wc -l)" -gt "0" ]; then
echo "Detected uncommitted changes after build. See status below:"
git diff --ignore-space-at-eol --text dist/
exit 1
fi
1 change: 1 addition & 0 deletions .github/workflows/continuous-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ jobs:
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'yarn'

- name: Install dependencies
run: yarn install
Expand Down
246 changes: 246 additions & 0 deletions .github/workflows/integration-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,246 @@
name: Integration Tests

on:
workflow_dispatch:
pull_request:
branches:
- main
push:
branches:
- main

permissions:
contents: read

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'yarn'

- name: Install dependencies
run: yarn install

- name: Build package
run: yarn build

- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: vue-mess-detector
retention-days: 1
path: |
./package.json
./dist
./node_modules
./yarn.lock
./index.d.ts
test-create-vue:
runs-on: ${{ matrix.platform }}
needs: build

strategy:
matrix:
platform: [ 'macos-latest', 'ubuntu-latest', 'windows-latest' ]
package-manager: [ npm, yarn, pnpm, bun ]

name: Testing Vue with ${{ matrix.package-manager }} on ${{ matrix.platform }}
steps:
- name: Create directories
run: |
mkdir ./package
mkdir ./test-repo
- name: Download artifact
uses: actions/download-artifact@v4
with:
name: vue-mess-detector
path: ./package

- if: matrix.package-manager != 'bun'
name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '20'

- if: matrix.package-manager == 'pnpm'
name: Check PNPM
uses: pnpm/action-setup@v4
with:
version: '9.9.0'

- if: matrix.package-manager == 'yarn'
name: Check Yarn
run: |
corepack prepare yarn@stable --activate
yarn set version stable
- if: matrix.package-manager == 'bun'
name: Check Bun
uses: oven-sh/setup-bun@v2
with:
bun-version: '1.1.26'

- if: runner.os != 'Windows'
name: Create and Run Vue Mess Detector (Linux/Mac)
working-directory: ./test-repo
run: |
if [ "${{ matrix.package-manager }}" == "pnpm" ]; then
yes "my-package" | head -n 1 | pnpm create vue@latest . --default --typescript
pnpm add file:${{ github.workspace }}/package/ -D
pnpm install
pnpm vue-mess-detector analyze --output=json --file-output=vmd-output.json
elif [ "${{ matrix.package-manager }}" == "yarn" ]; then
yes "my-package" | head -n 1 | yarn --cwd . create vue . --default --typescript
touch ./yarn.lock
yarn add vue-mess-detector@file:${{ github.workspace }}/package/ -D
yarn install
yarn vue-mess-detector analyze --output=json --file-output=vmd-output.json
elif [ "${{ matrix.package-manager }}" == "bun" ]; then
yes "my-package" | head -n 1 | bun create vue . --default --typescript --cwd=. --ignore-scripts
bun add file:${{ github.workspace }}/package/ --dev
bun install --ignore-scripts
bun run vue-mess-detector analyze --output=json --file-output=vmd-output.json
else
yes "my-package" | head -n 1 | npm create vue@latest -- . --default --typescript
npm install file:${{ github.workspace }}/package/ --save-dev
npm install
npx vue-mess-detector analyze --output=json --file-output=vmd-output.json
fi
node -e "const fs = require('fs'); try { const data = JSON.parse(fs.readFileSync('vmd-output.json', 'utf8')); console.log(JSON.stringify(data, null, 2)); } catch (e) { throw new Error('Something went wrong'); }"
- if: runner.os == 'Windows'
name: Create and Run Vue Mess Detector (Windows)
working-directory: ./test-repo
run: |
if ($Env:matrix_package_manager -eq 'pnpm') {
echo "my-package" | pnpm create vue@latest . --default --typescript
pnpm add file:${{ github.workspace }}/package/ -D
pnpm install
pnpm vue-mess-detector analyze --output=json --file-output=vmd-output.json
} elseif ($Env:matrix_package_manager -eq 'yarn') {
echo "my-package" | yarn create vue . --default --typescript
touch ./yarn.lock
yarn add vue-mess-detector@file:${{ github.workspace }}/package/ -D
yarn install
yarn vue-mess-detector analyze --output=json --file-output=vmd-output.json
} elseif ($Env:matrix_package_manager -eq 'bun') {
echo "my-package" | bun create vue . --default --typescript --ignore-scripts
bun add file:${{ github.workspace }}/package/ --d
bun install --ignore-scripts
bun run vue-mess-detector analyze --output=json --file-output=vmd-output.json
} else {
echo "my-package" | npm create vue@latest -- . --default --typescript
npm install file:${{ github.workspace }}/package/ --save-dev
npm install
npx vue-mess-detector analyze --output=json --file-output=vmd-output.json
}
node -e "const fs = require('fs'); try { const data = JSON.parse(fs.readFileSync('vmd-output.json', 'utf8')); console.log(JSON.stringify(data, null, 2)); } catch (e) { throw new Error('Something went wrong'); }"
test-nuxi:
runs-on: ${{ matrix.platform }}
needs: build
strategy:
matrix:
platform: [ 'macos-latest', 'ubuntu-latest', 'windows-latest' ]
package-manager: [ npm, yarn, pnpm, bun ]

name: Testing Nuxt with ${{ matrix.package-manager }} on ${{ matrix.platform }}
steps:
- name: Create directories
run: |
mkdir ./package
mkdir ./test-repo
- name: Download artifact
uses: actions/download-artifact@v4
with:
name: vue-mess-detector
path: ./package

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '20'

- if: matrix.package-manager == 'pnpm'
name: Check PNPM
uses: pnpm/action-setup@v4
with:
version: 'latest'

- if: matrix.package-manager == 'yarn'
name: Check Yarn
run: |
corepack prepare yarn@stable --activate
yarn set version stable
- if: matrix.package-manager == 'bun'
name: Check Bun
uses: oven-sh/setup-bun@v2
with:
bun-version: 'latest'

- if: runner.os != 'Windows'
name: Create and Run Vue Mess Detector (Linux/Mac)
working-directory: ./test-repo
run: |
if [ "${{ matrix.package-manager }}" == "pnpm" ]; then
(cd .. && pnpm dlx nuxi@latest init test-repo --package-manager pnpm --git-init -t themes/content-wind)
pnpm add file:${{ github.workspace }}/package/ -D
pnpm install
pnpm vue-mess-detector analyze ./ --output=json --file-output=vmd-output.json
elif [ "${{ matrix.package-manager }}" == "yarn" ]; then
(cd .. && yarn dlx nuxi@latest init test-repo --package-manager yarn --git-init -t themes/content-wind --no-install)
touch yarn.lock
yarn add vue-mess-detector@file:${{ github.workspace }}/package/ -D
yarn install
yarn vue-mess-detector analyze ./ --output=json --file-output=vmd-output.json
elif [ "${{ matrix.package-manager }}" == "bun" ]; then
(cd .. && bun x nuxi@latest init test-repo --package-manager bun --git-init -t themes/content-wind)
bun add file:${{ github.workspace }}/package/ --dev
bun install --ignore-scripts
bun run vue-mess-detector analyze ./ --output=json --file-output=vmd-output.json
else
(cd .. && npx nuxi@latest init test-repo --package-manager npm --git-init -t themes/content-wind)
npm install file:${{ github.workspace }}/package/ --save-dev
npm install
npx vue-mess-detector analyze ./ --output=json --file-output=vmd-output.json
fi
node -e "const fs = require('fs'); try { const data = JSON.parse(fs.readFileSync('vmd-output.json', 'utf8')); console.log(JSON.stringify(data, null, 2)); } catch (e) { throw new Error('Something went wrong'); }"
- if: runner.os == 'Windows'
name: Create and Run Vue Mess Detector (Windows)
working-directory: ./test-repo
run: |
if ($Env:matrix_package_manager -eq 'pnpm') {
(cd .. && pnpm dlx nuxi@latest init test-repo --package-manager pnpm --git-init -t themes/content-wind)
pnpm add file:${{ github.workspace }}/package/ -D
pnpm install
pnpm vue-mess-detector analyze ./ --output=json --file-output=vmd-output.json
} elseif ($Env:matrix_package_manager -eq 'yarn') {
(cd .. && yarn dlx nuxi@latest init test-repo --package-manager yarn --git-init -t themes/content-wind --no-install)
touch ./yarn.lock
yarn add vue-mess-detector@file:${{ github.workspace }}/package/ -D
yarn install
yarn vue-mess-detector analyze ./ --output=json --file-output=vmd-output.json
} elseif ($Env:matrix_package_manager -eq 'bun') {
(cd .. && bun x nuxi@latest init test-repo --package-manager bun --git-init -t themes/content-wind)
bun add file:${{ github.workspace }}/package/ --dev
bun install --ignore-scripts
bun run vue-mess-detector analyze ./ --output=json --file-output=vmd-output.json
} else {
(cd .. && npx nuxi@latest init test-repo --package-manager npm --git-init -t themes/content-wind)
npm install file:${{ github.workspace }}/package/ --save-dev
npm install
npx vue-mess-detector analyze ./ --output=json --file-output=vmd-output.json
}
node -e "const fs = require('fs'); try { const data = JSON.parse(fs.readFileSync('vmd-output.json', 'utf8')); console.log(JSON.stringify(data, null, 2)); } catch (e) { throw new Error('Something went wrong'); }"
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Run Tests
name: Run Unit Tests

on:
push:
Expand All @@ -17,6 +17,7 @@ jobs:
uses: actions/setup-node@v4
with:
node-version: '20' # or another version you prefer
cache: 'yarn'

- name: Install dependencies
run: yarn install
Expand Down
7 changes: 3 additions & 4 deletions .github/workflows/vmd-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: VMD Analysis

on:
workflow_dispatch:
pull_request:
pull_request_target:
branches:
- main
push:
Expand All @@ -25,8 +25,7 @@ jobs:
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'yarn'

- name: Vue Mess Detector Analysis
uses: brenoepics/vmd-action@v0.0.4
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
uses: brenoepics/vmd-action@v0.0.5
6 changes: 5 additions & 1 deletion src/helpers/projectTypeChecker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ const checkDependency = async (dependencyName: 'vue' | 'nuxt', projectRoot: stri
const packageJsonPath = path.join(projectPath, 'package.json')
if (fs.existsSync(packageJsonPath)) {
const packageJson = await getPackageJson(projectRoot)
return Boolean(packageJson.dependencies[dependencyName])
return Boolean(
packageJson.dependencies?.[dependencyName]
|| packageJson.devDependencies?.[dependencyName]
|| packageJson.peerDependencies?.[dependencyName],
)
}
return false
}
Expand Down
10 changes: 9 additions & 1 deletion src/types/PackageJson.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
export interface PackageJson {
version: string
dependencies: {
dependencies?: {
vue?: string
nuxt?: string
}
devDependencies?: {
vue?: string
nuxt?: string
}
peerDependencies?: {
vue?: string
nuxt?: string
}
Expand Down

0 comments on commit 4ed749a

Please sign in to comment.