name: Playwright Tests on: pull_request: branches: [master, release/*] workflow_dispatch: inputs: cs3d_ref: description: >- CS3D branch (e.g. main, origin:feat/foo) or version (e.g. 4.18.2, 4.19+, 4.x). Only used when ohif-integration label is present or via workflow_dispatch. required: false default: '4.19+' permissions: contents: read pull-requests: read issues: read concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true jobs: playwright-tests: timeout-minutes: 120 runs-on: self-hosted strategy: fail-fast: false matrix: node-version: [20] steps: - uses: actions/checkout@v4 - uses: oven-sh/setup-bun@v2 with: bun-version: 1.2.23 - uses: actions/setup-node@v4 with: node-version: ${{ matrix.node-version }} - name: Install Yarn run: npm install -g yarn@1.22.22 # ── CS3D integration: detect label and ref type ────────────────────── - name: Check for CS3D integration label id: cs3d-check run: bash .scripts/ci/cs3d-check-integration.sh env: GH_TOKEN: ${{ github.token }} EVENT_NAME: ${{ github.event_name }} CS3D_REF_INPUT: ${{ github.event.inputs.cs3d_ref || '4.19+' }} REPO: ${{ github.repository }} PR_NUMBER: ${{ github.event.pull_request.number }} - name: Detect CS3D ref type id: cs3d-ref if: steps.cs3d-check.outputs.enabled == 'true' run: | REF="${CS3D_REF}" if [[ "$REF" =~ ^[0-9]+\.[0-9x]+\+?(\.[0-9x]+)?(-[a-zA-Z0-9._]+)?$ ]]; then echo "type=version" >> "$GITHUB_OUTPUT" RESOLVED=$(node .scripts/cs3d-resolve-version.mjs "$REF") echo "version=$RESOLVED" >> "$GITHUB_OUTPUT" echo "::notice::CS3D version: $REF -> $RESOLVED" else echo "type=branch" >> "$GITHUB_OUTPUT" echo "::notice::CS3D branch: $REF" fi env: CS3D_REF: ${{ steps.cs3d-check.outputs.cs3d_ref }} # ── CS3D branch path: clone and build before OHIF install ─────────── - name: Clone CS3D if: steps.cs3d-check.outputs.enabled == 'true' && steps.cs3d-ref.outputs.type == 'branch' run: | REF="${CS3D_REF}" if [[ "$REF" == *:* ]]; then REPO="https://github.com/${REF%%:*}/cornerstone3D.git" BRANCH="${REF#*:}" else REPO="https://github.com/cornerstonejs/cornerstone3D.git" BRANCH="$REF" fi echo "::notice::Cloning CS3D from $REPO branch $BRANCH" git clone --depth 1 --branch "$BRANCH" "$REPO" libs/@cornerstonejs env: CS3D_REF: ${{ steps.cs3d-check.outputs.cs3d_ref }} - name: Install & Build CS3D if: steps.cs3d-check.outputs.enabled == 'true' && steps.cs3d-ref.outputs.type == 'branch' working-directory: libs/@cornerstonejs run: bun install --frozen-lockfile && bun run build:esm # ── Common: install OHIF dependencies ─────────────────────────────── - name: Install dependencies run: bun install --frozen-lockfile # ── CS3D branch path: link packages after OHIF install ────────────── - name: Link CS3D packages if: steps.cs3d-check.outputs.enabled == 'true' && steps.cs3d-ref.outputs.type == 'branch' working-directory: libs/@cornerstonejs run: node scripts/link-ohif-cornerstone-node-modules.mjs "$GITHUB_WORKSPACE" # ── CS3D version path: update versions after OHIF install ─────────── - name: Set CS3D version if: steps.cs3d-check.outputs.enabled == 'true' && steps.cs3d-ref.outputs.type == 'version' run: | node .scripts/cs3d-set-version.mjs "${CS3D_VERSION}" bun install --config=./bunfig.update-lockfile.toml env: CS3D_VERSION: ${{ steps.cs3d-ref.outputs.version }} # ── Common: run tests ─────────────────────────────────────────────── - name: Install Playwright browsers run: npx playwright install - name: Run Playwright tests run: | export NODE_OPTIONS="--max_old_space_size=10192" bun run test:e2e:coverage # ── Common: collect test results and coverage ─────────────────────── - name: Create directory of test results if: ${{ !cancelled() }} run: | mkdir -p packaged-test-results cp -r ./tests/test-results packaged-test-results/ || true cp -r ./tests/playwright-report packaged-test-results/ || true - name: Upload directory of test results artifact if: ${{ !cancelled() }} uses: actions/upload-artifact@v4 with: name: playwright-results path: packaged-test-results/ retention-days: 5 - name: create the coverage report run: | bun nyc report --reporter=lcov --reporter=text - name: Upload the coverage report to GitHub Actions Artifacts if: ${{ !cancelled() }} uses: actions/upload-artifact@v4 with: name: coverage-report-pr path: coverage retention-days: 3 # ── CS3D: build and deploy preview to Netlify ─────────────────────── - name: Log build context (OHIF/CS3D branch and version for build diagnosis) if: steps.cs3d-check.outputs.enabled == 'true' run: | if [[ "$CS3D_REF_TYPE" == "branch" ]]; then echo "::notice::Build type: ohif-downstream | OHIF: ${{ github.repository }}@${{ github.ref }} (${{ github.sha }}) | CS3D: branch ${{ steps.cs3d-check.outputs.cs3d_ref }}" else echo "::notice::Build type: ohif-upstream | OHIF: ${{ github.repository }}@${{ github.ref }} (${{ github.sha }}) | CS3D: version ${{ steps.cs3d-ref.outputs.version }}" fi node .scripts/log-build-context.mjs env: BUILD_TYPE: ${{ steps.cs3d-ref.outputs.type == 'branch' && 'ohif-downstream' || 'ohif-upstream' }} CS3D_REF_TYPE: ${{ steps.cs3d-ref.outputs.type }} - name: Build OHIF viewer (CS3D preview) if: steps.cs3d-check.outputs.enabled == 'true' run: bun run build:ci - name: Deploy CS3D preview to Netlify if: steps.cs3d-check.outputs.enabled == 'true' run: | RESULT=$(npx netlify-cli deploy --dir=platform/app/dist --alias="cs3d-pr-${PR_NUM}" --json --filter=@ohif/app) || { echo "::error::Netlify deploy command failed" exit 1 } URL=$(echo "$RESULT" | jq -r '.deploy_url') if [[ -z "$URL" || "$URL" == "null" ]]; then echo "::error::Netlify deploy did not return a valid URL" echo "$RESULT" exit 1 fi echo "::notice::CS3D preview deployed: $URL" env: NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }} NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }} PR_NUM: ${{ github.event.pull_request.number || 'manual' }} # ── CS3D: log results ─────────────────────────────────────────────── - name: Log CS3D build used if: steps.cs3d-check.outputs.enabled == 'true' run: | if [[ "$CS3D_REF_TYPE" == "branch" ]]; then echo "::notice::CS3D integration PASSED with branch ${CS3D_REF} (linked from libs/@cornerstonejs)" else echo "::notice::CS3D integration PASSED with @cornerstonejs/*@${CS3D_VERSION}" fi env: CS3D_REF_TYPE: ${{ steps.cs3d-ref.outputs.type }} CS3D_REF: ${{ steps.cs3d-check.outputs.cs3d_ref }} CS3D_VERSION: ${{ steps.cs3d-ref.outputs.version }} # ── Separate job: block merge when using a CS3D branch ───────────── cs3d-branch-merge-guard: name: "CS3D Branch Merge Guard" runs-on: ubuntu-latest timeout-minutes: 5 steps: - uses: actions/checkout@v4 - name: Check for CS3D branch usage run: bash .scripts/ci/cs3d-branch-merge-guard.sh env: GH_TOKEN: ${{ github.token }} EVENT_NAME: ${{ github.event_name }} CS3D_REF_INPUT: ${{ github.event.inputs.cs3d_ref || '4.19+' }} REPO: ${{ github.repository }} PR_NUMBER: ${{ github.event.pull_request.number }}