Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 110 additions & 0 deletions .github/workflows/js_hooks_test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
name: JSHooks Test sources

on:
push:
branches: ["dev", "candidate", "release", "jshooks"]
pull_request:
branches: ["dev", "candidate", "release", "jshooks"]

concurrency:
group: ${{ github.workflow }}
cancel-in-progress: false

jobs:
jshooks-test-sources:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y build-essential clang-format bc
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should pin a specific version of clang-format in some environment variable that be easily changed.

I noticed the other day that clang-format@19 would not work for some files.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that clang-format-10 is not provided in ubuntu-latest (ubuntu 22.04).

We can install clang-format-10 in ubuntu 20.04, but errors will occur around qjsc.

At the moment, there is no effect on SetJSHook_wasm.h, so I will leave it as it is.
If you could fix it, I would be very grateful.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I started working on extracting an action in #450

I'll make a PR to this once that's sorted we can just use that

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dangell7 wasn't a fan of touching the rippled shared clang-format workflow, in anticipation of merges, but I guess given this PR and #440 both install clang-format, we could use this action:

name: Install Clang-Format Ubuntu
description: Installs a specific version of clang-format on Ubuntu 20.04 and newer
inputs:
  clang-version:
    description: "Version of Clang-Format to install"
    required: true
    default: "10"

runs:
  using: "composite"
  steps:
    - name: Install Clang-Format
      run: |
        codename=$(lsb_release --codename --short)

        # Use modern key management for Ubuntu 20.04+ compatibility
        wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo tee /usr/share/keyrings/llvm-archive-keyring.gpg >/dev/null

        # Update LLVM repository sources
        echo "deb [signed-by=/usr/share/keyrings/llvm-archive-keyring.gpg] http://apt.llvm.org/${codename}/ llvm-toolchain-${codename}-${{ inputs.clang-version }} main" | sudo tee /etc/apt/sources.list.d/llvm.list
        echo "deb-src [signed-by=/usr/share/keyrings/llvm-archive-keyring.gpg] http://apt.llvm.org/${codename}/ llvm-toolchain-${codename}-${{ inputs.clang-version }} main" | sudo tee -a /etc/apt/sources.list.d/llvm.list

        # Update and install Clang-Format
        sudo apt-get update
        sudo apt-get install -y clang-format-${{ inputs.clang-version }}

        # Verify installation
        clang-format-${{ inputs.clang-version }} --version
      shell: bash

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the record, this is using clang-format 18 which seems to be fine for the file formatted by this.


- name: Clone quickjslite repository
run: |
# Clone only the latest commit with minimal data transfer
git clone --depth 1 https://github.com/RichardAH/quickjslite.git
# Get the HEAD commit hash for caching
cd quickjslite
COMMIT_HASH=$(git rev-parse HEAD)
echo "QUICKJSLITE_COMMIT_HASH=$COMMIT_HASH" >> $GITHUB_ENV
cd ..

- name: Cache qjsc binary
uses: actions/cache@v3
id: qjsc-cache
with:
path: src/test/app/qjsc
key: ${{ runner.os }}-qjsc-${{ env.QUICKJSLITE_COMMIT_HASH }}

- name: Build qjsc if not cached
if: steps.qjsc-cache.outputs.cache-hit != 'true'
run: |
# Build only qjsc
cd quickjslite
make qjsc
# Copy qjsc binary to the project root
cp qjsc ../src/test/app/
cd ..

- name: Copy qjsc from cache
if: steps.qjsc-cache.outputs.cache-hit == 'true'
run: |
# Ensure qjsc from cache is executable
chmod +x src/test/app/qjsc
echo "Using cached qjsc from commit ${{ env.QUICKJSLITE_COMMIT_HASH }}"

- name: Backup original SetJSHook_wasm.h
run: |
# Creating backup of the existing file
cp src/test/app/SetJSHook_wasm.h src/test/app/SetJSHook_wasm.h.original
echo "Original file backed up"

- name: Setup build environment
run: |
# Make scripts executable
chmod +x src/test/app/build_test_jshooks.sh
if [ -f src/test/app/build-js-carray.sh ]; then
chmod +x src/test/app/build-js-carray.sh
else
echo "Error: build-js-carray.sh not found"
ls -la src/test/app/
exit 1
fi

# Check if necessary test files exist
if [ ! -f src/test/app/SetJSHook_test.cpp ]; then
echo "Error: SetJSHook_test.cpp not found"
ls -la src/test/app/
exit 1
fi

- name: Run build_test_jshooks.sh
run: |
rm -f src/test/app/SetJSHook_wasm.h
src/test/app/build_test_jshooks.sh
# Check if output file was created
if [ ! -f src/test/app/SetJSHook_wasm.h ]; then
echo "Error: SetJSHook_wasm.h was not created"
exit 1
fi

- name: Check for differences
run: |
# Format original file for fair comparison
cp src/test/app/SetJSHook_wasm.h.original src/test/app/SetJSHook_wasm.h.original.formatted
clang-format -i src/test/app/SetJSHook_wasm.h.original.formatted

# Compare formatted files
if diff -u -q src/test/app/SetJSHook_wasm.h.original.formatted src/test/app/SetJSHook_wasm.h; then
echo "✅ SetJSHook_wasm.h is generated consistently with the original file!"
else
echo "❌ SetJSHook_wasm.h has differences compared to the original file!"
echo "Differences:"
diff -u src/test/app/SetJSHook_wasm.h.original.formatted src/test/app/SetJSHook_wasm.h
echo "Run 'src/test/app/build_test_jshooks.sh' to generate the SetJSHook_wasm.h file."
exit 1
fi
Loading
Loading