|
| 1 | +# Generates visual + interaction baselines for released SuperDoc versions |
| 2 | +# Triggered manually via workflow_dispatch |
| 3 | +name: 📸 Baseline superdoc |
| 4 | + |
| 5 | +on: |
| 6 | + workflow_dispatch: |
| 7 | + inputs: |
| 8 | + version: |
| 9 | + description: 'Version to baseline (e.g., 1.5.0-next.1). Leave empty to auto-detect from latest tag.' |
| 10 | + required: false |
| 11 | + type: string |
| 12 | + |
| 13 | +permissions: |
| 14 | + contents: read |
| 15 | + actions: write |
| 16 | + |
| 17 | +concurrency: |
| 18 | + group: baseline-superdoc-${{ github.run_id }} |
| 19 | + cancel-in-progress: false |
| 20 | + |
| 21 | +jobs: |
| 22 | + generate-baselines: |
| 23 | + name: Generate Baselines |
| 24 | + runs-on: ubuntu-24.04 |
| 25 | + |
| 26 | + steps: |
| 27 | + - name: Checkout |
| 28 | + uses: actions/checkout@v4 |
| 29 | + with: |
| 30 | + fetch-depth: 0 |
| 31 | + ref: ${{ github.sha }} |
| 32 | + |
| 33 | + - name: Resolve release version |
| 34 | + id: version |
| 35 | + run: | |
| 36 | + # If manual dispatch with version provided, use it |
| 37 | + if [ -n "${{ inputs.version }}" ]; then |
| 38 | + VERSION="${{ inputs.version }}" |
| 39 | + echo "version=$VERSION" >> $GITHUB_OUTPUT |
| 40 | + echo "✅ Using manually specified version: $VERSION" |
| 41 | + exit 0 |
| 42 | + fi |
| 43 | +
|
| 44 | + # Find tags pointing at the release commit |
| 45 | + HEAD_SHA="${{ github.sha }}" |
| 46 | + echo "Looking for tags at commit: $HEAD_SHA" |
| 47 | +
|
| 48 | + # Get all tags pointing at this commit |
| 49 | + TAGS=$(git tag --points-at "$HEAD_SHA" 2>/dev/null || true) |
| 50 | + echo "Tags found: $TAGS" |
| 51 | +
|
| 52 | + if [ -z "$TAGS" ]; then |
| 53 | + echo "⚠️ No tags found at commit $HEAD_SHA" |
| 54 | + echo "skip=true" >> $GITHUB_OUTPUT |
| 55 | + exit 0 |
| 56 | + fi |
| 57 | +
|
| 58 | + # Find a version tag (v* pattern, prefer -next. for prerelease) |
| 59 | + VERSION_TAG="" |
| 60 | + for tag in $TAGS; do |
| 61 | + if [[ "$tag" =~ ^v[0-9]+\.[0-9]+\.[0-9]+ ]]; then |
| 62 | + VERSION_TAG="$tag" |
| 63 | + # Prefer -next. tags if multiple exist |
| 64 | + if [[ "$tag" == *"-next."* ]]; then |
| 65 | + break |
| 66 | + fi |
| 67 | + fi |
| 68 | + done |
| 69 | +
|
| 70 | + if [ -z "$VERSION_TAG" ]; then |
| 71 | + echo "⚠️ No version tag (v*) found at commit" |
| 72 | + echo "skip=true" >> $GITHUB_OUTPUT |
| 73 | + exit 0 |
| 74 | + fi |
| 75 | +
|
| 76 | + # Strip leading 'v' to get npm version |
| 77 | + VERSION="${VERSION_TAG#v}" |
| 78 | + echo "version=$VERSION" >> $GITHUB_OUTPUT |
| 79 | + echo "✅ Resolved version: $VERSION (from tag $VERSION_TAG)" |
| 80 | +
|
| 81 | + - name: Skip if no release |
| 82 | + if: steps.version.outputs.skip == 'true' |
| 83 | + run: | |
| 84 | + echo "No release tag found - semantic-release may have been a no-op." |
| 85 | + echo "Exiting successfully." |
| 86 | +
|
| 87 | + - name: Setup pnpm |
| 88 | + if: steps.version.outputs.skip != 'true' |
| 89 | + uses: pnpm/action-setup@v4 |
| 90 | + |
| 91 | + - name: Setup Node.js |
| 92 | + if: steps.version.outputs.skip != 'true' |
| 93 | + uses: actions/setup-node@v4 |
| 94 | + with: |
| 95 | + node-version-file: .nvmrc |
| 96 | + cache: pnpm |
| 97 | + cache-dependency-path: devtools/visual-testing/pnpm-lock.yaml |
| 98 | + |
| 99 | + - name: Cache apt packages |
| 100 | + if: steps.version.outputs.skip != 'true' |
| 101 | + uses: actions/cache@v4 |
| 102 | + with: |
| 103 | + path: ~/apt-cache |
| 104 | + key: apt-canvas-${{ runner.os }}-v1 |
| 105 | + |
| 106 | + - name: Install canvas system dependencies |
| 107 | + if: steps.version.outputs.skip != 'true' |
| 108 | + run: | |
| 109 | + mkdir -p ~/apt-cache |
| 110 | + sudo apt-get update |
| 111 | + sudo apt-get install -y -o Dir::Cache::Archives="$HOME/apt-cache" \ |
| 112 | + build-essential \ |
| 113 | + libcairo2-dev \ |
| 114 | + libpango1.0-dev \ |
| 115 | + libjpeg-dev \ |
| 116 | + libgif-dev \ |
| 117 | + librsvg2-dev \ |
| 118 | + libpixman-1-dev |
| 119 | +
|
| 120 | + - name: Install dependencies |
| 121 | + if: steps.version.outputs.skip != 'true' |
| 122 | + working-directory: devtools/visual-testing |
| 123 | + run: pnpm install |
| 124 | + |
| 125 | + - name: Get Playwright version |
| 126 | + if: steps.version.outputs.skip != 'true' |
| 127 | + id: playwright-version |
| 128 | + working-directory: devtools/visual-testing |
| 129 | + run: | |
| 130 | + echo "version=$(node -p "require('./package.json').devDependencies['@playwright/test'].replace('^', '')")" >> $GITHUB_OUTPUT |
| 131 | +
|
| 132 | + - name: Cache Playwright browsers |
| 133 | + if: steps.version.outputs.skip != 'true' |
| 134 | + uses: actions/cache@v4 |
| 135 | + id: playwright-cache |
| 136 | + with: |
| 137 | + path: ~/.cache/ms-playwright |
| 138 | + key: playwright-${{ runner.os }}-${{ steps.playwright-version.outputs.version }} |
| 139 | + |
| 140 | + - name: Install Playwright browsers |
| 141 | + if: steps.version.outputs.skip != 'true' && steps.playwright-cache.outputs.cache-hit != 'true' |
| 142 | + working-directory: devtools/visual-testing |
| 143 | + run: pnpm exec playwright install --with-deps chromium firefox webkit |
| 144 | + |
| 145 | + - name: Install Playwright system deps (cache hit) |
| 146 | + if: steps.version.outputs.skip != 'true' && steps.playwright-cache.outputs.cache-hit == 'true' |
| 147 | + working-directory: devtools/visual-testing |
| 148 | + run: pnpm exec playwright install-deps chromium firefox webkit |
| 149 | + |
| 150 | + - name: Wait for npm propagation |
| 151 | + if: steps.version.outputs.skip != 'true' |
| 152 | + run: | |
| 153 | + VERSION="${{ steps.version.outputs.version }}" |
| 154 | + echo "Waiting for superdoc@$VERSION to be available on npm..." |
| 155 | +
|
| 156 | + for i in {1..30}; do |
| 157 | + if npm view "superdoc@$VERSION" version 2>/dev/null; then |
| 158 | + echo "✅ Version $VERSION is available on npm" |
| 159 | + exit 0 |
| 160 | + fi |
| 161 | + echo "Attempt $i/30: Version not yet available, waiting 10s..." |
| 162 | + sleep 10 |
| 163 | + done |
| 164 | +
|
| 165 | + echo "❌ Timed out waiting for npm propagation" |
| 166 | + exit 1 |
| 167 | +
|
| 168 | + - name: Switch to released version |
| 169 | + if: steps.version.outputs.skip != 'true' |
| 170 | + working-directory: devtools/visual-testing |
| 171 | + env: |
| 172 | + PNPM_FROZEN_LOCKFILE: 'false' |
| 173 | + NPM_CONFIG_FROZEN_LOCKFILE: 'false' |
| 174 | + run: | |
| 175 | + VERSION="${{ steps.version.outputs.version }}" |
| 176 | + echo "Installing superdoc@$VERSION..." |
| 177 | + pnpm superdoc "$VERSION" |
| 178 | +
|
| 179 | + # Verify installation |
| 180 | + INSTALLED=$(node -p "require('./packages/harness/node_modules/superdoc/package.json').version") |
| 181 | + echo "Installed version: $INSTALLED" |
| 182 | +
|
| 183 | + if [ "$INSTALLED" != "$VERSION" ]; then |
| 184 | + echo "❌ Version mismatch! Expected $VERSION, got $INSTALLED" |
| 185 | + exit 1 |
| 186 | + fi |
| 187 | +
|
| 188 | + - name: Generate baselines |
| 189 | + if: steps.version.outputs.skip != 'true' |
| 190 | + working-directory: devtools/visual-testing |
| 191 | + env: |
| 192 | + SD_TESTING_R2_ACCOUNT_ID: ${{ secrets.SD_TESTING_R2_ACCOUNT_ID }} |
| 193 | + SD_TESTING_R2_BUCKET_NAME: ${{ secrets.SD_TESTING_R2_BUCKET_NAME }} |
| 194 | + SD_TESTING_R2_BASELINES_BUCKET_NAME: ${{ secrets.SD_TESTING_R2_BASELINES_BUCKET_NAME }} |
| 195 | + SD_TESTING_R2_ACCESS_KEY_ID: ${{ secrets.SD_TESTING_R2_ACCESS_KEY_ID }} |
| 196 | + SD_TESTING_R2_SECRET_ACCESS_KEY: ${{ secrets.SD_TESTING_R2_SECRET_ACCESS_KEY }} |
| 197 | + run: | |
| 198 | + VERSION="${{ steps.version.outputs.version }}" |
| 199 | + pnpm baseline "$VERSION" --ci |
| 200 | +
|
| 201 | + - name: Summary |
| 202 | + if: steps.version.outputs.skip != 'true' |
| 203 | + run: | |
| 204 | + VERSION="${{ steps.version.outputs.version }}" |
| 205 | + cat >> $GITHUB_STEP_SUMMARY << EOF |
| 206 | + ## 📸 Visual Baselines Generated |
| 207 | +
|
| 208 | + | Property | Value | |
| 209 | + |----------|-------| |
| 210 | + | **Version** | \`$VERSION\` | |
| 211 | + | **Browsers** | Chromium, Firefox, WebKit | |
| 212 | + | **Trigger** | Manual | |
| 213 | +
|
| 214 | + ### R2 Paths |
| 215 | + - Visual: \`baselines/v.$VERSION/<browser>/\` |
| 216 | + - Interactions: \`baselines-interactions/v.$VERSION/<browser>/\` |
| 217 | + EOF |
| 218 | +
|
| 219 | + - name: Summary (skipped) |
| 220 | + if: steps.version.outputs.skip == 'true' |
| 221 | + run: | |
| 222 | + cat >> $GITHUB_STEP_SUMMARY << EOF |
| 223 | + ## ⏭️ Baseline Generation Skipped |
| 224 | +
|
| 225 | + No release tag was found at the triggering commit. This typically means: |
| 226 | + - semantic-release determined no release was needed |
| 227 | + - The commit didn't include releasable changes |
| 228 | +
|
| 229 | + This is expected behavior and not an error. |
| 230 | + EOF |
| 231 | +
|
| 232 | + - name: Cleanup corpus cache |
| 233 | + if: always() |
| 234 | + run: | |
| 235 | + rm -rf ~/.cache/superdoc-corpus || true |
0 commit comments