Skip to content

Commit

Permalink
CI (#4)
Browse files Browse the repository at this point in the history
* start prepping for building release in CI

* correct core versions

* love me some peer deps

* ci

* geez

* fix test script

* ci

* ci

* ci

* try ci

* restructure

* some more tweaks

* try adding step for publishing release version
  • Loading branch information
zth authored May 1, 2023
1 parent 5706ca8 commit fb96044
Show file tree
Hide file tree
Showing 76 changed files with 330 additions and 395 deletions.
162 changes: 162 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
name: CI

on:
push:
branches: [main]
tags: "*.*.*"
pull_request:
branches: [main]

jobs:
test:
strategy:
fail-fast: false
matrix:
# Stay on the oldest Ubuntu version that's still supported by Github Actions
# to avoid glibc incompatibilities as far as possible.
# TODO: Can we enable macos-arm here?
os: [macos-latest, ubuntu-20.04, windows-latest]
# syntax explanation:
# https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#example-including-additional-values-into-combinations
include:
- os: macos-latest
artifact-folder: darwin
# - os: macos-arm
# artifact-folder: darwinarm64
- os: ubuntu-20.04
artifact-folder: linux
- os: windows-latest
artifact-folder: win32

runs-on: ${{matrix.os}}

steps:
# needed for Windows testing
- name: Set git to use LF
run: |
git config --global core.autocrlf false
git config --global core.eol lf
- uses: actions/checkout@v3

- name: Cache OCaml's opam
uses: actions/cache@v3
with:
path: ~/.opam
key: ${{matrix.os}}-rescript-vscode-v4

- name: Use OCaml
uses: ocaml/setup-ocaml@v2
with:
ocaml-compiler: 4.14.x

- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: 16

- run: npm ci --legacy-peer-deps
- run: opam install dune cppo
# - run: npm run res:build

# These 2 runs (or just the second?) are for when you have opam dependencies. We don't.
# Don't add deps. But if you ever do, un-comment these and add an .opam file.
# - run: opam pin add resgraph.dev . --no-action
# - run: opam install . --deps-only --with-doc --with-test

- name: Build and test
run: opam exec -- make test

# Also avoids artifacts upload permission loss:
# https://github.com/actions/upload-artifact/tree/ee69f02b3dfdecd58bb31b4d133da38ba6fe3700#permission-loss
- name: Compress files
run: |
cd bin
mkdir ${{matrix.artifact-folder}}
mv dev/resgraph.exe ${{matrix.artifact-folder}}
tar -cvf binary.tar ${{matrix.artifact-folder}}
- uses: actions/upload-artifact@v3
with:
name: ${{matrix.os}}
path: bin/binary.tar

package:
needs: test
runs-on: ubuntu-20.04

steps:
- uses: actions/checkout@v3

- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: 16

- run: npm ci --legacy-peer-deps
- run: npm run res:build

- name: Download MacOS binary
uses: actions/download-artifact@v3
with:
name: macos-latest
path: ./bin
- run: tar -xvf binary.tar
working-directory: ./bin

#- name: Download MacOS ARM binary
# uses: actions/download-artifact@v3
# with:
# name: macos-arm
# path: ./bin
#- run: tar -xvf binary.tar
# working-directory: ./bin

- name: Download Linux binary
uses: actions/download-artifact@v3
with:
name: ubuntu-20.04
path: ./bin
- run: tar -xvf binary.tar
working-directory: ./bin

- name: Download Windows binary
uses: actions/download-artifact@v3
with:
name: windows-latest
path: ./bin
- run: tar -xvf binary.tar
working-directory: ./bin

- name: Cleanup tar file
run: rm binary.tar
working-directory: ./bin

- name: Store short commit SHA for filename
id: vars
env:
COMMIT_SHA: ${{ github.event.pull_request.head.sha || github.sha }}
run: echo "::set-output name=sha_short::${COMMIT_SHA:0:7}"

- name: Store tag name
id: tag_name
if: startsWith(github.ref, 'refs/tags/')
run: echo ::set-output name=tag::${GITHUB_REF#refs/*/}

- name: Package release
run: npm pack

- name: Rename package
run: mv resgraph*.tgz resgraph.tgz

- uses: actions/upload-artifact@v3
with:
name: resgraph.tgz
path: resgraph.tgz

- name: Publish release version if wanted
if: startsWith(github.ref, 'refs/tags/')
uses: JS-DevTools/npm-publish@v1
with:
token: ${{ secrets.NPM_TOKEN }}
package: ./package.json
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# ResGraph Changelog

## main

## 0.1.0

Initial release!
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
SHELL = /bin/bash

build-resgraph-binary:
rm -f resgraph.exe
rm -f bin/dev/resgraph.exe
dune build
cp _build/install/default/bin/resgraph resgraph.exe
cp _build/install/default/bin/resgraph bin/dev/resgraph.exe

build-tests:
make -C tests build
Expand All @@ -22,7 +22,7 @@ test-resgraph-binary: build-resgraph-binary
test: test-resgraph-binary

clean:
rm -f resgraph.exe
rm -f bin/dev/resgraph.exe
dune clean
make -C tests clean
make -C reanalyze clean
Expand Down
Empty file added bin/dev/.gitkeep
Empty file.
7 changes: 2 additions & 5 deletions bsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "rescript-relay-router",
"name": "resgraph",
"version": "0.1.0",
"uncurried": true,
"sources": [
Expand All @@ -20,8 +20,5 @@
"rescript-nodejs",
"@glennsl/rescript-fetch"
],
"bsc-flags": ["-open NodeJs", "-open RescriptCore"],
"js-post-build": {
"cmd": "./scripts/post-build.sh"
}
"bsc-flags": ["-open NodeJs", "-open RescriptCore"]
}
2 changes: 2 additions & 0 deletions cli/Cli.res
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
@@directive("#!/usr/bin/env node")

@val
external argv: array<option<string>> = "process.argv"

Expand Down
15 changes: 14 additions & 1 deletion cli/Utils.res
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,21 @@ external toCallResult: string => callResult = "JSON.parse"

external infinity: int = "Infinity"

let devBinLocation = "../bin/dev/resgraph.exe"

let hasDevBin = Lazy.from_fun(() => Fs.existsSync(devBinLocation))

let callPrivateCli = command => {
"../resgraph.exe"
let hasDevBin = hasDevBin->Lazy.force

// TODO: macos-arm
let binLocation = if hasDevBin {
devBinLocation
} else {
"../bin/" ++ Os.platform() ++ "/resgraph.exe"
}

binLocation
->ChildProcess.execFileSyncWith(
command->privateCliCallToArgs,
ChildProcess.execFileSyncOptions(~maxBuffer=infinity, ()),
Expand Down
4 changes: 4 additions & 0 deletions example/bsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
"name": "resgraph-example",
"version": "0.1.0",
"sources": [
{
"dir": "../src/res",
"subdirs": true
},
{
"dir": "src",
"subdirs": true
Expand Down
17 changes: 10 additions & 7 deletions example/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"author": "",
"license": "ISC",
"dependencies": {
"@rescript/core": "^0.2.0",
"@rescript/core": "0.3.0",
"rescript": "^11.0.0-alpha.5",
"@glennsl/rescript-fetch": "^0.2.0"
},
Expand Down
20 changes: 13 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 15 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
"res:build": "rescript build -with-deps",
"res:watch": "rescript build -with-deps -w"
},
"bin": {
"resgraph": "cli/Cli.mjs"
},
"repository": {
"type": "git",
"url": "git+https://github.com/zth/resgraph.git"
Expand All @@ -19,12 +22,22 @@
},
"homepage": "https://github.com/zth/resgraph#readme",
"dependencies": {
"@rescript/core": "^0.2.0",
"@rescript/core": "0.3.0",
"chalk": "^5.2.0",
"chokidar": "^3.5.3",
"rescript": "^11.0.0-alpha.5",
"@glennsl/rescript-fetch": "0.2.0",
"rescript-nodejs": "^14.3.1",
"vscode-jsonrpc": "^5.0.1"
}
},
"files": [
"bin/*",
"src/res",
"cli/**/*.mjs",
"bsconfig.json",
"package.json",
"LICENSE",
"README.md",
"CHANGELOG.md"
]
}
13 changes: 0 additions & 13 deletions scripts/post-build.sh

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit fb96044

Please sign in to comment.