Skip to content

Commit

Permalink
Improve Github Actions workflow (ocaml#318)
Browse files Browse the repository at this point in the history
* Improve Actions workflow

Signed-off-by: Sora Morimoto <[email protected]>

* Improve Makefile

* Generate lock files

* Update CI with Makefile and lockfiles

* Run dune-release in opam sandbox

* Add caching, save build minutes and the planet

* Remove unused files

* Make CI build for 4.11.1

Co-authored-by: Sora Morimoto <[email protected]>
  • Loading branch information
tmattio and smorimoto authored Dec 1, 2020
1 parent 3d2e533 commit db71298
Show file tree
Hide file tree
Showing 10 changed files with 294 additions and 82 deletions.
96 changes: 58 additions & 38 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
@@ -1,77 +1,97 @@
name: Build and Test

on:
- push
- pull_request
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
build-and-test:
name: Build and Test

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

strategy:
fail-fast: false
matrix:
os:
- macos-latest
- ubuntu-latest
skip_test:
- false
ocaml-version:
- 4.11.0
include:
- ocaml-version: 4.11.0
os: windows-latest
skip_test: true
- ocaml-version: 4.10.0
os: windows-latest
skip_test: true
- ocaml-version: 4.09.1
os: ubuntu-latest
skip_test: true
- ocaml-version: 4.06.1
os: ubuntu-latest
skip_test: true
- windows-latest

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

env:
SKIP_TEST: ${{ matrix.skip_test }}
ocaml-version:
- 4.11.1
- 4.10.1
- 4.09.1
- 4.08.1
- 4.07.1
- 4.06.1

steps:
- name: Checkout code
uses: actions/checkout@v2
with:
submodules: true

- name: Retrieve opam cache
uses: actions/cache@v2
if: runner.os != 'Windows'
id: cache-opam
with:
path: ~/.opam
key: v1-${{ runner.os }}-opam-${{ matrix.ocaml-version }}-${{ hashFiles('*.opam.locked') }}
restore-keys: |
v1-${{ runner.os }}-opam-${{ matrix.ocaml-version }}-
- name: Use latest LTS Node.js release
uses: actions/setup-node@v1
with:
node-version: 12.x
node-version: 14.x

- name: Use OCaml ${{ matrix.ocaml-version }}
uses: avsm/setup-ocaml@v1
with:
ocaml-version: ${{ matrix.ocaml-version }}

- run: opam pin -n .
- name: Print OCaml version
run: opam exec -- ocaml --version

- run: opam install -t . --deps-only
if: env.SKIP_TEST != 'true'
- name: Pin local packages
run: |
opam pin jsonrpc.dev . --no-action
opam pin lsp.dev . --no-action
opam pin ocaml-lsp-server.dev . --no-action
- run: opam install . --deps-only
if: env.SKIP_TEST == 'true'
- name: Install OCaml secondary compiler
if: steps.cache-opam.outputs.cache-hit != 'true' && runner.os != 'Windows' && (matrix.ocaml-version == '4.06.1' || matrix.ocaml-version == '4.07.1')
run: opam install ocamlfind-secondary

- run: opam exec -- make test
if: env.SKIP_TEST != 'true'
- name: Install Opam dependencies
if: steps.cache-opam.outputs.cache-hit != 'true'
run: |
opam install . --with-doc --with-test --locked --ignore-constraints-on=ocaml
opam install ocamlformat --skip-updates
- name: test source is well formatted
run: opam exec -- make fmt
if: env.OCAML_VERSION == '4.10.0' && env.OS == 'ubuntu-latest'
- name: Fix broken opam state
if: steps.cache-opam.outputs.cache-hit == 'true'
run: opam upgrade --fixup

- run: yarn --frozen-lockfile
- name: Install Node dependencies
working-directory: ocaml-lsp-server/test/e2e
if: env.SKIP_TEST != 'true'
run: |
yarn --frozen-lockfile
- name: Build
run: opam exec -- make build

- name: Check formatting
if: matrix.ocaml-version == '4.11.1' && runner.os == 'Linux'
run: opam exec -- make fmt

- name: Run OCaml tests
run: opam exec -- make test

- run: opam exec -- yarn test
- name: Run Node tests
working-directory: ocaml-lsp-server/test/e2e
if: env.SKIP_TEST != 'true'
run: opam exec -- dune exec -- yarn test
80 changes: 42 additions & 38 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,57 +1,61 @@
.DEFAULT_GOAL := all

TEST_E2E_DIR = ocaml-lsp-server/test/e2e

build:
dune build
.PHONY: build
$(TEST_E2E_DIR)/node_modules:
cd $(TEST_E2E_DIR) && yarn install

fmt:
dune build @fmt --auto-promote
cd $(TEST_E2E_DIR) && yarn fmt
.PHONY: fmt
-include Makefile.dev

gen:
dune build @cinaps --auto-promote
dune build @fmt --auto-promote
.PHONY: gen
.PHONY: all
all:
dune build --root . @install

.PHONY: dev
dev: ## Setup a development environment
opam switch create --no-install . ocaml-base-compiler.4.11.1
opam install -y dune-release merlin ocamlformat utop ocaml-lsp-server
opam install --locked --deps-only --with-test --with-doc -y .

jest-promote:
cd $(TEST_E2E_DIR) && yarn promote
.PHONY: jest-promote
.PHONY: build
build: ## Build the project, including non installable libraries and executables
dune build --root .

dune-promote:
dune promote
.PHONY: dune-promote
.PHONY: install
install: all ## Install the packages on the system
dune install --root .

fmt-check:
dune build @fmt
cd $(TEST_E2E_DIR) && yarn fmt-check
.PHONY: fmt-check
.PHONY: lock
lock: ## Generate the lock files
opam lock -y .

lsp-server:
dune build @install
.PHONY: lsp-server
.PHONY: test
test: ## Run the unit tests
dune build --root . @lsp-fiber/runtest @fiber-unix/runtest @jsonrpc-fiber/runtest

test-e2e: $(TEST_E2E_DIR)/node_modules
dune build @install
.PHONY: test-template
test-e2e: $(TEST_E2E_DIR)/node_modules all ## Run the template integration tests
cd $(TEST_E2E_DIR) && dune exec -- yarn test
.PHONY: test-e2e

test-ocaml:
dune build @lsp-fiber/runtest @fiber-unix/runtest @jsonrpc-fiber/runtest
.PHONY: test-ocaml
.PHONY: clean
clean: ## Clean build artifacts and other generated files
dune clean --root .

test: test-ocaml test-e2e
.PHONY: test
.PHONY: fmt
fmt: ## Format the codebase with ocamlformat
dune build --root . @fmt --auto-promote
cd $(TEST_E2E_DIR) && yarn fmt

clean:
dune clean
.PHONY: clean
.PHONY: watch
watch: ## Watch for the filesystem and rebuild on every change
dune build ---root . -watch

$(TEST_E2E_DIR)/node_modules:
cd $(TEST_E2E_DIR) && yarn install --frozen-lockfile
.PHONY: utop
utop: ## Run a REPL and link with the project's libraries
dune utop --root . . -- -implicit-bindings

opam-release:
.PHONY: release
release: all ## Release on Opam
dune-release distrib --skip-build --skip-lint --skip-tests --include-submodules
# See https://github.com/ocamllabs/dune-release/issues/206
DUNE_RELEASE_DELEGATE=github-dune-release-delegate dune-release publish distrib --verbose
Expand Down
41 changes: 41 additions & 0 deletions jsonrpc.opam.locked
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
opam-version: "2.0"
name: "jsonrpc"
version: "dev"
synopsis: "Jsonrpc protocol implemenation"
description: "See https://www.jsonrpc.org/specification"
maintainer: "Rudi Grinberg <[email protected]>"
authors: [
"Andrey Popp <[email protected]>"
"Rusty Key <[email protected]>"
"Louis Roché <[email protected]>"
"Oleksiy Golovko <[email protected]>"
"Rudi Grinberg <[email protected]>"
"Sacha Ayoun <[email protected]>"
"cannorin <[email protected]>"
]
license: "ISC"
homepage: "https://github.com/ocaml/ocaml-lsp"
bug-reports: "https://github.com/ocaml/ocaml-lsp/issues"
depends: [
"base-bigarray" {= "base"}
"base-threads" {= "base"}
"base-unix" {= "base"}
"biniou" {= "1.2.1"}
"cppo" {= "1.6.6"}
"dune" {= "2.7.1"}
"easy-format" {= "1.3.2"}
"ocaml" {= "4.11.1"}
"ocaml-config" {= "1"}
"ocaml-syntax-shims" {= "1.0.0"}
"ocaml-system" {= "4.11.1"}
"ppx_yojson_conv_lib" {= "v0.14.0"}
"result" {= "1.5"}
"stdlib-shims" {= "0.1.0"}
"yojson" {= "1.7.0"}
]
build: [
["dune" "subst"] {dev}
["ocaml" "unix.cma" "unvendor.ml"]
["dune" "build" "-p" name "-j" jobs "@install" "@doc" {with-doc}]
]
dev-repo: "git+https://github.com/ocaml/ocaml-lsp.git"
82 changes: 82 additions & 0 deletions lsp.opam.locked
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
opam-version: "2.0"
name: "lsp"
version: "dev"
synopsis: "LSP protocol implementation in OCaml"
description: """
Implementation of the LSP protocol in OCaml. It is designed to be as portable as
possible and does not make any assumptions about IO."""
maintainer: "Rudi Grinberg <[email protected]>"
authors: [
"Andrey Popp <[email protected]>"
"Rusty Key <[email protected]>"
"Louis Roché <[email protected]>"
"Oleksiy Golovko <[email protected]>"
"Rudi Grinberg <[email protected]>"
"Sacha Ayoun <[email protected]>"
"cannorin <[email protected]>"
]
license: "ISC"
homepage: "https://github.com/ocaml/ocaml-lsp"
bug-reports: "https://github.com/ocaml/ocaml-lsp/issues"
depends: [
"base" {= "v0.14.0" & with-test}
"base-bigarray" {= "base"}
"base-threads" {= "base"}
"base-unix" {= "base"}
"biniou" {= "1.2.1"}
"cinaps" {= "v0.14.0" & with-test}
"cmdliner" {= "1.0.4"}
"conf-m4" {= "1"}
"cppo" {= "1.6.6"}
"csexp" {= "1.3.2"}
"dune" {= "2.7.1"}
"dune-configurator" {= "2.7.1" & with-test}
"easy-format" {= "1.3.2"}
"jane-street-headers" {= "v0.14.0" & with-test}
"jsonrpc" {= "dev"}
"jst-config" {= "v0.14.0" & with-test}
"menhir" {= "20201122" & with-test}
"menhirLib" {= "20201122" & with-test}
"menhirSdk" {= "20201122" & with-test}
"ocaml" {= "4.11.1"}
"ocaml-compiler-libs" {= "v0.12.3" & with-test}
"ocaml-config" {= "1"}
"ocaml-migrate-parsetree" {= "2.1.0" & with-test}
"ocaml-syntax-shims" {= "1.0.0"}
"ocaml-system" {= "4.11.1"}
"ocamlbuild" {= "0.14.0"}
"ocamlfind" {= "1.8.1"}
"octavius" {= "1.2.2" & with-test}
"ppx_assert" {= "v0.14.0" & with-test}
"ppx_base" {= "v0.14.0" & with-test}
"ppx_cold" {= "v0.14.0" & with-test}
"ppx_compare" {= "v0.14.0" & with-test}
"ppx_derivers" {= "1.2.1" & with-test}
"ppx_enumerate" {= "v0.14.0" & with-test}
"ppx_expect" {= "v0.14.1" & with-test}
"ppx_hash" {= "v0.14.0" & with-test}
"ppx_here" {= "v0.14.0" & with-test}
"ppx_inline_test" {= "v0.14.1" & with-test}
"ppx_js_style" {= "v0.14.0" & with-test}
"ppx_optcomp" {= "v0.14.1" & with-test}
"ppx_sexp_conv" {= "v0.14.2" & with-test}
"ppx_yojson_conv_lib" {= "v0.14.0"}
"ppxlib" {= "0.20.0" & with-test}
"re" {= "1.9.0" & with-test}
"result" {= "1.5"}
"seq" {= "base" & with-test}
"sexplib0" {= "v0.14.0" & with-test}
"stdio" {= "v0.14.0" & with-test}
"stdlib-shims" {= "0.1.0"}
"time_now" {= "v0.14.0" & with-test}
"topkg" {= "1.0.3"}
"uchar" {= "0.0.2"}
"uutf" {= "1.0.2"}
"yojson" {= "1.7.0"}
]
build: [
["dune" "subst"] {dev}
["ocaml" "unix.cma" "unvendor.ml"]
["dune" "build" "-p" name "-j" jobs "@install" "@doc" {with-doc}]
]
dev-repo: "git+https://github.com/ocaml/ocaml-lsp.git"
Loading

0 comments on commit db71298

Please sign in to comment.