Skip to content

Commit

Permalink
Release version 0.2.0 on NPM and include pre-built binaries
Browse files Browse the repository at this point in the history
This adds Windows and Mac CI and binary bundling
  • Loading branch information
mhallin committed Feb 10, 2018
1 parent 63f2655 commit 973f917
Show file tree
Hide file tree
Showing 11 changed files with 249 additions and 27 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/_build
/bin
/graphql_ppx.native
/node_modules
/tests/lib
Expand Down
3 changes: 3 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
/_build
/.vscode
/graphql_ppx.native
/node_modules
/tests/lib
/tests_apollo/lib
/lib
/ppx
/graphql_ppx.*
/doc
/lib
/ci
/src
76 changes: 64 additions & 12 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,72 @@
language: node_js
language: generic

node_js:
- "8"
os:
- linux
- osx

addons:
apt:
sources:
- avsm
packages:
- ocaml
- ocaml-native-compilers
- camlp4-extra
- opam

before_install:
- sudo add-apt-repository ppa:avsm/ppa -y
- sudo apt-get -qq update
- sudo apt-get install -y ocaml ocaml-native-compilers camlp4-extra opam
- OPAMYES=1 opam init
- bash -e ci/travis_before_install.sh
- if [ "$TRAVIS_OS_NAME" = "osx" ]; then export TARGET_NAME=darwin-x64; export OCAMLBUILDFLAGS=""; fi
- if [ "$TRAVIS_OS_NAME" = "linux" ]; then export TARGET_NAME=linux-x64; export OCAMLBUILDFLAGS="-lflags '-ccopt -static'"; fi
- eval `opam config env`

before_script:
- ln -fs graphql_ppx.native ppx
- yarn
- IS_GRAPHQL_PPX_CI=true yarn
- OPAMYES=1 opam pin add graphql_ppx . -n
- OPAMYES=1 opam install graphql_ppx --deps-only

script:
- OPAMYES=1 opam pin add graphql_ppx .
- make
- make test
- make "OCAMLBUILDFLAGS=$OCAMLBUILDFLAGS"
- make test "OCAMLBUILDFLAGS=$OCAMLBUILDFLAGS"
- cp _build/src/graphql_ppx.native graphql_ppx-$TARGET_NAME.exe

deploy:
provider: releases
skip_cleanup: true
file_glob: true
file: graphql_ppx-*.exe
api_key:
secure: "xFRAioN2zdN/iDNFNTzjTp+bRPBxpdokJRYCWo4sA4FExvSrf5pibHGjapmESTdWkSziNHVWDqQr8oWeN93sGEuPn/faKhhqtn8ikeqMpB9PVIc/1X9+ScIWD9meMG8hPEDJsD5W/dgsJs75M4P9bmVDKvQ4X96rSyl0r5RRRFqTHc4Irc1Io5XoLSftuA++DVFvDUAlrfOHguGRK1LtMcDX7ei8CTbiTrYshn6LabeqV12nVxVYCqKQROqQ/RQCFtRvWKe6z98Zp1roOafX4X4k9Q0w5BUx6x7hniOQoaQZpyZukrOlAqwJsURxiH+MrwJPv52steFz2CXPTSPY6LTHlmc39yhULmnkwMIFjJGQJQbgmb+7XWMfZZV5he7OarnqiCVJRIoTvOMbPfKEhswns4mf1NrEsSBoWJMGAot+q8/Gx5eMZaPRnr8SNYL5e3TJmu7g/J/0nJb7gZHZieljiZotwadS1AA2JUoqhPnkuZpVK9xMXOVbzOUuqhOF3P/fbT2FTpMjCtUPxpf0A7nBC92kb5uVKw/WKQVZUe3D1fjh/a8dzUPHyQ9a+7wnfOPId36GM0tFGZhvpuFgt/+lCh7d1MJFOvn5Y3nPIqUHJT6pWvLckBCY//lUkVF7d5ddXrEXNywA62ZOYojPK5qYQIGyWNeE9x8kpiVaYfs="
on:
tags: true


jobs:
include:
- stage: Wait for Windows binaries to become available
addons:
apt:
sources: []
packages: []
before_install: skip
before_script: skip
deploy: []
script: bash -e ci/wait_for_builds.sh

