|
| 1 | +name: Shared CI Tests |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_call: |
| 5 | + inputs: |
| 6 | + test-published-packages: |
| 7 | + description: 'Test against published packages instead of checked out code' |
| 8 | + required: false |
| 9 | + type: boolean |
| 10 | + default: false |
| 11 | + |
| 12 | +env: |
| 13 | + NODE_OPTIONS: "--max-old-space-size=4096" |
| 14 | + NPM_CONFIG_UNSAFE_PERM: true |
| 15 | + |
| 16 | +jobs: |
| 17 | + test: |
| 18 | + runs-on: ubuntu-latest |
| 19 | + permissions: |
| 20 | + id-token: write |
| 21 | + contents: read |
| 22 | + strategy: |
| 23 | + fail-fast: false |
| 24 | + matrix: |
| 25 | + node-version: ['18.x', '20.x', '22.x', 'latest'] |
| 26 | + test-type: ['node', 'browser'] |
| 27 | + # Determine test categories based on whether testing published packages or source code: |
| 28 | + # - Testing published packages: only run vector tests (don't have build artifacts to test coverage or compliance) |
| 29 | + # - Testing source code: run coverage, vector, and compliance tests |
| 30 | + test-category: ${{ fromJSON(inputs['test-published-packages'] && '["vectors"]' || '["coverage", "vectors", "compliance"]') }} |
| 31 | + name: test-${{ matrix.test-category }}-${{ matrix.test-type }}-${{ matrix.node-version }} |
| 32 | + steps: |
| 33 | + - name: Checkout code |
| 34 | + # Always need repo for test scripts and configuration, even when testing published packages |
| 35 | + uses: actions/checkout@v4 |
| 36 | + with: |
| 37 | + fetch-depth: 0 |
| 38 | + submodules: true |
| 39 | + |
| 40 | + - name: Setup Node.js ${{ matrix.node-version }} |
| 41 | + uses: actions/setup-node@v4 |
| 42 | + with: |
| 43 | + node-version: ${{ matrix.node-version }} |
| 44 | + cache: 'npm' |
| 45 | + |
| 46 | + - name: Configure AWS Credentials for Tests |
| 47 | + uses: aws-actions/configure-aws-credentials@v4 |
| 48 | + with: |
| 49 | + aws-region: us-west-2 |
| 50 | + role-to-assume: arn:aws:iam::370957321024:role/GitHub-CI-MPL-Dafny-Role-us-west-2 |
| 51 | + role-session-name: JavaScriptTests |
| 52 | + |
| 53 | + - name: Install dependencies |
| 54 | + run: npm ci --unsafe-perm |
| 55 | + |
| 56 | + - name: Build (for source code testing) |
| 57 | + if: ${{ !inputs.test-published-packages }} |
| 58 | + run: npm run build |
| 59 | + |
| 60 | + - name: Run coverage tests (${{ matrix.test-type }}) |
| 61 | + if: ${{ matrix.test-category == 'coverage' }} |
| 62 | + run: npm run coverage-${{ matrix.test-type }} |
| 63 | + |
| 64 | + - name: Publish locally for vector tests |
| 65 | + if: ${{ matrix.test-category == 'vectors' && !inputs.test-published-packages }} |
| 66 | + run: npm run verdaccio-publish |
| 67 | + |
| 68 | + - name: Run vector tests (${{ matrix.test-type }}) |
| 69 | + if: ${{ matrix.test-category == 'vectors' }} |
| 70 | + run: | |
| 71 | + npm run verdaccio-${{ matrix.test-type }}-decrypt |
| 72 | + npm run verdaccio-${{ matrix.test-type }}-encrypt |
| 73 | +
|
| 74 | + - name: Run compliance tests |
| 75 | + # Don't run linting or check Duvet requirements for published packages |
| 76 | + if: ${{ matrix.test-category == 'compliance'}} |
| 77 | + run: | |
| 78 | + npm run lint |
| 79 | + npm run test_conditions |
0 commit comments