Skip to content
Draft
101 changes: 75 additions & 26 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,41 @@ jobs:
runs-on: ubuntu-latest
outputs:
reduced: ${{ github.event_name == 'workflow_dispatch' || github.event.pull_request.draft == true || (github.event_name == 'push' && github.ref_type == 'branch' && github.repository != 'simplex-chat/simplexmq') }}
resolver: ${{ steps.changes.outputs.resolver }}
steps:
- name: Reject a manual run on a tag
if: github.event_name == 'workflow_dispatch' && github.ref_type == 'tag'
run: |
echo "::error::A manual run starts on a branch; to retry a release, re-run the jobs of its tag push."
exit 1

- name: Clone project to check changes
if: github.event_name != 'push'
uses: actions/checkout@v3
with:
fetch-depth: 2

- name: Check changes
id: changes
shell: bash
env:
GH_TOKEN: ${{ github.token }}
run: |
case "$GITHUB_EVENT_NAME" in
pull_request)
base=HEAD^1
;;
workflow_dispatch)
base=$(gh api "repos/$GITHUB_REPOSITORY/compare/master...$GITHUB_REF_NAME" --jq .merge_base_commit.sha)
git fetch -q --depth=1 origin "$base"
;;
*)
echo "resolver=true" >> "$GITHUB_OUTPUT"
exit 0
;;
esac
git diff --quiet "$base" HEAD -- scripts/resolver/service .github/workflows/build.yml || echo "resolver=true" >> "$GITHUB_OUTPUT"

- name: Clone project
if: startsWith(github.ref, 'refs/tags/v')
uses: actions/checkout@v3
Expand Down Expand Up @@ -95,6 +123,7 @@ jobs:
cache_o0: ${{ github.event_name == 'push' && (github.ref == 'refs/heads/master' || github.ref == 'refs/heads/stable') }}
image_cache: ghcr.io/${{ github.repository_owner }}/simplexmq-build-cache:${{ matrix.os }}-${{ matrix.arch }}-ghc${{ matrix.ghc }}
source_hashes: dist-newstyle/sources.sha256
resolver: ${{ needs.maybe-release.outputs.resolver == 'true' && matrix.os == '24.04' && matrix.arch == 'x86-64' && matrix.client_postgres != true }}
runs-on: ${{ matrix.runner }}
services: &build-services
postgres:
Expand Down Expand Up @@ -158,6 +187,52 @@ jobs:
with:
submodules: recursive

- name: Set up uv
if: env.resolver == 'true'
# uv takes Python from .python-version, the version of the Dockerfile's runtime stage.
uses: astral-sh/setup-uv@c18668ad3cf93ea998bef934396af7bb5c839dc7 # v10.2.0

- name: Lint resolver
if: env.resolver == 'true'
working-directory: scripts/resolver/service
run: uv run --frozen ruff check .

- name: Set up Node
if: env.resolver == 'true'
uses: actions/setup-node@v7
with:
node-version: 22

- name: Build names dev chain
if: env.resolver == 'true'
env:
SNRC_DEV_CHAIN: ${{ runner.temp }}/dev-chain
SIMPLEX_DOMAINS_REPO: https://github.com/simplex-chat/simplex.domains
SIMPLEX_DOMAINS_COMMIT: 65f02f1faa53bc350d8bc63e35b7d411cce4406a
run: |
git clone -q --filter=blob:none "$SIMPLEX_DOMAINS_REPO" "$SNRC_DEV_CHAIN/simplex.domains"
cd "$SNRC_DEV_CHAIN/simplex.domains"
git checkout -q "$SIMPLEX_DOMAINS_COMMIT"
for stage in contracts anvil; do
docker build -q --target "$stage" -t "names-$stage" -f webapp/dev/Dockerfile .
done
mkdir "$SNRC_DEV_CHAIN/ens-contracts"
contracts=$(docker create names-contracts)
docker cp "$contracts:/src/ens-contracts/artifacts" "$SNRC_DEV_CHAIN/ens-contracts/artifacts"
docker rm "$contracts"
anvil=$(docker create names-anvil)
docker cp "$anvil:/usr/local/bin/anvil" "$SNRC_DEV_CHAIN/anvil"
docker rm "$anvil"
cd webapp
npm ci --no-audit --no-fund

- name: Test resolver
if: env.resolver == 'true'
working-directory: scripts/resolver/service
env:
SNRC_DEV_CHAIN: ${{ runner.temp }}/dev-chain
run: uv run --frozen pytest -v

- name: Set up Docker Buildx
if: matrix.should_run == true
uses: simplex-chat/docker-setup-buildx-action@v3
Expand Down Expand Up @@ -552,29 +627,3 @@ jobs:
should_run: true
client_postgres: true
steps: *build-steps

# =============================
# Resolver test job
# =============================

# The SNRC resolver is Python, so this job needs none of the Haskell toolchain
# above and runs independently of it.

resolver-test:
name: "resolver (python)"
runs-on: ubuntu-latest
steps:
- name: Clone project
uses: actions/checkout@v3

- name: Set up uv
# uv takes Python from .python-version, the version of the Dockerfile's runtime stage.
uses: astral-sh/setup-uv@c18668ad3cf93ea998bef934396af7bb5c839dc7 # v10.2.0

- name: Lint
working-directory: scripts/resolver/service
run: uv run --frozen ruff check .