- stage: Deploy to npmjs
addons:
apt:
sources: []
packages: []
before_install: skip
before_script: skip
script:
- bash -e ci/download_binaries.sh
deploy:
provider: npm
email: [email protected]
api_key:
secure: "WrVb4p1hoobkvcL5B0Tx+6H/+6wNqJbHc5/BfsXCLautjk4kEjgWFfpNOGKtww+vXm2O/huzmkJgoieRUXFmTxD/enC0jWthv5JCCtGPtBNjvPGv000M0PNoamcy9Cmmn9NbJ8oAjCp8vDH9TLnielP7sPnUtqiBbi0igzcQu7UJoXgN+oCcs0d+L4rGHDD+EyJ5UugcXWefY9U/vWzec5fcIjazATMjl1yIGn9Mq4ldFp/ekzsOMXf5rlVeN0UZJ8tsAMY+tdMruZgmqC/h4f/nVeVxXaGqF/2AWlfdD/YGIN8HABK1Z6yHp1JHiG4BbY6r3OIygiva2FMXVS5MOpFIpfgr65LvMvV01M9KrQrTSF44cCJBmtYJdmDjvgvBSAY4Ifzl1DpD96W9SW5pRXXIPEGpn1ByTJYZiXs1I4T0T6hEWSNIHMX0TASR/bhyvC38MfoSd9/RmRH89avN4v+5jeSaIJPwVHxzvieF9iD+i+sFUMLDcEbcLRDhhIuEfsgzEW4lf0iVJC2/EvissQu64nYWAv0dKr1I/K+ahn9uWnrWBxFGbLIJydDQieLGtu1sfjfEuroLH+no6mpHeGAQQ4GYDJ38WtDxzmAOn5HolotKMsLG3GgYiNrmyoWA55LRRiWcEoYj4Spe/nAd/dCjjms82SezNK9a7/D2VJI="
on:
tags: true
skip_cleanup: true
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ build:
-package yojson \
-package ppx_tools.metaquot \
-I src \
$(OCAMLBUILDFLAGS) \
graphql_ppx.native
rm graphql_ppx.native
cp _build/src/graphql_ppx.native .

test: build tests/graphql_schema.json
(cd tests && \
Expand Down
24 changes: 14 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,17 @@ Bucklescript standard library.
## Installation

Assuming that you've already got a Bucklescript project set up, installing this
syntax extension consists of three steps:
syntax extension consists of two steps:

First, install the [OPAM](https://opam.ocaml.org) package to download and build
the transform itself:

```sh
opam install graphql_ppx
```

Next, add this package as a dependency to your `package.json`:
First, add this package as a dependency to your `package.json`:

```sh
yarn add --dev graphql_ppx
# or, if you use npm:
npm install --saveDev graphql_ppx
```

Finally, add the PPX to your `bsconfig.json`:
Second, add the PPX to your `bsconfig.json`:

```json
{
Expand All @@ -48,6 +41,11 @@ Finally, add the PPX to your `bsconfig.json`:
**Note**: If you want to use this, make sure to read the limitations at the
bottom of this readme first!

### Upgrading from older versions

The OPAM package `graphql_ppx` is no longer needed. If you've used an earlier
version of this PPX you can safely remove this package.

## Examples

If you add a field that does not exist, you'll get a compiler error on the exact
Expand Down Expand Up @@ -377,3 +375,9 @@ let heroQuery = HeroQuery.make ();
/* This is no longer a string, but rather an object structure */
let query = heroQuery##query;
```

## Building manually on unsupported platforms

graphql_ppx supports 64 bit Linux, Windows, and macOS, as well as 32 bit
Windows out of the box. If you're on any other platform, please open an issue
on this repository so we can support it.
51 changes: 51 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
platform:
- x64

environment:
matrix:
- FORK_USER: ocaml
FORK_BRANCH: master
CYG_ROOT: C:\cygwin64
OPAM_SWITCH: 4.02.3+mingw64c
PACKAGE: graphql_ppx
OPAMYES: 1
INSTALL: false
REVDEPS: false
IS_GRAPHQL_PPX_CI: true
TARGET_PLATFORM: win-x64

- FORK_USER: ocaml
FORK_BRANCH: master
CYG_ROOT: C:\cygwin
OPAM_SWITCH: 4.02.3+mingw32c
PACKAGE: graphql_ppx
OPAMYES: 1
INSTALL: false
REVDEPS: false
IS_GRAPHQL_PPX_CI: true
TARGET_PLATFORM: win-x86

install:
- ps: Install-Product node LTS
- ps: iex ((new-object net.webclient).DownloadString("https://raw.githubusercontent.com/$env:FORK_USER/ocaml-ci-scripts/$env:FORK_BRANCH/appveyor-install.ps1"))
- yarn

build_script:
- call %CYG_ROOT%\bin\bash.exe -l %APPVEYOR_BUILD_FOLDER%\appveyor-opam.sh
- call %CYG_ROOT%\bin\bash.exe -l -c "cd /cygdrive/c/projects/graphql-ppx && make build"

test_script:
- node node_modules/gql-tools/cli/gqlschema.js -o tests/graphql_schema.json tests/schema.gql
- call %CYG_ROOT%\bin\bash.exe -l -c "cd /cygdrive/c/projects/graphql-ppx && make test"
- copy graphql_ppx.native graphql_ppx-%TARGET_PLATFORM%.exe

artifacts:
- path: graphql_ppx-*.exe

deploy:
provider: GitHub
auth_token:
secure: cNoylUr8IbJuXONnyQFAUTNzU0GsZkq4mnAhvyzqPgbtesQSJM0rCJGDPhLjMHo+
artifact: /graphql_ppx-.*\.exe/
on:
appveyor_repo_tag: true
14 changes: 14 additions & 0 deletions ci/download_binaries.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
set -e

if [ -z "$TRAVIS_TAG" ]; then
echo "TRAVIS_TAG variable empty, will not download binaries"
exit 0
fi

BASE_URL=https://github.com/mhallin/graphql_ppx/releases/download/$TRAVIS_TAG/graphql_ppx-

mkdir -p bin

for platform in linux-x64 darwin-x64 win-x64 win-x86; do
(cd bin && curl -fOL $BASE_URL$platform.exe)
done
24 changes: 24 additions & 0 deletions ci/travis_before_install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash

set -e

case "$TRAVIS_OS_NAME" in
osx)
brew update
brew install aspcud awscli yarn opam ocaml
curl -L https://github.com/aktau/github-release/releases/download/v0.7.2/darwin-amd64-github-release.tar.bz2 | tar xjf -
mv bin/darwin/amd64/github-release .
;;
linux)
source "$HOME/.nvm/nvm.sh"
nvm install 9
nvm use 9
curl -L https://github.com/aktau/github-release/releases/download/v0.7.2/linux-amd64-github-release.tar.bz2 | tar xjf -
mv bin/linux/amd64/github-release .
;;
esac

