|
| 1 | +name: Benchx CLI Publish |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + branches: |
| 6 | + - develop |
| 7 | + push: |
| 8 | + tags: |
| 9 | + - '*' |
| 10 | + workflow_call: |
| 11 | + inputs: |
| 12 | + skip_release: |
| 13 | + description: 'Skip the release job' |
| 14 | + required: false |
| 15 | + default: false |
| 16 | + type: boolean |
| 17 | + commit_ref: |
| 18 | + description: 'Commit SHA or branch name to build' |
| 19 | + required: false |
| 20 | + type: string |
| 21 | + workflow_dispatch: |
| 22 | + |
| 23 | +permissions: |
| 24 | + contents: write |
| 25 | + |
| 26 | +jobs: |
| 27 | + build: |
| 28 | + name: Build ${{ matrix.os_name }} ${{ matrix.arch_name }} |
| 29 | + runs-on: ${{ matrix.os }} |
| 30 | + env: |
| 31 | + SCCACHE_GHA_ENABLED: 'true' |
| 32 | + strategy: |
| 33 | + fail-fast: false |
| 34 | + matrix: |
| 35 | + include: |
| 36 | + - os: ubuntu-latest |
| 37 | + os_name: Linux |
| 38 | + arch_name: x86_64 |
| 39 | + - os: macos-latest |
| 40 | + os_name: Darwin |
| 41 | + arch_name: arm64 |
| 42 | + |
| 43 | + steps: |
| 44 | + - name: Checkout |
| 45 | + uses: actions/checkout@v4 |
| 46 | + with: |
| 47 | + ref: ${{ inputs.commit_ref || github.ref }} |
| 48 | + |
| 49 | + - name: Setup Node |
| 50 | + uses: actions/setup-node@v4 |
| 51 | + with: |
| 52 | + node-version: '24' |
| 53 | + |
| 54 | + - name: Setup sccache |
| 55 | + uses: mozilla-actions/sccache-action@v0.0.8 |
| 56 | + |
| 57 | + - name: Setup uv |
| 58 | + uses: astral-sh/setup-uv@v5 |
| 59 | + |
| 60 | + - name: Install Dependencies |
| 61 | + run: | |
| 62 | + # Configure sccache |
| 63 | + echo "SCCACHE_DIR=$GITHUB_WORKSPACE/.sccache" >> $GITHUB_ENV |
| 64 | + mkdir -p .sccache |
| 65 | +
|
| 66 | + # Show sccache stats before build |
| 67 | + sccache -z |
| 68 | +
|
| 69 | + uv venv |
| 70 | + uv pip install pip |
| 71 | +
|
| 72 | + # Ensure tools are executable |
| 73 | + chmod +x tools/hab || true |
| 74 | +
|
| 75 | + # Source envsetup to set paths for hab and other tools |
| 76 | + set +u |
| 77 | + source tools/envsetup.sh |
| 78 | +
|
| 79 | + echo "Syncing dependencies..." |
| 80 | + tools/hab sync . |
| 81 | +
|
| 82 | + - name: Build |
| 83 | + run: | |
| 84 | + set +u |
| 85 | + source tools/envsetup.sh |
| 86 | +
|
| 87 | + echo "Generating build files for ${{ matrix.os_name }} ${{ matrix.arch_name }}..." |
| 88 | +
|
| 89 | + # Base args |
| 90 | + ARGS='enable_unittests=true enable_trace="perfetto" jsengine_type="quickjs" enable_frozen_mode=true use_sccache=true' |
| 91 | +
|
| 92 | +
|
| 93 | + # Platform specific args |
| 94 | + if [[ "${{ matrix.os_name }}" == "Darwin" ]]; then |
| 95 | + ARGS="$ARGS use_flutter_cxx=false" |
| 96 | + fi |
| 97 | +
|
| 98 | + # Note: If cross-compilation is needed for arm64 on Linux, target_cpu arg would be needed |
| 99 | + # But here we are running on native runners (macos-latest is arm64, others x64) |
| 100 | +
|
| 101 | + echo "GN Args: $ARGS" |
| 102 | + gn gen --args="$ARGS" out/Default |
| 103 | +
|
| 104 | + echo "Building benchx_cli..." |
| 105 | + ninja -C out/Default cli/benchx:benchx_cli |
| 106 | +
|
| 107 | + # Show sccache stats after build |
| 108 | + sccache -s |
| 109 | +
|
| 110 | + - name: Verify benchx_cli |
| 111 | + run: | |
| 112 | + # Create temp directory |
| 113 | + TEST_DIR=$(mktemp -d) |
| 114 | + echo "Using temp dir: $TEST_DIR" |
| 115 | +
|
| 116 | + # 1. Download test bundle |
| 117 | + curl -L -o "$TEST_DIR/GalleryComplete.lynx.bundle" https://unpkg.com/@lynx-example/gallery@0.6.7/dist/GalleryComplete.lynx.bundle |
| 118 | +
|
| 119 | + # 2. Run benchx_cli |
| 120 | + out/Default/benchx_cli -o "$TEST_DIR/GalleryComplete.ptrace" run "$TEST_DIR/GalleryComplete.lynx.bundle" --wait 1000 |
| 121 | +
|
| 122 | + # 3. Download trace_processor |
| 123 | + # Download the downloader script |
| 124 | + curl -L -o "$TEST_DIR/trace_processor" https://get.perfetto.dev/trace_processor |
| 125 | + chmod +x "$TEST_DIR/trace_processor" |
| 126 | +
|
| 127 | + # 4. Verify trace content |
| 128 | + # Write SQL query to a file to handle multiple symbols cleanly |
| 129 | + # Using 'EOF' prevents shell expansion, making it safe for special characters |
| 130 | + cat > "$TEST_DIR/verify_symbols.sql" <<'EOF' |
| 131 | + SELECT name FROM slice WHERE |
| 132 | + name GLOB 'LynxEngine::LoadTemplate' |
| 133 | + OR name GLOB 'LynxShell::~LynxShell' |
| 134 | + OR name GLOB 'ReactLynx::diff::*' |
| 135 | + EOF |
| 136 | +
|
| 137 | + "$TEST_DIR/trace_processor" -q "$TEST_DIR/verify_symbols.sql" "$TEST_DIR/GalleryComplete.ptrace" > "$TEST_DIR/query_result.txt" |
| 138 | +
|
| 139 | + cat "$TEST_DIR/query_result.txt" |
| 140 | +
|
| 141 | + # Define expected symbols to check (one per line) |
| 142 | + cat > "$TEST_DIR/expected_symbols.txt" <<'EOF' |
| 143 | + LynxEngine::LoadTemplate |
| 144 | + LynxShell::~LynxShell |
| 145 | + ReactLynx::diff:: |
| 146 | + EOF |
| 147 | +
|
| 148 | + FAILED=0 |
| 149 | + while read -r SYMBOL; do |
| 150 | + [[ -z "$SYMBOL" ]] && continue |
| 151 | + if ! grep -qF "$SYMBOL" "$TEST_DIR/query_result.txt"; then |
| 152 | + echo "Error: Missing expected symbol '$SYMBOL' in trace output" |
| 153 | + FAILED=1 |
| 154 | + fi |
| 155 | + done < "$TEST_DIR/expected_symbols.txt" |
| 156 | +
|
| 157 | + if [ "$FAILED" -ne 0 ]; then |
| 158 | + echo "Verification Failed: One or more expected symbols are missing." |
| 159 | + exit 1 |
| 160 | + fi |
| 161 | +
|
| 162 | + echo "Verification Success: Found all expected symbols in trace." |
| 163 | +
|
| 164 | + # 5. Verify FiberElement Constructor/Destructor balance |
| 165 | + # Ensure every FiberElement::Constructor has a matching FiberElement::Destructor |
| 166 | + cat > "$TEST_DIR/verify_match.sql" <<'EOF' |
| 167 | + SELECT |
| 168 | + (SELECT COUNT(DISTINCT int_value) FROM args JOIN slice USING(arg_set_id) |
| 169 | + WHERE slice.name = 'FiberElement::Constructor' AND key = 'debug.id') as constructed_unique, |
| 170 | + (SELECT COUNT(DISTINCT int_value) FROM args JOIN slice USING(arg_set_id) |
| 171 | + WHERE slice.name = 'FiberElement::Destructor' AND key = 'debug.id') as destroyed_unique, |
| 172 | + (SELECT COUNT(*) FROM ( |
| 173 | + SELECT int_value FROM args JOIN slice USING(arg_set_id) |
| 174 | + WHERE slice.name = 'FiberElement::Constructor' AND key = 'debug.id' |
| 175 | + EXCEPT |
| 176 | + SELECT int_value FROM args JOIN slice USING(arg_set_id) |
| 177 | + WHERE slice.name = 'FiberElement::Destructor' AND key = 'debug.id' |
| 178 | + )) as diff_count; |
| 179 | + EOF |
| 180 | +
|
| 181 | + "$TEST_DIR/trace_processor" -q "$TEST_DIR/verify_match.sql" "$TEST_DIR/GalleryComplete.ptrace" > "$TEST_DIR/match_result.txt" |
| 182 | +
|
| 183 | + cat "$TEST_DIR/match_result.txt" |
| 184 | +
|
| 185 | + # Extract the counts from the last line (format: "constructed","destroyed","diff") |
| 186 | + LAST_LINE=$(tail -n 1 "$TEST_DIR/match_result.txt") |
| 187 | + CONSTRUCTED=$(echo "$LAST_LINE" | cut -d',' -f1) |
| 188 | + DESTROYED=$(echo "$LAST_LINE" | cut -d',' -f2) |
| 189 | + DIFF=$(echo "$LAST_LINE" | cut -d',' -f3) |
| 190 | +
|
| 191 | + echo "Constructed: $CONSTRUCTED, Destroyed: $DESTROYED, Diff: $DIFF" |
| 192 | +
|
| 193 | + # Verify that we have some constructions, and diff is 0 |
| 194 | + if [ "$DIFF" == "0" ] && [ "$CONSTRUCTED" -gt 0 ]; then |
| 195 | + echo "Verification Success: FiberElement Constructor/Destructor are balanced ($CONSTRUCTED objects)." |
| 196 | + else |
| 197 | + echo "Verification Failed: FiberElement imbalance or missing (Diff: $DIFF, Constructed: $CONSTRUCTED)." |
| 198 | + exit 1 |
| 199 | + fi |
| 200 | +
|
| 201 | + # Cleanup |
| 202 | + rm -rf "$TEST_DIR" |
| 203 | +
|
| 204 | + - name: Prepare and Package Artifacts |
| 205 | + run: | |
| 206 | + mkdir -p dist/bin |
| 207 | + BINARY_PATH="out/Default/benchx_cli" |
| 208 | +
|
| 209 | + if [ ! -f "$BINARY_PATH" ]; then |
| 210 | + echo "Error: Binary not found at $BINARY_PATH" |
| 211 | + ls -R out/Default |
| 212 | + exit 1 |
| 213 | + fi |
| 214 | +
|
| 215 | + echo "Found binary at $BINARY_PATH" |
| 216 | + cp "$BINARY_PATH" dist/bin/benchx_cli |
| 217 | +
|
| 218 | + # Create archive with specific naming format: benchx_cli_OS_Arch.tar.gz |
| 219 | + # e.g., benchx_cli_Darwin_arm64.tar.gz |
| 220 | + ARCHIVE_NAME="benchx_cli_${{ matrix.os_name }}_${{ matrix.arch_name }}.tar.gz" |
| 221 | +
|
| 222 | + cd dist/bin |
| 223 | + tar -czvf "../../$ARCHIVE_NAME" benchx_cli |
| 224 | + cd ../.. |
| 225 | +
|
| 226 | + echo "Created archive: $ARCHIVE_NAME" |
| 227 | +
|
| 228 | + - name: Upload Artifact |
| 229 | + uses: actions/upload-artifact@v4 |
| 230 | + with: |
| 231 | + name: build-artifact-${{ matrix.os_name }}-${{ matrix.arch_name }} |
| 232 | + path: benchx_cli_*.tar.gz |
| 233 | + |
| 234 | + release: |
| 235 | + name: Create Release |
| 236 | + needs: build |
| 237 | + if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/') && !inputs.skip_release |
| 238 | + runs-on: ubuntu-latest |
| 239 | + steps: |
| 240 | + - name: Download Artifacts |
| 241 | + uses: actions/download-artifact@v4 |
| 242 | + with: |
| 243 | + path: artifacts |
| 244 | + merge-multiple: true # Merge all artifacts into one directory |
| 245 | + |
| 246 | + - name: List Artifacts |
| 247 | + run: | |
| 248 | + ls -R artifacts |
| 249 | +
|
| 250 | + - name: Publish Release |
| 251 | + uses: softprops/action-gh-release@v2 |
| 252 | + with: |
| 253 | + files: artifacts/* |
0 commit comments