- name: Test
working-directory: scripts/resolver/service
run: uv run --frozen pytest -v
26 changes: 26 additions & 0 deletions .github/workflows/resolver-mainnet.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: resolver mainnet

on:
schedule:
- cron: "17 6 * * *"
workflow_dispatch:
pull_request:
paths:
- .github/workflows/resolver-mainnet.yml

jobs:
mainnet:
name: "resolver on mainnet"
runs-on: ubuntu-latest
steps:
- name: Clone project
uses: actions/checkout@v3

- name: Set up uv
uses: astral-sh/setup-uv@c18668ad3cf93ea998bef934396af7bb5c839dc7 # v10.2.0

- name: Test known names
working-directory: scripts/resolver/service
env:
SNRC_MAINNET_RPC: ${{ secrets.SNRC_MAINNET_RPC || 'https://ethereum-rpc.publicnode.com' }}
run: uv run --frozen pytest -v test_ground_truth.py -k MainnetTests
12 changes: 11 additions & 1 deletion scripts/ci/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,17 @@
| a push to a draft pull request<br>a manual run (workflow_dispatch)<br>a push to master or stable in a fork | reduced | build-reduced: 2 entries, ubuntu-24.04 x86-64, GHC 9.6.3, at -O0 (-O2 on pushes), without the standard build |
| a pull request marked ready for review, and later pushes to it<br>a push to master or stable in simplex-chat/simplexmq<br>a push of a v* tag | full | build: 6 entries (GHC 8.10.7 and 9.6.3, x86-64 and aarch64), at -O0 on pull requests and -O2 on pushes |

Both builds also run maybe-release and resolver (python). Tests run on the x86-64 entries, after xftp-web is built with Node.js 22 (`npm install`, `npm run build`) for the XFTP Web Client tests. In both builds, the ubuntu-24.04 x86-64 entry named "PostgreSQL agent store" builds and runs only the tests built with `-fclient_postgres -fslow_servers` (agent with the PostgreSQL store, and XFTP servers that delay responses for the slow-server test, which the other builds skip), in the build directory dist-client-postgres, in step "Test with PostgreSQL agent store", in parallel with the other entries; its build directory has its own cache key. After the tests, step "Check generated files" fails if a test changed a tracked file: the schema dump and query plan tests overwrite their files, so a stale file fails here even when the test passes on retry. The reduced build restores the -O0 build caches saved by master pushes; the Docker image cache is tagged by ISO week, so the first run of a week rebuilds the image.
Both builds also run maybe-release. Tests run on the x86-64 entries, after xftp-web is built with Node.js 22 (`npm install`, `npm run build`) for the XFTP Web Client tests. In both builds, the ubuntu-24.04 x86-64 entry named "PostgreSQL agent store" builds and runs only the tests built with `-fclient_postgres -fslow_servers` (agent with the PostgreSQL store, and XFTP servers that delay responses for the slow-server test, which the other builds skip), in the build directory dist-client-postgres, in step "Test with PostgreSQL agent store", in parallel with the other entries; its build directory has its own cache key. After the tests, step "Check generated files" fails if a test changed a tracked file: the schema dump and query plan tests overwrite their files, so a stale file fails here even when the test passes on retry. The reduced build restores the -O0 build caches saved by master pushes; the Docker image cache is tagged by ISO week, so the first run of a week rebuilds the image.

The ubuntu-24.04 x86-64 entry without the PostgreSQL agent store also lints and tests the resolver (scripts/resolver/service, steps "Lint resolver" and "Test resolver"):
- on a push;
- on a pull request or a manual run that changes scripts/resolver/service or build.yml. A manual run is compared with its merge base with master.

In "Build names dev chain", the `contracts` and `anvil` stages of `webapp/dev/Dockerfile` of simplex.domains, at the commit set in the step, are built, the compiled ens-contracts artifacts and anvil are copied out of them, and the webapp's dependencies are installed. In test_ground_truth.py, anvil is started, the `.simplex` contracts are deployed and seeded with the webapp's `dev/deploy.ts`, the other states the tests need are seeded over JSON-RPC, and the resolver's answer for each seeded name is checked.

`resolver-mainnet.yml` checks the resolver's answers for known mainnet names daily, on a manual run and on a pull request that changes it. The RPC is the secret `SNRC_MAINNET_RPC`, or a public endpoint without it.

Local run: scripts/resolver/README.md, "Resolver API reference".

## Test selection

Expand Down
7 changes: 7 additions & 0 deletions scripts/resolver/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,13 @@ uv run pytest
uv run ruff check .
```

`test_ground_truth.py` runs only with its variables set: `SNRC_DEV_CHAIN`, a directory with `anvil`, `ens-contracts/artifacts` and a simplex.domains checkout in `simplex.domains` with its webapp's dependencies installed, prepared as in the CI step "Build names dev chain", with Node.js 22.18 or later, and `SNRC_MAINNET_RPC`, a mainnet JSON-RPC endpoint:

```sh
SNRC_DEV_CHAIN=../dev-chain uv run pytest test_ground_truth.py
SNRC_MAINNET_RPC=https://ethereum-rpc.publicnode.com uv run pytest test_ground_truth.py -k MainnetTests
```

Dependencies are locked in `uv.lock`; the Docker image installs exactly those.

Three routes, versioned separately from the protocol so each only changes when
Expand Down
Loading
Loading