Skip to content

Commit

Permalink
ci: list workspaces script
Browse files Browse the repository at this point in the history
  • Loading branch information
dangreen committed Jan 1, 2025
1 parent 6bcef23 commit cc36c97
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 8 deletions.
19 changes: 16 additions & 3 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,26 @@ on:
branches:
- main
jobs:
list-workspaces:
runs-on: ubuntu-latest
name: list workspaces
outputs:
test-size: ${{ steps.set-matrix.outputs.test-size }}
steps:
- name: Checkout the repository
uses: actions/checkout@v4
- name: Install Node.js
uses: actions/setup-node@v4
with:
node-version: 18
- id: set-matrix
run: node .github/workflows/list-workspaces.js test:size
size:
runs-on: ubuntu-latest
needs: list-workspaces
strategy:
matrix:
workspace:
- nanoviews
- stores
workspace: ${{ fromJson(needs.list-workspaces.outputs.test-size) }}
name: ${{ matrix.workspace }} / size-limit
steps:
- name: Checkout the repository
Expand Down
31 changes: 31 additions & 0 deletions .github/workflows/list-workspaces.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import fs from 'fs/promises'
import path from 'path'

const scriptsToFind = process.argv.slice(2)
const workspaceDir = 'packages'
const workspaceFiles = await fs.readdir(workspaceDir, {
withFileTypes: true
})
const foundWorkspaces = {}

for (const file of workspaceFiles) {
if (file.isDirectory()) {
try {
const packageJson = await fs.readFile(path.join(workspaceDir, file.name, 'package.json'), 'utf-8')
const { scripts } = JSON.parse(packageJson)

if (scripts) {
for (const scriptToFind of scriptsToFind) {
if (scripts[scriptToFind]) {
foundWorkspaces[scriptToFind] = foundWorkspaces[scriptToFind] || []
foundWorkspaces[scriptToFind].push(file.name)
}
}
}
} catch (error) {}
}
}

for (const foundWorkspacesKey in foundWorkspaces) {
console.log('::set-output name=' + foundWorkspacesKey.replaceAll(':', '-') + '::' + JSON.stringify(foundWorkspaces[foundWorkspacesKey]))
}
12 changes: 7 additions & 5 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ jobs:
runs-on: ubuntu-latest
name: list workspaces
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
test-types: ${{ steps.set-matrix.outputs.test-types }}
lint: ${{ steps.set-matrix.outputs.lint }}
test-unit: ${{ steps.set-matrix.outputs.test-unit }}
steps:
- name: Checkout the repository
uses: actions/checkout@v4
Expand All @@ -18,13 +20,13 @@ jobs:
with:
node-version: 18
- id: set-matrix
run: node -e "console.log('::set-output name=matrix::' + JSON.stringify(fs.readdirSync('packages')))"
run: node .github/workflows/list-workspaces.js test:types lint test:unit
types:
runs-on: ubuntu-latest
needs: list-workspaces
strategy:
matrix:
workspace: ${{ fromJson(needs.list-workspaces.outputs.matrix) }}
workspace: ${{ fromJson(needs.list-workspaces.outputs.test-types) }}
name: ${{ matrix.workspace }} / types
steps:
- name: Checkout the repository
Expand All @@ -47,7 +49,7 @@ jobs:
needs: list-workspaces
strategy:
matrix:
workspace: ${{ fromJson(needs.list-workspaces.outputs.matrix) }}
workspace: ${{ fromJson(needs.list-workspaces.outputs.lint) }}
name: ${{ matrix.workspace }} / lint
steps:
- name: Checkout the repository
Expand All @@ -70,7 +72,7 @@ jobs:
needs: list-workspaces
strategy:
matrix:
workspace: ${{ fromJson(needs.list-workspaces.outputs.matrix) }}
workspace: ${{ fromJson(needs.list-workspaces.outputs.test-unit) }}
name: ${{ matrix.workspace }} / unit
steps:
- name: Checkout the repository
Expand Down

0 comments on commit cc36c97

Please sign in to comment.