diff --git a/.github/workflows/e2e-ui.yml b/.github/workflows/e2e-ui.yml new file mode 100644 index 00000000000..1ac9cd115d0 --- /dev/null +++ b/.github/workflows/e2e-ui.yml @@ -0,0 +1,390 @@ +name: End-to-End Tests with upcoming @sanity/ui changes +permissions: + contents: read # for checkout +on: + # Can only be called remotely + workflow_call: + secrets: + TURBO_TOKEN: + SANITY_E2E_SESSION_TOKEN_NEW: + required: true + SANITY_E2E_PROJECT_ID: + required: true + +jobs: + prepare: + runs-on: ubuntu-latest + env: + TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }} + TURBO_TEAM: ${{ vars.TURBO_TEAM }} + steps: + - uses: actions/checkout@v4 + - uses: pnpm/action-setup@v4 + - uses: actions/setup-node@v4 + with: + node-version: lts/* + - run: pnpm install + - name: Patch increment version in package.json + id: npm-version + shell: bash + run: | + echo "NPM_VERSION=$(npm version --no-git-commit-hooks --no-git-tag-version patch)" >> $GITHUB_OUTPUT + - name: Namespace version with build run id + run: npm version --no-git-commit-hooks --no-git-tag-version "${{ steps.npm-version.outputs.NPM_VERSION }}-gh.${{ github.run_id }}" + - run: pnpm pack --pack-destination ./artifacts + - uses: actions/upload-artifact@v4 + with: + name: pack-sanity-ui + path: artifacts + if-no-files-found: error + overwrite: true + + cache-cli: + needs: [prepare] + timeout-minutes: 30 + runs-on: ubuntu-latest + env: + TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }} + TURBO_TEAM: ${{ vars.TURBO_TEAM }} + + steps: + - uses: actions/checkout@v4 + with: + repository: sanity-io/sanity + - uses: actions/setup-node@v4 + with: + node-version: 18 + + - uses: pnpm/action-setup@v4 + name: Install pnpm + id: pnpm-install + with: + run_install: false + + - uses: actions/download-artifact@v4 + with: + name: pack-sanity-ui + path: artifacts + - name: Install project dependencies + run: pnpm install + - run: pnpm add -w ./artifacts/sanity-ui-*.tgz + + - name: Build CLI + run: pnpm build:cli --output-logs=full --log-order=grouped + + install: + needs: [prepare, cache-cli] + timeout-minutes: 30 + runs-on: ubuntu-latest + env: + TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }} + TURBO_TEAM: ${{ vars.TURBO_TEAM }} + strategy: + fail-fast: false + matrix: + # Be sure to update all instances in this file and `pr-cleanup.yml` if updated + project: [chromium, firefox] + steps: + - uses: actions/checkout@v4 + with: + repository: sanity-io/sanity + - uses: actions/setup-node@v4 + with: + node-version: 18 + + - uses: pnpm/action-setup@v4 + name: Install pnpm + id: pnpm-install + with: + run_install: false + + - name: Get pnpm store directory + id: pnpm-cache + shell: bash + run: | + echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT + + - name: Cache node modules + id: cache-node-modules + uses: actions/cache@v4 + env: + cache-name: cache-node-modules + with: + path: ${{ steps.pnpm-cache.outputs.STORE_PATH }} + key: ${{ runner.os }}-pnpm-store-${{ env.cache-name }}-${{ hashFiles('**/pnpm-lock.yaml') }} + restore-keys: | + v1-${{ runner.os }}-pnpm-store-${{ env.cache-name }}- + v1-${{ runner.os }}-pnpm-store- + v1-${{ runner.os }}- + + - uses: actions/download-artifact@v4 + with: + name: pack-sanity-ui + path: artifacts + - name: Install project dependencies + run: pnpm install + - run: pnpm add -w ./artifacts/sanity-ui-*.tgz + + - name: Store Playwright's Version + run: | + PLAYWRIGHT_VERSION=$(npx playwright --version | sed 's/Version //') + echo "Playwright's Version: $PLAYWRIGHT_VERSION" + echo "PLAYWRIGHT_VERSION=$PLAYWRIGHT_VERSION" >> $GITHUB_ENV + + - name: Cache Playwright Browsers for Playwright's Version + id: cache-playwright-browsers + uses: actions/cache@v4 + with: + path: ~/.cache/ms-playwright + key: playwright-browsers-${{ env.PLAYWRIGHT_VERSION }} + + - name: Install Playwright Browsers + if: steps.cache-playwright-browsers.outputs.cache-hit != 'true' + run: npx playwright install --with-deps + + - name: Build CLI + run: pnpm build:cli --output-logs=full --log-order=grouped + + # - name: Build E2E test studio on next + # if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/next' }} + # env: + # # Update the SANITY_E2E_SESSION_TOKEN on github to the new value once this is merged to next + # # Change the below to `secrets.SANITY_E2E_SESSION_TOKEN` + # # Delete `SANITY_E2E_SESSION_TOKEN_NEW` from github + # SANITY_E2E_SESSION_TOKEN: ${{ secrets.SANITY_E2E_SESSION_TOKEN_NEW }} + # SANITY_E2E_PROJECT_ID: ${{ secrets.SANITY_E2E_PROJECT_ID }} + # SANITY_E2E_DATASET: ${{ secrets.SANITY_E2E_DATASET }} + # run: pnpm e2e:setup && pnpm e2e:build + + - name: Build E2E test studio on PR + # Always run with PRs logic, to ensure tests run by the UI repo doesn't conflict with tests run by the sanity repo + # if: ${{ github.event_name == 'pull_request' }} + env: + # Update the SANITY_E2E_SESSION_TOKEN on github to the new value once this is merged to next + # Change the below to `secrets.SANITY_E2E_SESSION_TOKEN` + # Delete `SANITY_E2E_SESSION_TOKEN_NEW` from github + SANITY_E2E_SESSION_TOKEN: ${{ secrets.SANITY_E2E_SESSION_TOKEN_NEW }} + SANITY_E2E_PROJECT_ID: ${{ secrets.SANITY_E2E_PROJECT_ID }} + SANITY_E2E_DATASET: pr-${{ matrix.project }}-${{ github.event.number }} + run: pnpm e2e:setup && pnpm e2e:build + + # Caches build from either PR or next + - name: Cache build + id: cache-e2e-build + uses: actions/cache@v4 + env: + cache-name: cache-e2e-build + with: + path: | + ./* + !**/node_modules/** + # Unique key for a workflow run. Should be invalidated in the next run + key: ${{ runner.os }}-${{ matrix.project }}-${{ env.cache-name }}-${{ github.run_id }} + + playwright-test: + timeout-minutes: 30 + runs-on: ubuntu-latest + needs: [install] + env: + TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }} + TURBO_TEAM: ${{ vars.TURBO_TEAM }} + strategy: + fail-fast: false + matrix: + # Be sure to update all instances in this file and `pr-cleanup.yml` if updated + project: [chromium, firefox] + # Add more shards here if needed + shardIndex: [1, 2] + shardTotal: [2] + steps: + - uses: actions/checkout@v4 + with: + repository: sanity-io/sanity + - uses: actions/setup-node@v4 + with: + node-version: 18 + + - uses: pnpm/action-setup@v4 + name: Install pnpm + id: pnpm-install + with: + run_install: false + + - name: Get pnpm store directory + id: pnpm-cache + shell: bash + run: | + echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT + + - name: Cache node modules + id: cache-node-modules + uses: actions/cache@v4 + env: + cache-name: cache-node-modules + with: + path: ${{ steps.pnpm-cache.outputs.STORE_PATH }} + key: ${{ runner.os }}-pnpm-store-${{ env.cache-name }}-${{ hashFiles('**/pnpm-lock.yaml') }} + restore-keys: | + v1-${{ runner.os }}-pnpm-store-${{ env.cache-name }}- + v1-${{ runner.os }}-pnpm-store- + v1-${{ runner.os }}- + + - uses: actions/download-artifact@v4 + with: + name: pack-sanity-ui + path: artifacts + - name: Install project dependencies + run: pnpm install + + - name: Store Playwright's Version + run: | + PLAYWRIGHT_VERSION=$(npx playwright --version | sed 's/Version //') + echo "Playwright's Version: $PLAYWRIGHT_VERSION" + echo "PLAYWRIGHT_VERSION=$PLAYWRIGHT_VERSION" >> $GITHUB_ENV + + - name: Cache Playwright Browsers for Playwright's Version + id: cache-playwright-browsers + uses: actions/cache/restore@v4 + with: + path: ~/.cache/ms-playwright + key: playwright-browsers-${{ env.PLAYWRIGHT_VERSION }} + + - name: Install Playwright Browsers + if: steps.cache-playwright-browsers.outputs.cache-hit != 'true' + run: npx playwright install --with-deps + + - name: Restore build cache + uses: actions/cache/restore@v4 + id: restore-build + env: + cache-name: cache-e2e-build + with: + path: | + ./* + !**/node_modules/** + key: ${{ runner.os }}-${{ matrix.project }}-${{ env.cache-name }}-${{ github.run_id }} + # If the cached build from the pervious step is not available. Fail the build + fail-on-cache-miss: true + + # - name: Run E2E tests on next + # if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/next' }} + # env: + # # Missing in docs but in use + # # here https://github.com/microsoft/playwright/blob/main/packages/playwright/src/reporters/blob.ts#L108 + # PWTEST_BLOB_REPORT_NAME: ${{ matrix.project }} + # # Update the SANITY_E2E_SESSION_TOKEN on github to the new value once this is merged to next + # # Change the below to `secrets.SANITY_E2E_SESSION_TOKEN` + # # Delete `SANITY_E2E_SESSION_TOKEN_NEW` from github + # SANITY_E2E_SESSION_TOKEN: ${{ secrets.SANITY_E2E_SESSION_TOKEN_NEW }} + # SANITY_E2E_PROJECT_ID: ${{ secrets.SANITY_E2E_PROJECT_ID }} + # SANITY_E2E_DATASET: ${{ secrets.SANITY_E2E_DATASET }} + # run: pnpm test:e2e --project ${{ matrix.project }} --shard ${{ matrix.shardIndex }}/${{ matrix.shardTotal }} + + - name: Run E2E tests on PR + # Always run with PRs logic, to ensure tests run by the UI repo doesn't conflict with tests run by the sanity repo + # if: ${{ github.event_name == 'pull_request' }} + env: + # Missing in docs but in use + # here https://github.com/microsoft/playwright/blob/main/packages/playwright/src/reporters/blob.ts#L108 + PWTEST_BLOB_REPORT_NAME: ${{ matrix.project }} + # Update the SANITY_E2E_SESSION_TOKEN on github to the new value once this is merged to next + # Change the below to `secrets.SANITY_E2E_SESSION_TOKEN` + # Delete `SANITY_E2E_SESSION_TOKEN_NEW` from github + SANITY_E2E_SESSION_TOKEN: ${{ secrets.SANITY_E2E_SESSION_TOKEN_NEW }} + SANITY_E2E_PROJECT_ID: ${{ secrets.SANITY_E2E_PROJECT_ID }} + SANITY_E2E_DATASET: pr-${{ matrix.project }}-${{ github.event.number }} + run: pnpm test:e2e --project ${{ matrix.project }} --shard ${{ matrix.shardIndex }}/${{ matrix.shardTotal }} + + - uses: actions/upload-artifact@v3 + if: always() + with: + name: playwright-report + path: blob-report + retention-days: 30 + merge-reports: + if: always() + needs: [playwright-test] + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + repository: sanity-io/sanity + - uses: actions/setup-node@v4 + with: + node-version: 18 + + - uses: pnpm/action-setup@v4 + name: Install pnpm + id: pnpm-install + with: + run_install: false + + - name: Get pnpm store directory + id: pnpm-cache + shell: bash + run: | + echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT + + - name: Cache node modules + id: cache-node-modules + uses: actions/cache@v4 + env: + cache-name: cache-node-modules + with: + path: ${{ steps.pnpm-cache.outputs.STORE_PATH }} + key: ${{ runner.os }}-pnpm-store-${{ env.cache-name }}-${{ hashFiles('**/pnpm-lock.yaml') }} + restore-keys: | + v1-${{ runner.os }}-pnpm-store-${{ env.cache-name }}- + v1-${{ runner.os }}-pnpm-store- + v1-${{ runner.os }}- + + - name: Install project dependencies + run: pnpm install + + - name: Download blob reports from Github Actions Artifacts + uses: actions/download-artifact@v3 + with: + name: playwright-report + path: playwright-report + + - name: Merge into HTML Report + run: npx playwright merge-reports --reporter html ./playwright-report + + - name: Upload HTML report + uses: actions/upload-artifact@v3 + with: + name: html-report--attempt-${{ github.run_attempt }} + path: playwright-report + retention-days: 30 + + cleanup: + permissions: + contents: read + actions: write # needed to delete the cache + timeout-minutes: 30 + name: Cleanup (${{ matrix.project }}) + runs-on: ubuntu-latest + needs: [playwright-test] + + strategy: + # we want to know if a test fails on a specific node version + fail-fast: false + matrix: + # Be sure to update all instances in this file and `pr-cleanup.yml` if updated + project: [chromium, firefox] + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup node + uses: actions/setup-node@v4 + with: + node-version: 18 + + # Delete the cache so it is only used once + - name: Delete Cache + run: gh cache delete ${{ runner.os }}-${{ matrix.project }}-${{ env.cache-name }}-${{ github.run_id }} + env: + cache-name: cache-e2e-build + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index d7dac534038..d8c4129cd7d 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -1,4 +1,6 @@ name: End-to-End Tests +permissions: + contents: read # for checkout on: # Build on pushes branches that have a PR (including drafts) pull_request: @@ -274,6 +276,9 @@ jobs: retention-days: 30 cleanup: + permissions: + contents: read + actions: write # needed to delete the cache timeout-minutes: 30 name: Cleanup (${{ matrix.project }}) runs-on: ubuntu-latest diff --git a/.gitignore b/.gitignore index afe43e1e51f..e3295cb0bb3 100644 --- a/.gitignore +++ b/.gitignore @@ -72,6 +72,8 @@ etc /test/e2e/results /test/e2e/state blob-report +/artifacts + # Temporary files made when running canary releases .turbo diff --git a/package.json b/package.json index d2a45637365..22521616d93 100644 --- a/package.json +++ b/package.json @@ -112,6 +112,7 @@ "@sanity/prettier-config": "^1.0.2", "@sanity/test": "0.0.1-alpha.1", "@sanity/tsdoc": "1.0.83", + "@sanity/ui": "^2.6.8", "@sanity/uuid": "^3.0.2", "@types/glob": "^7.2.0", "@types/lodash": "^4.14.149", @@ -182,6 +183,7 @@ }, "overrides": { "@npmcli/arborist": "^7.5.4", + "@sanity/ui@2": "$@sanity/ui", "@typescript-eslint/eslint-plugin": "$@typescript-eslint/eslint-plugin", "@typescript-eslint/parser": "$@typescript-eslint/parser" } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index f904ace3607..220b21e6ba7 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -5,9 +5,10 @@ settings: excludeLinksFromLockfile: false overrides: + '@npmcli/arborist': ^7.5.4 + '@sanity/ui@2': ^2.6.8 '@typescript-eslint/eslint-plugin': ^7.11.0 '@typescript-eslint/parser': ^7.11.0 - '@npmcli/arborist': ^7.5.4 importers: @@ -68,6 +69,9 @@ importers: '@sanity/tsdoc': specifier: 1.0.83 version: 1.0.83(@types/node@18.19.31)(debug@4.3.5)(react-dom@18.3.1)(react-is@18.3.1)(react@18.3.1)(sanity@packages+sanity)(styled-components@6.1.11) + '@sanity/ui': + specifier: ^2.6.8 + version: 2.6.8(react-dom@18.3.1)(react-is@18.3.1)(react@18.3.1)(styled-components@6.1.11) '@sanity/uuid': specifier: ^3.0.2 version: 3.0.2 @@ -17162,7 +17166,7 @@ packages: resolution: {integrity: sha512-y+FP4JgRaIKO17cBMyzCCVcxwl3fh7DXEp99QlvZSWUFi3NJJg2ZXFIXc2Om66HNkprfH2ORzEmEZMuDShtlTg==} engines: {node: '>=18'} peerDependencies: - '@sanity/ui': ^2.0.0 + '@sanity/ui': ^2.6.8 react: '*' sanity: ^3.0.0 styled-components: ^6.1