OPAMYES=1 opam init
OPAMYES=1 opam switch 4.02.3

eval `opam config env`
28 changes: 28 additions & 0 deletions ci/wait_for_builds.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
set -e

if [ -z "$TRAVIS_TAG" ]; then
echo "TRAVIS_TAG variable empty, will not wait for builds"
exit 0
fi

CURL="curl -ifs"
BASE_URL=https://github.com/mhallin/graphql_ppx/releases/download/$TRAVIS_TAG/graphql_ppx-
START_TIME=$(date "+%s")

## Wait at most 30 minutes for all platform binaries to be ready

for platform in linux-x64 darwin-x64 win-x64 win-x86; do
echo Checking binary for $platform

while ! $CURL $BASE_URL$platform.exe > /dev/null; do
if [ $(( $(date "+%s") - $START_TIME )) -gt 1800 ]; then
echo Timed out waiting for builds to finish
exit 1
fi

echo Build task for $platform not yet finished, waiting...
sleep 10
done
done

echo 'All binaries found'
43 changes: 43 additions & 0 deletions copyPlatformBinaryInPlace.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/usr/bin/env node

var fs = require('fs');

var arch = process.arch;
var platform = process.platform;

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

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

var filename = 'bin/graphql_ppx-' + platform + '-' + arch + '.exe';
var supported = fs.existsSync(filename);

if (!supported) {
console.error('graphql_ppx does not support this platform :(');
console.error('');
console.error('graphql_ppx comes prepacked as built binaries to avoid large');
console.error('dependencies at build-time.');
console.error('');
console.error('If you want graphql_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 (!process.env.IS_GRAPHQL_PPX_CI) {
process.exit(1);
}
}

if (process.env.IS_GRAPHQL_PPX_CI) {
console.log('graphql_ppx: IS_GRAPHQL_PPX_CI has been set, skipping moving binary in place');
process.exit(0);
}

if (!fs.existsSync('ppx')) {
fs.copyFileSync(filename, 'ppx');
fs.chmodSync('ppx', 0755);
}
9 changes: 4 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "graphql_ppx",
"version": "0.0.1",
"version": "0.2.0",
"description": "GraphQL PPX rewriter for Bucklescript/ReasonML",
"main": "index.js",
"repository": "https://github.com/mhallin/graphql_ppx",
Expand All @@ -9,17 +9,16 @@
"bin": {
"send-introspection-query": "./sendIntrospectionQuery.js"
},
"scripts": {
"postinstall": "node copyPlatformBinaryInPlace.js"
},
"devDependencies": {
"@glennsl/bs-jest": "^0.3.2",
"bs-platform": "^2.1.0",
"gql-tools": "^0.0.15",
"graphql": "^0.12.3",
"graphql-tag": "^2.6.1"
},
"scripts": {
"preinstall": "if [ ! -x \"$(opam config var graphql_ppx:bin)/graphql_ppx.native\" ]; then echo 'You must install graphql_ppx through opam before using this package. Run `opam install graphql_ppx`'; fi",
"postinstall": "if [ ! -e ./ppx ]; then ln -fs \"$(opam config var graphql_ppx:bin)/graphql_ppx.native\" ./ppx; fi"
},
"dependencies": {
"request": "^2.82.0",
"yargs": "^11.0.0"
Expand Down

0 comments on commit 973f917

Please sign in to comment.