Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Migrate plugin workspace to pnpm #204

Merged
merged 16 commits into from
Mar 30, 2024
110 changes: 24 additions & 86 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# Build, Test, Lint & e2e pushes.
# TODO: use the .nvmrc for node versions
# https://github.com/actions/setup-node/issues/32
name: CI

on:
Expand All @@ -19,124 +17,64 @@ on:
jobs:
setup:
runs-on: ubuntu-latest
env:
CI: true

strategy:
matrix:
node-version: [18]

steps:
# Setup steps
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v3
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- name: Cache node modules
id: cache-node-modules
uses: actions/cache@v4
with:
path: node_modules
key: ${{ runner.os }}-node-modules-${{ matrix.node-version }}-${{ hashFiles('**/package-lock.json') }}
- name: Install npm
if: steps.cache-node-modules.outputs.cache-hit != 'true'
run: npm ci
node-version-file: '.nvmrc'
cache: 'pnpm'
- run: pnpm install

build:
needs: [setup]

runs-on: ubuntu-latest
env:
CI: true

strategy:
matrix:
node-version: [18]

steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v3
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- name: Cache node modules
id: cache-node-modules
uses: actions/cache@v4
with:
path: node_modules
key: ${{ runner.os }}-node-modules-${{ matrix.node-version }}-${{ hashFiles('**/package-lock.json') }}
- name: Build
run: npm run build
node-version-file: '.nvmrc'
cache: 'pnpm'
- run: pnpm install
- run: pnpm run build

lint:
needs: [setup]

runs-on: ubuntu-latest
env:
CI: true

strategy:
matrix:
node-version: [18]

steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v3
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- name: Cache node modules
id: cache-node-modules
uses: actions/cache@v4
with:
path: node_modules
key: ${{ runner.os }}-node-modules-${{ matrix.node-version }}-${{ hashFiles('**/package-lock.json') }}
- name: Lint Affected Apps
run: npm run lint
node-version-file: '.nvmrc'
cache: 'pnpm'
- run: pnpm install
- run: pnpm run lint

test:
needs: [setup]

runs-on: ubuntu-latest
env:
CI: true

strategy:
matrix:
node-version: [18]

steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v3
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- name: Cache node modules
id: cache-node-modules
uses: actions/cache@v4
with:
path: node_modules
key: ${{ runner.os }}-node-modules-${{ matrix.node-version }}-${{ hashFiles('**/package-lock.json') }}
- run: npm run test
node-version-file: '.nvmrc'
cache: 'pnpm'
- run: pnpm install
- run: pnpm run test

# e2e might be too much work todo for every push, lets see.
e2e:
needs: [setup]

runs-on: ubuntu-latest
env:
CI: true

strategy:
matrix:
node-version: [18]

steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v3
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- name: Cache node modules
id: cache-node-modules
uses: actions/cache@v4
with:
path: node_modules
key: ${{ runner.os }}-node-modules-${{ matrix.node-version }}-${{ hashFiles('**/package-lock.json') }}
- run: npm run e2e
node-version-file: '.nvmrc'
cache: 'pnpm'
- run: pnpm install
- run: pnpm run e2e
20 changes: 11 additions & 9 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- run: |
TAG_VERSION=${GITHUB_REF#refs/tags/v}
PACKAGE_VERSION=$(node -p "require('./packages/nx-firebase/package.json').version")
Expand All @@ -27,23 +26,25 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v3
- uses: actions/setup-node@v4
with:
node-version: 18
node-version-file: '.nvmrc'
cache: 'pnpm'
registry-url: 'https://npm.pkg.github.com/simondotm'
#scope: '@simondotm'
#- run: npm run addscope
- run: npm ci
- run: pnpm install

- name: Build plugin
run: npx nx build nx-firebase

- name: Create package
run: npm pack
run: pnpm pack
working-directory: ./dist/packages/nx-firebase

- name: Publish to GitHub Packages
run: npm publish
run: pnpm publish
working-directory: ./dist/packages/nx-firebase
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -53,18 +54,19 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
# Setup .npmrc file to publish to npm
- uses: pnpm/action-setup@v3
- uses: actions/setup-node@v4
with:
node-version: 18
node-version-file: '.nvmrc'
cache: 'pnpm'
registry-url: 'https://registry.npmjs.org'
- run: npm ci
- run: pnpm install

- name: Build plugin
run: npx nx build nx-firebase

- name: Publish to NPM
run: npm publish --access=public
run: pnpm publish --access=public
working-directory: ./dist/packages/nx-firebase
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,5 @@ Thumbs.db
e2e.log

.nx/cache

.nx-firebase
8 changes: 8 additions & 0 deletions e2e/compat/src/app/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { defaultCwd } from './utils/cwd'

// this is the package manager that will be used for the test Nx workspace
export const PACKAGE_MANAGER = 'pnpm'

// const CACHE_DIR = `${defaultCwd}/node_modules/.cache/nx-firebase`
export const CACHE_DIR = `${defaultCwd}/.nx-firebase`
// const CACHE_DIR = `${defaultCwd}/../.nx-firebase`
5 changes: 1 addition & 4 deletions e2e/compat/src/app/utils/cache.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import { CACHE_DIR } from '../config'
import { defaultCwd } from './cwd'
import { info } from './log'
import { satisfies } from 'semver'

export const localPluginVersion = 'local'

// const CACHE_DIR = `${defaultCwd}/node_modules/.cache/nx-firebase`
// const CACHE_DIR = `${defaultCwd}/.nx-firebase`
const CACHE_DIR = `${defaultCwd}/../.nx-firebase`

export type Cache = {
nxVersion: string
pluginVersion: string
Expand Down
5 changes: 3 additions & 2 deletions e2e/compat/src/app/utils/log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,19 @@ const DEFAULT_LOG_FILE = `${process.cwd()}/e2e.log`

import * as fs from 'fs'
import { ensureDir } from './utils'
import { dirname } from 'path'

let LOG_FILE: string | undefined

function writeLog(msg: string) {
ensureDir(LOG_FILE)
ensureDir(dirname(LOG_FILE))
fs.appendFileSync(LOG_FILE, `${msg}\n`)
}

export function setLogFile(path?: string) {
LOG_FILE = path || DEFAULT_LOG_FILE
console.log(`Logging to '${LOG_FILE}'`)
ensureDir(LOG_FILE)
ensureDir(dirname(LOG_FILE))
fs.writeFileSync(LOG_FILE, '') // reset log file
}

Expand Down
11 changes: 5 additions & 6 deletions e2e/compat/src/app/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as fs from 'fs'
// import { readJsonFile, writeJsonFile } from '@nx/devkit'
// import { exit } from 'process'
import { log } from './log'
import { dirname } from 'path'


/**
* Set current working directory
Expand All @@ -17,15 +17,14 @@ export function setCwd(dir: string) {
}

/**
* Ensure given directory path to filename or dir exists, create if it doesn't
* @param path - filename or directory path
* Ensure given directory path exists, create if it doesn't
* @param dir - directory path
* @returns true if path already exists
*/
export function ensureDir(path: string) {
const dir = dirname(path)
export function ensureDir(dir: string) {
const pathExists = fs.existsSync(dir)
if (!pathExists) {
console.log(`Creating dir '${dir}'...`)
console.log(` - Creating dir '${dir}'...`)
fs.mkdirSync(dir, { recursive: true })
}
return pathExists
Expand Down
8 changes: 5 additions & 3 deletions e2e/compat/src/app/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Cache, isNxVersionSince } from './utils/cache'
import { customExec, runNxCommandAsync } from './utils/exec'
import { info, log } from './utils/log'
import { deleteDir, ensureDir, setCwd } from './utils/utils'
import { PACKAGE_MANAGER } from './config'

export function createTestDir(testDir: string) {
ensureDir(testDir)
Expand Down Expand Up @@ -48,19 +49,20 @@ export async function installPlugin(cache: Cache) {
await customExec(`cp -rf ${pluginFileSrc} ${pluginFileDst}`)

log(`Installing plugin '${pluginFileDst}'...`)
await customExec(`npm i ${pluginFileDst} --save-dev ${legacyPeerDeps}`)
await customExec(`${PACKAGE_MANAGER} i ${pluginFileDst} --save-dev ${legacyPeerDeps}`)
} else {
await customExec(
`npm i @simondotm/nx-firebase@${cache.pluginVersion} --save-dev ${legacyPeerDeps}`,
`${PACKAGE_MANAGER} i @simondotm/nx-firebase@${cache.pluginVersion} --save-dev ${legacyPeerDeps}`,
)
}
}

export async function createWorkspace(cache: Cache) {
cleanWorkspace(cache.workspaceDir)
const nxCloudOption = isNxVersionSince(cache, '17.3.2') ? 'skip' : 'false'

await customExec(
`npx create-nx-workspace@${cache.nxVersion} --preset=apps --interactive=false --name=myorg --nxCloud=${nxCloudOption}`,
`npx create-nx-workspace@${cache.nxVersion} --preset=apps --interactive=false --name=myorg --nxCloud=${nxCloudOption} --packageManager=${PACKAGE_MANAGER}`,
)
setCwd(cache.workspaceDir)

Expand Down
Loading
Loading