name: Preview Documentation (Azure Blob Storage) on: pull_request: types: [opened, synchronize, reopened, closed] permissions: contents: read pull-requests: write concurrency: group: ${{ github.workflow }}-${{ github.event.pull_request.number }} cancel-in-progress: true env: AZCOPY_AUTO_LOGIN_TYPE: SPN AZCOPY_SPA_APPLICATION_ID: ${{ secrets.AZURE_CLIENT_ID }} AZCOPY_SPA_CLIENT_SECRET: ${{ secrets.AZURE_CLIENT_SECRET }} AZCOPY_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }} jobs: build_and_deploy_job: if: github.event_name == 'pull_request' && github.event.action != 'closed' runs-on: ubuntu-26.04 name: Build and Deploy Job timeout-minutes: 30 outputs: first_gen_docs_url: ${{ steps.deploy.outputs.first_gen_docs_url }} first_gen_storybook_url: ${{ steps.deploy.outputs.first_gen_storybook_url }} gen2_storybook_dev_url: ${{ steps.deploy.outputs.gen2_storybook_dev_url }} gen2_storybook_prod_url: ${{ steps.deploy.outputs.gen2_storybook_prod_url }} steps: ## --- SETUP --- ## - name: Check out code uses: actions/checkout@v7 with: fetch-depth: 0 - name: Use Node version from .nvmrc uses: actions/setup-node@v7 with: node-version-file: '.nvmrc' cache: yarn - name: Enable Corepack run: corepack enable - name: Generate PR hash id: pr_hash run: | # Use just PR number so each commit overwrites the previous deployment pr_hash="pr-${{ github.event.pull_request.number }}" echo "hash=${pr_hash}" >> "$GITHUB_OUTPUT" echo "Generated PR hash: ${pr_hash}" ## --- YARN CACHE --- ## - name: Check for cached dependencies continue-on-error: true id: cache-dependencies uses: actions/cache@v6 with: path: | .cache/yarn node_modules key: ubuntu-26.04-${{ hashFiles('.nvmrc', 'package.json', 'yarn.lock') }} ## --- INSTALL & BUILD --- ## - name: Install dependencies shell: bash run: yarn install --immutable - name: Build all generations run: yarn build - name: Generate Custom Elements Manifest run: yarn workspace @spectrum-web-components/1st-gen docs:analyze - name: Analyze gen2 components run: yarn workspace @adobe/spectrum-wc analyze - name: Generate LLM reference files run: yarn generate:llms - name: Generate Agent Skills run: yarn generate:skills - name: Move CEM to Storybook directory run: cp 1st-gen/projects/documentation/custom-elements.json 1st-gen/storybook/ - name: Build documentation with path prefix env: SWC_DIR: ${{ steps.pr_hash.outputs.hash }}/docs/gen1-docs run: | yarn workspace @spectrum-web-components/1st-gen docs:build - name: Build Gen1 Storybook env: # Cross-link to this PR's gen2 preview (prod-mode build) instead of # the default production URL. SWC_GEN2_STORYBOOK_URL: https://swcpreviews.z13.web.core.windows.net/${{ steps.pr_hash.outputs.hash }}/docs/gen2-storybook-prod/ run: yarn workspace @spectrum-web-components/1st-gen storybook:build - name: Build Gen2 Storybook (dev mode) env: # Full dev-mode story set (internal stories, .test.ts fixtures, # .vrt.ts). `storybook build` only defaults NODE_ENV to production # when unset, so setting it explicitly here keeps the dev story set. NODE_ENV: development run: yarn workspace @adobe/spectrum-wc storybook:build --output-dir storybook-static-dev - name: Build Gen2 Storybook (prod mode) # No NODE_ENV override: this is the same production-trimmed build # that publish-gen2-docs.yml deploys to the live site, so # reviewers can validate exactly what will end up on prod. env: # Cross-link to this PR's gen1 preview instead of the default # production URL. SWC_GEN1_STORYBOOK_URL: https://swcpreviews.z13.web.core.windows.net/${{ steps.pr_hash.outputs.hash }}/docs/gen1-storybook/ run: yarn workspace @adobe/spectrum-wc storybook:build --output-dir storybook-static-prod ## --- DEPLOY TO AZURE BLOB STORAGE --- ## - name: Setup AzCopy uses: ./.github/actions/setup-azcopy - name: Deploy Gen1 documentation to Azure Blob Storage env: PR_HASH: ${{ steps.pr_hash.outputs.hash }} run: | echo "Uploading Gen1 documentation to ${PR_HASH}/docs/gen1-docs/" azcopy copy "1st-gen/projects/documentation/dist/*" \ "https://swcpreviews.blob.core.windows.net/\$web/${PR_HASH}/docs/gen1-docs/" \ --recursive \ --from-to LocalBlob echo "✅ Gen1 documentation uploaded successfully" - name: Deploy Gen1 Storybook to Azure Blob Storage env: PR_HASH: ${{ steps.pr_hash.outputs.hash }} run: | echo "Uploading Gen1 Storybook to ${PR_HASH}/docs/gen1-storybook/" azcopy copy "1st-gen/projects/documentation/dist/storybook/*" \ "https://swcpreviews.blob.core.windows.net/\$web/${PR_HASH}/docs/gen1-storybook/" \ --recursive \ --from-to LocalBlob echo "✅ Gen1 Storybook uploaded successfully" - name: Deploy Gen2 Storybook (dev mode) to Azure Blob Storage env: PR_HASH: ${{ steps.pr_hash.outputs.hash }} run: | echo "Uploading Gen2 Storybook (dev) to ${PR_HASH}/docs/gen2-storybook-dev/" azcopy copy "gen2/packages/swc/storybook-static-dev/*" \ "https://swcpreviews.blob.core.windows.net/\$web/${PR_HASH}/docs/gen2-storybook-dev/" \ --recursive \ --from-to LocalBlob echo "✅ Gen2 Storybook (dev) uploaded successfully" - name: Deploy Gen2 Storybook (prod mode) to Azure Blob Storage env: PR_HASH: ${{ steps.pr_hash.outputs.hash }} run: | echo "Uploading Gen2 Storybook (prod) to ${PR_HASH}/docs/gen2-storybook-prod/" azcopy copy "gen2/packages/swc/storybook-static-prod/*" \ "https://swcpreviews.blob.core.windows.net/\$web/${PR_HASH}/docs/gen2-storybook-prod/" \ --recursive \ --from-to LocalBlob echo "✅ Gen2 Storybook (prod) uploaded successfully" - name: Set deployment URLs id: deploy env: PR_HASH: ${{ steps.pr_hash.outputs.hash }} run: | first_gen_docs_url="https://swcpreviews.z13.web.core.windows.net/${PR_HASH}/docs/gen1-docs/" first_gen_storybook_url="https://swcpreviews.z13.web.core.windows.net/${PR_HASH}/docs/gen1-storybook/" gen2_storybook_dev_url="https://swcpreviews.z13.web.core.windows.net/${PR_HASH}/docs/gen2-storybook-dev/" gen2_storybook_prod_url="https://swcpreviews.z13.web.core.windows.net/${PR_HASH}/docs/gen2-storybook-prod/" echo "first_gen_docs_url=${first_gen_docs_url}" >> "$GITHUB_OUTPUT" echo "first_gen_storybook_url=${first_gen_storybook_url}" >> "$GITHUB_OUTPUT" echo "gen2_storybook_dev_url=${gen2_storybook_dev_url}" >> "$GITHUB_OUTPUT" echo "gen2_storybook_prod_url=${gen2_storybook_prod_url}" >> "$GITHUB_OUTPUT" echo "📦 All deployments completed:" echo " - Documentation: ${first_gen_docs_url}" echo " - Gen1 Storybook: ${first_gen_storybook_url}" echo " - Gen2 Storybook (dev): ${gen2_storybook_dev_url}" echo " - Gen2 Storybook (prod): ${gen2_storybook_prod_url}" - name: Post Previews Comment uses: actions/github-script@v9 with: script: | const { buildPreviewURLComment } = await import('${{ github.workspace }}/.github/scripts/build-preview-urls-comment.js'); const { commentOrUpdate } = await import('${{ github.workspace }}/.github/scripts/comment-or-update.js'); const prNumber = context.payload.pull_request.number; const body = buildPreviewURLComment(prNumber); console.log(`Posting comment to PR #${prNumber}`); commentOrUpdate(github, context, '## 📚 Branch Preview Links', body); smoke_tests: if: github.event_name == 'pull_request' && github.event.action != 'closed' needs: build_and_deploy_job runs-on: ubuntu-26.04 name: Smoke Tests timeout-minutes: 15 steps: - name: Checkout PR branch uses: actions/checkout@v7 - name: Wait for deployment env: DOC_URL: ${{ needs.build_and_deploy_job.outputs.first_gen_docs_url }} run: | echo "Waiting for deployment to be available at: ${DOC_URL}" # Wait up to 10 minutes for the deployment to be available max_attempts=60 attempt=1 while [ $attempt -le $max_attempts ]; do echo "Attempt $attempt/$max_attempts: Checking if site is available..." if curl -f -s --max-time 10 "${DOC_URL}" > /dev/null; then echo "✅ ${DOC_URL} is now available!" break else echo "❌ Site not ready yet, waiting 10 seconds..." sleep 10 attempt=$((attempt + 1)) fi done if [ $attempt -gt $max_attempts ]; then echo "❌ Timeout: Site was not available after 10 minutes" exit 1 fi - name: Setup Job and Install Dependencies uses: ./.github/actions/setup-job - name: Install Chromium run: cd 1st-gen && yarn playwright install --with-deps chromium - name: Run Playwright tests run: cd 1st-gen && yarn playwright test projects/documentation/e2e/ --browser chromium env: DOC_PREVIEW_URL: ${{ needs.build_and_deploy_job.outputs.first_gen_docs_url }} SWC_DIR: pr-${{ github.event.pull_request.number }} NODE_ENV: CI - name: Upload Playwright Report uses: actions/upload-artifact@v7 if: always() with: name: playwright-report path: playwright-report/ retention-days: 30 close_pull_request_job: if: github.event_name == 'pull_request' && github.event.action == 'closed' runs-on: ubuntu-26.04 name: Clean up PR deployment timeout-minutes: 5 steps: - name: Check out code uses: actions/checkout@v7 with: fetch-depth: 0 - name: Generate PR hash id: pr_hash run: | # Create the same hash as in the deploy job pr_hash="pr-${{ github.event.pull_request.number }}" echo "hash=${pr_hash}" >> "$GITHUB_OUTPUT" - name: Setup AzCopy uses: ./.github/actions/setup-azcopy - name: Clean up PR deployment env: PR_HASH: ${{ steps.pr_hash.outputs.hash }} run: | echo "Cleaning up deployment: ${PR_HASH}/" azcopy remove "https://swcpreviews.blob.core.windows.net/\$web/${PR_HASH}/" \ --recursive || echo "Cleanup completed (some files may not exist)" echo "Cleanup completed for PR deployment: ${PR_HASH}/"