From d86a55354bc9448b1a8f6e6fa362877f5a077fde Mon Sep 17 00:00:00 2001 From: Alex Fedoseev Date: Mon, 26 Feb 2024 13:08:04 +0400 Subject: [PATCH] Update deps + switch to opam on CI --- .github/workflows/ci.yml | 301 ++++++++++++------ .../workflows/scripts/write-package-json.js | 53 ++- devbox.json | 21 +- devbox.lock | 44 ++- dune-project | 2 +- dune-workspace | 1 + ppx/bin/dune | 6 + re-formality-ppx.opam | 22 ++ 8 files changed, 295 insertions(+), 155 deletions(-) create mode 100644 dune-workspace diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d6b8b69c..03be8b11 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -4,15 +4,20 @@ on: pull_request: branches: - master + push: + branches: + - release jobs: - build: - name: Build on ${{ matrix.os }} - runs-on: ${{ matrix.os }} + check: + name: PR check + runs-on: ubuntu-latest + if: ${{ github.event_name == 'pull_request' && github.base_ref == 'master' }} strategy: matrix: + os: [ubuntu-latest] + ocaml-version: [4.14.1] node-version: [16.x] - os: [macOS-latest, windows-latest] steps: - name: Checkout repo @@ -25,37 +30,28 @@ jobs: - name: Print Yarn cache id: print-yarn-cache - run: echo "::set-output name=yarn-cache::$(yarn cache dir)" + run: echo "yarn-cache=$(yarn cache dir)" >> $GITHUB_OUTPUT - name: Restore Yarn cache id: yarn-cache uses: actions/cache@v1 with: path: ${{ steps.print-yarn-cache.outputs.yarn-cache }} - key: ${{ matrix.os }}-yarn-${{ hashFiles('**/yarn.lock') }} + key: ${{ matrix.os }}-yarn-${{ hashFiles('yarn.lock', '*/yarn.lock') }} - name: Install Yarn deps run: yarn install - - name: Install Esy - run: npm install -g esy@0.7.2 - - - name: Install Esy deps - run: esy install - - - name: Print Esy cache - id: print-esy-cache - run: node .github/workflows/scripts/print-esy-cache.js - - - name: Restore Esy cache - id: esy-cache - uses: actions/cache@v1 + - name: Setup OCaml ${{ matrix.ocaml-version }} + uses: ocaml/setup-ocaml@v2 with: - path: ${{ steps.print-esy-cache.outputs.esy-cache }} - key: ${{ matrix.os }}-esy-${{ hashFiles('**/index.json') }} + ocaml-compiler: ${{ matrix.ocaml-version }} + + - name: Install Opam deps + run: opam install . --deps-only --with-test - - name: Build ppx - run: esy build + - name: Build PPX + run: opam exec -- dune build - name: Build ReScript lib run: | @@ -64,69 +60,120 @@ jobs: cd ../examples yarn run build - - name: Run ppx tests - # FIXME: Snapshot tests are broken on Win - if: matrix.os != 'windows-latest' - run: esy x test.exe + - name: Run PPX tests + run: opam exec -- dune exec test.exe - name: Run integration tests run: | cd specs yarn run test + + build_linux: + name: Build on ${{ matrix.container-os }} + runs-on: ${{ matrix.host-os }} + # if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/release' }} + strategy: + matrix: + host-os: [ubuntu-latest] + container-os: [linux-alpine] + ocaml-version: [4.14.1] + node-version: [16.x] + container: + image: alex35mil/alpine-ocaml-opam-node-yarn:alpine-3.19-ocaml-4.14-node-16.20-yarn-1.22-o5gm + + steps: + - name: Checkout repo + uses: actions/checkout@v2 + + - name: Print Yarn cache + id: print-yarn-cache + run: echo "yarn-cache=$(yarn cache dir)" >> $GITHUB_OUTPUT + + - name: Restore Yarn cache + id: yarn-cache + uses: actions/cache@v1 + with: + path: ${{ steps.print-yarn-cache.outputs.yarn-cache }} + key: ${{ matrix.container-os }}-yarn-${{ hashFiles('yarn.lock', '*/yarn.lock') }} + + - name: Install Yarn deps + run: yarn install + + - name: Setup OCaml ${{ matrix.ocaml-version }} + run: opam init -a --disable-sandboxing --compiler=${{ matrix.ocaml-version }} + + - name: Install Opam deps + run: opam install . --deps-only --with-test + + - name: Build PPX + run: opam exec -- dune build --profile static + + - name: Build ReScript lib + run: | + cd lib + yarn run build + cd ../examples + yarn run build + + - name: Run PPX tests + run: opam exec -- dune exec test.exe + + # NOTE: Integration tests are broken on Alpine + # - name: Run integration tests + # run: | + # cd specs + # yarn run test + - name: Upload artifacts uses: actions/upload-artifact@v1 with: - name: ${{ matrix.os }} + name: ${{ matrix.container-os }} path: _build/default/ppx/bin/bin.exe - build_linux: + build_macos: name: Build on ${{ matrix.os }} runs-on: ${{ matrix.os }} + # if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/release' }} strategy: matrix: - os: [ubuntu-latest] - - container: - image: alexfedoseev/alpine-node-yarn-esy:0.0.10 + os: [macos-13, macos-14] + ocaml-version: [4.14.1] + node-version: [16.x] steps: - name: Checkout repo uses: actions/checkout@v2 - - name: Apply static linking patch - run: git apply linux.patch + - name: Setup Node ${{ matrix.node-version }} + uses: actions/setup-node@v1 + with: + node-version: ${{ matrix.node-version }} - name: Print Yarn cache id: print-yarn-cache - run: echo "::set-output name=yarn-cache::$(yarn cache dir)" + run: echo "yarn-cache=$(yarn cache dir)" >> $GITHUB_OUTPUT - name: Restore Yarn cache id: yarn-cache uses: actions/cache@v1 with: path: ${{ steps.print-yarn-cache.outputs.yarn-cache }} - key: ${{ matrix.os }}-yarn-${{ hashFiles('yarn.lock') }}-v1 + key: ${{ matrix.os }}-yarn-${{ hashFiles('yarn.lock', '*/yarn.lock') }} - name: Install Yarn deps run: yarn install - - name: Install Esy deps - run: esy install - - - name: Print Esy cache - id: print-esy-cache - run: node .github/workflows/scripts/print-esy-cache.js - - - name: Restore Esy cache - id: esy-cache - uses: actions/cache@v1 + - name: Setup OCaml ${{ matrix.ocaml-version }} + uses: ocaml/setup-ocaml@v2 with: - path: ${{ steps.print-esy-cache.outputs.esy-cache }} - key: ${{ matrix.os }}-esy-${{ hashFiles('esy.lock/index.json') }} + ocaml-compiler: ${{ matrix.ocaml-version }} - - name: Build ppx - run: esy build + - name: Install Opam deps + run: opam install . --deps-only --with-test + + - name: Build PPX + run: opam exec -- dune build - name: Build ReScript lib run: | @@ -135,14 +182,13 @@ jobs: cd ../examples yarn run build - - name: Run ppx tests - run: esy x test.exe + - name: Run PPX tests + run: opam exec -- dune exec test.exe - # FIXME: Integration tests are broken on Linux - # - name: Run integration tests - # run: | - # cd specs - # yarn run test + - name: Run integration tests + run: | + cd specs + yarn run test - name: Upload artifacts uses: actions/upload-artifact@v1 @@ -150,12 +196,15 @@ jobs: name: ${{ matrix.os }} path: _build/default/ppx/bin/bin.exe - rc: - needs: - - build - - build_linux - name: Prepare RC - runs-on: ubuntu-latest + build_windows: + name: Build on ${{ matrix.os }} + runs-on: ${{ matrix.os }} + # if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/release' }} + strategy: + matrix: + os: [windows-latest] + ocaml-version: [4.14.1] + node-version: [16.x] steps: - name: Checkout repo @@ -164,45 +213,107 @@ jobs: - name: Setup Node ${{ matrix.node-version }} uses: actions/setup-node@v1 with: - node-version: 16.x + node-version: ${{ matrix.node-version }} - - name: Download Linux artifacts - uses: actions/download-artifact@v1 - with: - name: ubuntu-latest - path: _bin/linux + - name: Print Yarn cache + id: print-yarn-cache + run: echo "::set-output name=yarn-cache::$(yarn cache dir)" # Using the old way as the new way doesn't work on windows - - name: Download macOS artifacts - uses: actions/download-artifact@v1 + - name: Restore Yarn cache + id: yarn-cache + uses: actions/cache@v1 with: - name: macOS-latest - path: _bin/darwin + path: ${{ steps.print-yarn-cache.outputs.yarn-cache }} + key: ${{ matrix.os }}-yarn-${{ hashFiles('yarn.lock', '*/yarn.lock') }} - - name: Download Windows artifacts - uses: actions/download-artifact@v1 + - name: Install Yarn deps + run: yarn install + + - name: Setup OCaml ${{ matrix.ocaml-version }} + uses: ocaml/setup-ocaml@v2 with: - name: windows-latest - path: _bin/windows + ocaml-compiler: ${{ matrix.ocaml-version }} - - name: Move artifacts + - name: Install Opam deps + run: opam install . --deps-only --with-test + + - name: Build PPX + run: opam exec -- dune build + + - name: Build ReScript lib run: | - mkdir -p _release/bin - mv _bin/darwin/bin.exe _release/bin/re-formality-ppx-darwin-x64.exe - mv _bin/windows/bin.exe _release/bin/re-formality-ppx-win-x64.exe - mv _bin/linux/bin.exe _release/bin/re-formality-ppx-linux-x64.exe - rm -rf _bin + cd lib + yarn run build + cd ../examples + yarn run build - - name: Move lib files + - name: Run PPX tests + run: opam exec -- dune exec test.exe + + - name: Run integration tests run: | - mkdir -p _release/src - cp README.md _release/README.md - cp lib/bsconfig.json _release/bsconfig.json - cp -a lib/src/. _release/src/ - cp .github/workflows/scripts/postinstall.js _release/postinstall.js - node .github/workflows/scripts/write-package-json.js - - - name: Upload release + cd specs + yarn run test + + - name: Upload artifacts uses: actions/upload-artifact@v1 with: - name: release - path: _release + name: ${{ matrix.os }} + path: _build/default/ppx/bin/bin.exe + + # rc: + # needs: + # - build + # - build_linux + # name: Prepare RC + # runs-on: ubuntu-latest + # + # steps: + # - name: Checkout repo + # uses: actions/checkout@v2 + # + # - name: Setup Node ${{ matrix.node-version }} + # uses: actions/setup-node@v1 + # with: + # node-version: 16.x + # + # - name: Download Linux artifacts + # uses: actions/download-artifact@v1 + # with: + # name: ubuntu-latest + # path: _bin/linux + # + # - name: Download macOS artifacts + # uses: actions/download-artifact@v1 + # with: + # name: macOS-latest + # path: _bin/darwin + # + # - name: Download Windows artifacts + # uses: actions/download-artifact@v1 + # with: + # name: windows-latest + # path: _bin/windows + # + # - name: Move artifacts + # run: | + # mkdir -p _release/bin + # mv _bin/darwin/bin.exe _release/bin/re-formality-ppx-darwin-x64.exe + # mv _bin/windows/bin.exe _release/bin/re-formality-ppx-win-x64.exe + # mv _bin/linux/bin.exe _release/bin/re-formality-ppx-linux-x64.exe + # rm -rf _bin + # + # - name: Move lib files + # run: | + # mkdir -p _release/src + # cp README.md _release/README.md + # cp lib/bsconfig.json _release/bsconfig.json + # cp -a lib/src/. _release/src/ + # cp .github/workflows/scripts/postinstall.js _release/postinstall.js + # node .github/workflows/scripts/write-package-json.js + # + # - name: Upload release + # uses: actions/upload-artifact@v1 + # with: + # name: release + # path: _release diff --git a/.github/workflows/scripts/write-package-json.js b/.github/workflows/scripts/write-package-json.js index e2b017b3..e7ad3323 100644 --- a/.github/workflows/scripts/write-package-json.js +++ b/.github/workflows/scripts/write-package-json.js @@ -1,43 +1,26 @@ const fs = require("fs"); const path = require("path"); -const { - name, - version, - description, - author, - license, - repository, - keywords -} = require("../../../package.json"); +const { name, version, description, author, license, repository, keywords } = require("../../../package.json"); const { dependencies } = require("../../../lib/package.json"); const packageJson = JSON.stringify( - { - name, - version, - description, - author, - license, - repository, - keywords, - dependencies, - files: [ - "src", - "bin", - "bsconfig.json", - "postinstall.js", - ], - scripts: { - postinstall: "node ./postinstall.js" - } - }, - null, - 2 + { + name, + version, + description, + author, + license, + repository, + keywords, + dependencies, + files: ["src", "bin", "rescript.json", "postinstall.js"], + scripts: { + postinstall: "node ./postinstall.js", + }, + }, + null, + 2, ); -fs.writeFileSync( - path.join(__dirname, "..", "..", "..", "_release", "package.json"), - packageJson, - { encoding: "utf8" } -); +fs.writeFileSync(path.join(__dirname, "..", "..", "..", "_release", "package.json"), packageJson, { encoding: "utf8" }); diff --git a/devbox.json b/devbox.json index 18b67441..018ac8a9 100644 --- a/devbox.json +++ b/devbox.json @@ -1,18 +1,15 @@ { "packages": [ - "path:./nix/ocaml#ocaml", - "path:./nix/ocaml#dune", - "path:./nix/ocaml#result", - "path:./nix/ocaml#findlib", - "path:./nix/ocaml#ppxlib", - "path:./nix/ocaml#alcotest", - "path:./nix/ocaml#merlin", - "path:./nix/ocaml#lsp", - "path:./nix/ocaml#ocamlformat", - "path:./nix/ocaml#ocamlformat_rpc", + "ocamlPackages.ocaml", + "ocamlPackages.dune_3", + "ocamlPackages.findlib", + "ocamlPackages.ppxlib", + "ocamlPackages.alcotest", + "ocamlPackages.ocaml-lsp", + "ocamlPackages.ocamlformat", + "ocamlPackages.ocamlformat-rpc-lib", "nodejs", - "yarn", - "awscli2" + "yarn" ], "shell": { "init_hook": [ diff --git a/devbox.lock b/devbox.lock index 96e49608..6f2a5df6 100644 --- a/devbox.lock +++ b/devbox.lock @@ -1,22 +1,42 @@ { "lockfile_version": "1", "packages": { - "awscli2": { - "resolved": "github:NixOS/nixpkgs/f80ac848e3d6f0c12c52758c0f25c10c97ca3b62#awscli2", - "source": "nixpkg" - }, "nodejs": { "resolved": "github:NixOS/nixpkgs/f80ac848e3d6f0c12c52758c0f25c10c97ca3b62#nodejs", "source": "nixpkg" }, - "path:./nix/ocaml#alcotest": {}, - "path:./nix/ocaml#dune": {}, - "path:./nix/ocaml#findlib": {}, - "path:./nix/ocaml#lsp": {}, - "path:./nix/ocaml#merlin": {}, - "path:./nix/ocaml#ocaml": {}, - "path:./nix/ocaml#ppxlib": {}, - "path:./nix/ocaml#result": {}, + "ocamlPackages.alcotest": { + "resolved": "github:NixOS/nixpkgs/75a52265bda7fd25e06e3a67dee3f0354e73243c#ocamlPackages.alcotest", + "source": "nixpkg" + }, + "ocamlPackages.dune_3": { + "resolved": "github:NixOS/nixpkgs/75a52265bda7fd25e06e3a67dee3f0354e73243c#ocamlPackages.dune_3", + "source": "nixpkg" + }, + "ocamlPackages.findlib": { + "resolved": "github:NixOS/nixpkgs/75a52265bda7fd25e06e3a67dee3f0354e73243c#ocamlPackages.findlib", + "source": "nixpkg" + }, + "ocamlPackages.ocaml": { + "resolved": "github:NixOS/nixpkgs/75a52265bda7fd25e06e3a67dee3f0354e73243c#ocamlPackages.ocaml", + "source": "nixpkg" + }, + "ocamlPackages.ocaml-lsp": { + "resolved": "github:NixOS/nixpkgs/75a52265bda7fd25e06e3a67dee3f0354e73243c#ocamlPackages.ocaml-lsp", + "source": "nixpkg" + }, + "ocamlPackages.ocamlformat": { + "resolved": "github:NixOS/nixpkgs/75a52265bda7fd25e06e3a67dee3f0354e73243c#ocamlPackages.ocamlformat", + "source": "nixpkg" + }, + "ocamlPackages.ocamlformat-rpc-lib": { + "resolved": "github:NixOS/nixpkgs/75a52265bda7fd25e06e3a67dee3f0354e73243c#ocamlPackages.ocamlformat-rpc-lib", + "source": "nixpkg" + }, + "ocamlPackages.ppxlib": { + "resolved": "github:NixOS/nixpkgs/75a52265bda7fd25e06e3a67dee3f0354e73243c#ocamlPackages.ppxlib", + "source": "nixpkg" + }, "yarn": { "resolved": "github:NixOS/nixpkgs/f80ac848e3d6f0c12c52758c0f25c10c97ca3b62#yarn", "source": "nixpkg" diff --git a/dune-project b/dune-project index ad918f3f..63fc91b5 100644 --- a/dune-project +++ b/dune-project @@ -1,2 +1,2 @@ (lang dune 2.6) - (name re-formality-ppx) +(name re-formality-ppx) diff --git a/dune-workspace b/dune-workspace new file mode 100644 index 00000000..e8b83749 --- /dev/null +++ b/dune-workspace @@ -0,0 +1 @@ +(lang dune 2.6) diff --git a/ppx/bin/dune b/ppx/bin/dune index b346a3c5..b0d97d6f 100644 --- a/ppx/bin/dune +++ b/ppx/bin/dune @@ -1,4 +1,10 @@ +(env + (static + (flags + (:standard -ccopt -static)))) + (executable + (package re-formality-ppx) (name bin) (public_name re-formality-ppx) (libraries re-formality-ppx.lib)) diff --git a/re-formality-ppx.opam b/re-formality-ppx.opam index e69de29b..3c9317e1 100644 --- a/re-formality-ppx.opam +++ b/re-formality-ppx.opam @@ -0,0 +1,22 @@ +opam-version: "2.0" +name: "re-formality-ppx" +version: "4.0.0-beta.20" +synopsis: "Form validation tool for @rescript/react" +description: """ +Form validation tool for @rescript/react +""" +maintainer: "Alex Fedoseev " +authors: "Alex Fedoseev " +license: "MIT" +homepage: "https://github.com/MinimaHQ/re-formality.git" +bug-reports: "https://github.com/MinimaHQ/re-formality/issues" +dev-repo: "git+https://github.com/MinimaHQ/re-formality.git" +depends: [ + "ocaml" { = "4.14.1" } + "dune" { = "3.5.0" } + "ppxlib" { = "0.30.0" } + "alcotest" { = "1.7.0" } +] +build: [ + ["dune" "build" "-p" name "-j" jobs] +]