fix: Playwright package release build #1001
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Build | |
| on: | |
| pull_request: | |
| push: | |
| branches: | |
| - main | |
| tags: | |
| - "v*.*.*" | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v5 | |
| - name: Setup Zig | |
| uses: mlugg/setup-zig@v2 | |
| with: | |
| version: 0.15.2 | |
| - name: Install nasm | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y nasm | |
| - name: Cross-compile for all targets | |
| run: | | |
| zig build -Doptimize=ReleaseFast ci --verbose | |
| - name: Prepare binaries as artifacts | |
| run: | | |
| mkdir binaries | |
| cp zig-out/x86_64-linux/odiff binaries/odiff-linux-x64 | |
| cp zig-out/aarch64-linux/odiff binaries/odiff-linux-arm64 | |
| cp zig-out/riscv64-linux/odiff binaries/odiff-linux-riscv64 | |
| cp zig-out/riscv64-linux-rva23/odiff binaries/odiff-linux-riscv64-rva23 | |
| cp zig-out/x86_64-windows/odiff.exe binaries/odiff-windows-x64.exe | |
| cp zig-out/aarch64-windows/odiff.exe binaries/odiff-windows-arm64.exe | |
| cp zig-out/x86_64-macos/odiff binaries/odiff-macos-x64 | |
| cp zig-out/aarch64-macos/odiff binaries/odiff-macos-arm64 | |
| - name: Upload x86_64-linux artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| if-no-files-found: error | |
| name: odiff-linux-x64 | |
| path: binaries/odiff-linux-x64 | |
| retention-days: 14 | |
| - name: Upload aarch64-linux artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| if-no-files-found: error | |
| name: odiff-linux-arm64 | |
| path: binaries/odiff-linux-arm64 | |
| retention-days: 14 | |
| - name: Upload riscv64-linux artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| if-no-files-found: error | |
| name: odiff-linux-riscv64 | |
| path: binaries/odiff-linux-riscv64 | |
| retention-days: 14 | |
| - name: Upload riscv64-linux rva23 artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| if-no-files-found: error | |
| name: odiff-linux-riscv64-rva23 | |
| path: binaries/odiff-linux-riscv64-rva23 | |
| retention-days: 14 | |
| - name: Upload x86_64-windows artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| if-no-files-found: error | |
| name: odiff-windows-x64.exe | |
| path: binaries/odiff-windows-x64.exe | |
| retention-days: 14 | |
| - name: Upload aarch64-windows artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| if-no-files-found: error | |
| name: odiff-windows-arm64.exe | |
| path: binaries/odiff-windows-arm64.exe | |
| retention-days: 14 | |
| - name: Upload x86_64-macos artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| if-no-files-found: error | |
| name: odiff-macos-x64 | |
| path: binaries/odiff-macos-x64 | |
| retention-days: 14 | |
| - name: Upload aarch64-macos artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| if-no-files-found: error | |
| name: odiff-macos-arm64 | |
| path: binaries/odiff-macos-arm64 | |
| retention-days: 14 | |
| test: | |
| name: Run Tests (all targets) | |
| runs-on: ${{ matrix.os }} | |
| strategy: | |
| matrix: | |
| include: | |
| - target: x86_64-linux-gnu | |
| os: ubuntu-latest | |
| run_tests: true | |
| - target: x86_64-windows-gnu | |
| os: windows-latest | |
| run_tests: true | |
| - target: aarch64-macos | |
| os: macos-latest | |
| run_tests: true | |
| - target: riscv64-linux-gnu | |
| os: ubuntu-latest | |
| run_tests: false | |
| defaults: | |
| run: | |
| shell: bash | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v5 | |
| - name: Setup Zig | |
| uses: mlugg/setup-zig@v2 | |
| with: | |
| version: 0.15.2 | |
| - name: Install nasm for x86 targets (Linux) | |
| if: contains(matrix.target, 'x86_64') && runner.os == 'Linux' | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y nasm | |
| - name: Install nasm for x86 targets (macOS) | |
| if: contains(matrix.target, 'x86_64') && runner.os == 'macOS' | |
| run: | | |
| brew install nasm | |
| - name: Install nasm for x86 targets (Windows) | |
| if: contains(matrix.target, 'x86_64') && runner.os == 'Windows' | |
| run: | | |
| choco install -y nasm | |
| - name: Build and run tests | |
| if: matrix.run_tests == true | |
| run: | | |
| zig build -Dtarget=${{matrix.target}} test-all --summary all | |
| - name: Build without running tests | |
| if: matrix.run_tests != true | |
| run: | | |
| zig build -Dtarget=${{matrix.target}} | |
| test-avx: | |
| name: Run Tests (AVX x86_64) | |
| runs-on: ${{ matrix.os }} | |
| strategy: | |
| matrix: | |
| include: | |
| - target: x86_64-linux-gnu | |
| os: ubuntu-latest | |
| - target: x86_64-macos | |
| os: macos-latest | |
| defaults: | |
| run: | |
| shell: bash | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v5 | |
| - name: Setup Zig | |
| uses: mlugg/setup-zig@v2 | |
| with: | |
| version: 0.15.2 | |
| - name: Install nasm for x86 targets (Linux) | |
| if: contains(matrix.target, 'x86_64') && runner.os == 'Linux' | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y nasm | |
| - name: Install nasm for x86 targets (macOS) | |
| if: contains(matrix.target, 'x86_64') && runner.os == 'macOS' | |
| run: | | |
| brew install nasm | |
| - name: Run AVX tests | |
| run: | | |
| zig build test-all --summary all | |
| e2e-tests: | |
| name: JavaScript tests | |
| needs: [build] | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v5 | |
| - name: Download x86_64-linux artifact | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: odiff-linux-x64 | |
| path: zig-out/bin | |
| - name: Set up Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: "24" | |
| cache: "npm" | |
| - name: Install root dependencies | |
| run: npm ci --ignore-scripts | |
| - name: Prepare binary for tests | |
| run: | | |
| ls -la zig-out/bin/ | |
| cp zig-out/bin/odiff-linux-x64 zig-out/bin/odiff | |
| chmod +x zig-out/bin/odiff | |
| file zig-out/bin/odiff | |
| zig-out/bin/odiff --version | |
| - run: npm run test:js | |
| playwright-tests: | |
| name: Playwright visual regression tests | |
| needs: [build] | |
| runs-on: ubuntu-latest | |
| container: | |
| image: mcr.microsoft.com/playwright:v1.56.0-noble | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v5 | |
| - name: Download x86_64-linux artifact | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: odiff-linux-x64 | |
| path: zig-out/bin | |
| - name: Install root dependencies | |
| run: npm ci --ignore-scripts | |
| - name: Prepare binary for tests | |
| run: | | |
| ls -la zig-out/bin/ | |
| cp zig-out/bin/odiff-linux-x64 zig-out/bin/odiff | |
| cp zig-out/bin/odiff-linux-x64 npm_packages/odiff-bin/bin/odiff.exe | |
| chmod +x zig-out/bin/odiff | |
| chmod +x npm_packages/odiff-bin/bin/odiff.exe | |
| zig-out/bin/odiff --version | |
| - name: Build playwright-odiff package | |
| working-directory: npm_packages/playwright-odiff | |
| run: npm run build | |
| - name: Run Playwright tests | |
| working-directory: npm_packages/playwright-odiff | |
| run: npm test | |
| - name: Upload test results | |
| if: always() | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: test-results | |
| path: npm_packages/playwright-odiff/test-results | |
| retention-days: 7 | |
| valgrind: | |
| name: Valgrind Memory Check | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v5 | |
| - name: Setup Zig | |
| uses: mlugg/setup-zig@v2 | |
| with: | |
| version: 0.15.2 | |
| - name: Install nasm and valgrind | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y nasm valgrind | |
| - name: Build with debug symbols | |
| run: | | |
| zig build -Doptimize=Debug | |
| - name: Run valgrind memcheck - normal mode with diff output | |
| run: | | |
| valgrind --leak-check=full --show-leak-kinds=all --error-exitcode=1 --errors-for-leak-kinds=definite,possible \ | |
| ./zig-out/bin/odiff test/png/orange.png test/png/orange_changed.png /tmp/diff-output.png | |
| - name: Run valgrind memcheck - normal mode without diff output | |
| run: | | |
| valgrind --leak-check=full --show-leak-kinds=all --error-exitcode=1 --errors-for-leak-kinds=definite,possible \ | |
| ./zig-out/bin/odiff test/png/orange.png test/png/orange_changed.png | |
| - name: Run valgrind memcheck - server mode | |
| run: | | |
| timeout 5 valgrind --leak-check=full --show-leak-kinds=all --error-exitcode=1 --errors-for-leak-kinds=definite,possible \ | |
| ./zig-out/bin/odiff --server || [ $? -eq 124 ] | |
| spellcheck: | |
| name: Spell check | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v5 | |
| - name: Run typos | |
| uses: crate-ci/typos@master | |
| with: | |
| config: ./typos.toml | |
| publish: | |
| name: Publish release | |
| needs: [build, test, e2e-tests] | |
| if: startsWith(github.ref, 'refs/tags/') | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v5 | |
| - name: Download all built binaries | |
| uses: actions/download-artifact@v4 | |
| with: | |
| pattern: odiff-* | |
| merge-multiple: true | |
| path: binaries | |
| - name: Verify that we have 8 binaries | |
| run: | | |
| ls -la binaries | |
| [ $(ls -1 binaries | wc -l) -eq 8 ] || (echo "Expected 8 binaries" && exit 1) | |
| - name: Copy binaries to npm package (excluding rva23) | |
| run: | | |
| mkdir -p npm_packages/odiff-bin/raw_binaries | |
| find binaries -type f ! -name '*riscv64-linux-rva23*' -exec cp {} npm_packages/odiff-bin/raw_binaries/ \; | |
| - name: Set up Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: "24" | |
| cache: "npm" | |
| always-auth: true | |
| registry-url: "https://registry.npmjs.org" | |
| cache-dependency-path: "package-lock.json" | |
| - name: Copy root readme | |
| run: cp README.md npm_packages/odiff-bin/README.md | |
| - name: Publish odiff-bin package | |
| working-directory: npm_packages/odiff-bin | |
| run: npm publish | |
| env: | |
| NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | |
| - name: Build playwright-odiff package | |
| working-directory: npm_packages/playwright-odiff | |
| run: npm run build | |
| - name: Publish playwright-odiff package | |
| working-directory: npm_packages/playwright-odiff | |
| run: npm publish | |
| env: | |
| NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | |
| - name: Create github release | |
| uses: softprops/action-gh-release@v1 | |
| with: | |
| files: "binaries/*" | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| commit-sanity-check: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v5 | |
| - name: Verify binary was not commit in npm package folder | |
| run: | | |
| if ! file ./npm_packages/odiff-bin/bin/odiff.exe | grep -q "Node.js script executable"; then | |
| echo "Looks like you commited a local binary to ./npm_packages/odiff-bin/bin/odiff.exe. Please revert" | |
| exit 1 | |
| fi | |
| - name: Check docs in readme | |
| run: | | |
| npm run update-readme | |
| if ! git diff --quiet; then | |
| echo "Please run `npm run update-readme` and commit changes." | |
| exit 1 | |
| fi |