ci-workflow.spec.ts 1.3 KB

123456789101112131415161718192021222324252627282930313233
  1. import { readFileSync } from 'node:fs'
  2. import { resolve } from 'node:path'
  3. import * as yaml from 'js-yaml'
  4. import { describe, expect, it } from 'vitest'
  5. const root = resolve(import.meta.dirname, '..')
  6. const runnerPrivatePnpmDestination = '${{ runner.temp }}/setup-pnpm'
  7. describe('CI workflow', () => {
  8. it('isolates every pnpm action setup destination per runner', () => {
  9. const workflow: unknown = yaml.load(readFileSync(resolve(root, '.github/workflows/ci.yml'), 'utf8'))
  10. if (!isRecord(workflow) || !isRecord(workflow.jobs)) throw new TypeError('CI workflow must define jobs')
  11. const setups = Object.entries(workflow.jobs).flatMap(([jobName, job]) => {
  12. if (!isRecord(job) || !Array.isArray(job.steps)) return []
  13. return job.steps.flatMap((step) => {
  14. if (!isRecord(step) || typeof step.uses !== 'string' || !step.uses.startsWith('pnpm/action-setup@')) return []
  15. return [{ jobName, step }]
  16. })
  17. })
  18. expect(setups.length).toBeGreaterThan(0)
  19. for (const { jobName, step } of setups) {
  20. expect(step, `${jobName} must not share pnpm/action-setup's default destination`).toMatchObject({
  21. with: { dest: runnerPrivatePnpmDestination },
  22. })
  23. }
  24. })
  25. })
  26. function isRecord(value: unknown): value is Record<string, unknown> {
  27. return typeof value === 'object' && value !== null && !Array.isArray(value)
  28. }