name: W3C Trace Context Integration Test

on:
  push:
    branches:
      - main
  pull_request:

jobs:
  build-and-test:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout 🛎️
        uses: actions/checkout@v2

      - name: restore lock files
        uses: actions/cache@master # must use unreleased master to cache multiple paths
        id: cache
        with:
          # must be done before bootstrap to not include node_modules files in the cache paths
          path: |
            package-lock.json
            packages/*/package-lock.json
            metapackages/*/package-lock.json
            packages/*/package-lock.json
            integration-tests/*/package-lock.json
          key: ${{ runner.os }}-w3c_integration-${{ hashFiles('**/package.json') }}

      - name: Install and Bootstrap (cache miss) 🔧
        if: steps.cache.outputs.cache-hit != 'true'
        run: |
          npm install --ignore-scripts
          npx lerna bootstrap --no-ci --hoist --scope=propagation-validation-server --include-dependencies

      - name: Install and Bootstrap (cache hit) 🔧
        if: steps.cache.outputs.cache-hit == 'true'
        run: |
          npm ci --ignore-scripts
          npx lerna bootstrap --hoist --scope=propagation-validation-server --include-dependencies

      - name: Generate version.ts files
        run: lerna run version

      - name: Build 🔧
        run: npm run compile
        working-directory: ./integration-tests/propagation-validation-server

      - name: Run W3C Test harness
        run: ./integration-tests/tracecontext-integration-test.sh
