Skip to content

Commit

Permalink
Merge pull request #60 from MinimaHQ/ppx
Browse files Browse the repository at this point in the history
[Experimental] PPX + dynamic forms support
  • Loading branch information
Alex Fedoseev authored Mar 21, 2020
2 parents ee453e2 + fafe4c8 commit eabee3a
Show file tree
Hide file tree
Showing 211 changed files with 18,702 additions and 4,154 deletions.
147 changes: 147 additions & 0 deletions .github/workflows/pipeline.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
name: re-formality pipeline

on:
pull_request:
branches:
- master

jobs:
build:
name: Build on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
node-version: [12.x]
os: [ubuntu-latest, macOS-latest, windows-latest]

steps:
- name: Checkout repo
uses: actions/checkout@v2

- 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)"

- 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') }}

- name: Install Yarn deps
run: |
yarn install
- name: Install Esy
run: |
npm install -g [email protected]
- name: Install Esy deps
run: |
cd lib
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
with:
path: ${{ steps.print-esy-cache.outputs.esy-cache }}
key: ${{ matrix.os }}-esy-${{ hashFiles('**/index.json') }}

- name: Build ppx
run: |
cd lib
esy build
- name: Build BuckleScript lib
run: |
cd lib
yarn bs:build
- name: Install public interface of BuckleScript lib
run: |
cd lib
yarn bs:install
- name: Run ppx tests
# FIXME: Snapshot tests are broken on Win
if: matrix.os != 'windows-latest'
run: |
cd lib
esy x test.exe
- name: Run integration tests
run: |
cd specs
yarn run test
- name: Upload artifacts
uses: actions/upload-artifact@v1
with:
name: ${{ matrix.os }}
path: lib/_build/default/bin/bin.exe

rc:
needs: build
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: 12.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/copy-binaries.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
53 changes: 53 additions & 0 deletions .github/workflows/scripts/copy-binaries.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/usr/bin/env node

const fs = require("fs");

const PPX = "re-formality-ppx";

let arch = process.arch;
let platform = process.platform;

if (arch === "ia32") {
arch = "x86";
}

if (platform === "win32") {
platform = "win";
}

const filename = `bin/${PPX}-${platform}-${arch}.exe`;

const supported = fs.existsSync(filename);

if (!supported) {
console.error(`${PPX} does not support this platform :(`);
console.error("");
console.error(`${PPX} comes prepacked as built binaries to avoid large`);
console.error("dependencies at build-time.");
console.error("");
console.error(`If you want ${PPX} to support this platform natively,`);
console.error("please open an issue at our repository, linked above. Please");
console.error(`specify that you are on the ${platform} platform,`);
console.error(`on the ${arch} architecture.`);

}

if (platform === "win") {
if (!fs.existsSync("ppx.exe")) {
copyFileSync(filename, "ppx.exe");
fs.chmodSync("ppx.exe", 0755);
}
} else {
if (!fs.existsSync("ppx")) {
copyFileSync(filename, "ppx");
fs.chmodSync("ppx", 0755);
}
}

function copyFileSync(source, dest) {
if (typeof fs.copyFileSync === "function") {
fs.copyFileSync(source, dest);
} else {
fs.writeFileSync(dest, fs.readFileSync(source));
}
}
15 changes: 15 additions & 0 deletions .github/workflows/scripts/print-esy-cache.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const fs = require("fs");
const os = require("os");
const path = require("path");

const ESY_FOLDER = process.env.ESY__PREFIX
? process.env.ESY__PREFIX
: path.join(os.homedir(), ".esy");

const esy3 = fs
.readdirSync(ESY_FOLDER)
.filter(name => name.length > 0 && name[0] === "3")
.sort()
.pop();

console.log(`::set-output name=esy-cache::${path.join(ESY_FOLDER, esy3, "i")}`);
43 changes: 43 additions & 0 deletions .github/workflows/scripts/write-package-json.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
const fs = require("fs");
const path = require("path");

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
);

fs.writeFileSync(
path.join(__dirname, "..", "..", "..", "_release", "package.json"),
packageJson,
{ encoding: "utf8" }
);
8 changes: 6 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
node_modules/
lib/
dist/
*/**/lib/
*/dist/
.merlin
.bsb.lock
*.bs.js
yarn-error.log
.cache
.DS_Store
_esy
_build
re-formality-ppx.install
lib/test/**/*.cm[itj]
11 changes: 0 additions & 11 deletions .travis.yml

This file was deleted.

71 changes: 71 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# Contributing

## Requesting a feature
If you would like to request a feature, please, [create an issue](https://github.com/MinimaHQ/re-formality/issues/new).

## Reporting a bug
If you want to report a bug, there are few options:
1. You can contribute a minimal falling test with your use case. It would make things easier for us to proceed with the fix.
2. You can contribute a minimal falling test and a fix. Even better :)
3. If you don't feel like contributing a test, please, [create an issue](https://github.com/MinimaHQ/re-formality/issues/new) with as many details as possible and we will try to figure out something.

### Contributing a test
There might be 2 types of issues:
1. Compile-time error.
2. Runtime error (related to logic or just runtime crashes).

If you are facing the former, add PPX test in [`lib/test`](./lib/test).<br>
If you are facing the latter, add integration test in [`specs`](./specs).

See the corresponding README for details.

It would be great if you could reduce your test case to minimal size. I.e. instead of copy/pasting code from your app as is, try to remove unrelated parts and keep only what's related to the error.

## Technical details
### Repository structure
```shell
- docs/ # Documentation
- examples/ # Examples
- lib/ # Library
- bin/ # PPX binary
- ppx/ # PPX sources
- sandbox/ # Sandbox for PPX debugging
- src/ # BuckleScript lib sources
- test/ # PPX tests
- specs/ # Integration tests
```

### Setup
This repo uses `yarn` workspaces to manage frontend related dependencies and `esy` to manage PPX related dependencies.

Install dependencies:

```shell
# Install yarn deps
yarn install

# Install esy deps
cd lib
esy install
```

Build PPX:

```shell
# In lib folder
esy build
```

Build BuckleScript library:

```shell
# In lib folder
yarn bsb -clean-world -make-world
```

Build public interface of the BuckleScript lib:

```shell
# In lib folder
yarn bsb -install
```
Loading

0 comments on commit eabee3a

Please sign in to comment.