Skip to content

Commit c863ce5

Browse files
authored
Improve templates (#108)
* make switch install from lockfile * Ignore constraint on OCaml * Add None for test framework * Misc improvements to templates * Update CI schedule * Fix CI errors * Fix test command
1 parent 434812d commit c863ce5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+283
-1268
lines changed

.github/workflows/ci.yml

+31-47
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,55 @@
11
name: CI
22

3-
on: [push, pull_request]
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
48

59
jobs:
6-
build:
7-
name: Build and test
8-
9-
runs-on: ${{ matrix.os }}
10+
build-and-test:
11+
name: CI
1012

1113
strategy:
1214
fail-fast: false
15+
1316
matrix:
1417
os:
1518
- macos-latest
1619
- ubuntu-latest
17-
ocaml-version:
18-
- 4.10.1
20+
- windows-latest
21+
22+
ocaml-compiler:
23+
- 4.12.x
24+
25+
runs-on: ${{ matrix.os }}
1926

2027
steps:
28+
2129
- name: Checkout code
2230
uses: actions/checkout@v2
2331

24-
- name: Retrieve opam cache
25-
uses: actions/cache@v2
26-
if: runner.os != 'Windows'
27-
id: cache-opam
28-
with:
29-
path: ~/.opam
30-
key: v1-${{ runner.os }}-opam-${{ matrix.ocaml-version }}-${{ hashFiles('spin.opam.locked') }}
31-
restore-keys: |
32-
v1-${{ runner.os }}-opam-${{ matrix.ocaml-version }}-
33-
34-
- name: Use OCaml ${{ matrix.ocaml-version }}
35-
uses: avsm/setup-ocaml@v1
36-
with:
37-
ocaml-version: ${{ matrix.ocaml-version }}
38-
39-
- name: Use Node.js 12.x
40-
uses: actions/setup-node@v1
32+
- name: Use OCaml ${{ matrix.ocaml-compiler }}
33+
uses: avsm/setup-ocaml@v2
4134
with:
42-
node-version: 12.x
43-
registry-url: "https://registry.npmjs.org"
44-
45-
- name: Install esy
46-
run: npm install -g esy@latest
35+
ocaml-compiler: ${{ matrix.ocaml-compiler }}
36+
dune-cache: ${{ matrix.os != 'macos-latest' }}
37+
opam-depext-flags: --with-test
4738

48-
- name: Pin package
49-
run: opam pin add spin.dev . --no-action
39+
- name: Install ocamlformat
40+
run: opam install ocamlformat.0.18.0
41+
if: ${{ matrix.os == 'ubuntu-latest' }}
5042

51-
- name: Query and install external dependencies
52-
run: opam depext spin --yes --with-doc --with-test
43+
- name: Install opam packages
44+
run: opam install . --with-test
5345

54-
- name: Install dependencies
55-
if: steps.cache-opam.outputs.cache-hit != 'true'
56-
run: |
57-
opam install . --deps-only --with-doc --with-test --locked --unlock-base
58-
opam install ocamlformat reason --skip-updates
59-
60-
- name: Upgrade dependencies
61-
run: opam upgrade --fixup
62-
if: steps.cache-opam.outputs.cache-hit == 'true'
46+
- name: Check formatting
47+
run: make fmt
48+
if: ${{ matrix.os == 'ubuntu-latest' && always() }}
6349

64-
- name: Build
50+
- name: Run build
6551
run: make build
6652

67-
- name: Check formatting
68-
run: make format
69-
70-
- name: Run tests
53+
- name: Run the unit tests
7154
run: make test
55+
timeout-minutes: 1

.github/workflows/release.yml

+33-26
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,30 @@ on:
66

77
jobs:
88
build:
9-
name: Build and test
10-
runs-on: ${{ matrix.os }}
119
strategy:
10+
fail-fast: false
11+
1212
matrix:
13-
os: [ubuntu-latest, macos-latest]
14-
ocaml-version: ['4.10.1']
13+
os:
14+
- macos-latest
15+
- ubuntu-latest
16+
17+
ocaml-compiler:
18+
- 4.12.x
19+
20+
runs-on: ${{ matrix.os }}
1521

1622
steps:
17-
- uses: actions/checkout@v2
1823

19-
- uses: avsm/setup-ocaml@master
24+
- name: Checkout code
25+
uses: actions/checkout@v2
26+
27+
- name: Use OCaml ${{ matrix.ocaml-compiler }}
28+
uses: avsm/setup-ocaml@v2
2029
with:
21-
ocaml-version: ${{ matrix.ocaml-version }}
30+
ocaml-compiler: ${{ matrix.ocaml-compiler }}
31+
dune-cache: ${{ matrix.os != 'macos-latest' }}
32+
opam-depext-flags: --with-test
2233

2334
- name: Use Node.js 12.x
2435
if: ${{ matrix.os == 'ubuntu-latest' }}
@@ -29,25 +40,21 @@ jobs:
2940
- name: Fetch git tags
3041
run: git fetch --tags --force
3142

32-
- name: Pin package
33-
run: opam pin add spin.dev -n .
43+
- name: Install opam packages
44+
run: opam install .
45+
46+
- name: Substitute watermarks
47+
run: opam exec -- dune subst
3448

35-
- name: Query and install external dependencies
36-
run: opam depext -yt spin
49+
- name: Run build
50+
run: opam exec -- dune build --release
3751

38-
- name: Install dependencies
39-
run: opam install --deps-only -y .
40-
4152
- name: Substitute watermarks
4253
run: opam exec -- dune subst
4354

4455
- name: Build
4556
run: opam exec -- dune build --release
4657

47-
- name: Make NPM release skeleton
48-
if: ${{ matrix.os == 'ubuntu-latest' }}
49-
run: node script/release-make-skeleton.js
50-
5158
- name: Upload _release
5259
if: ${{ matrix.os == 'ubuntu-latest' }}
5360
uses: actions/upload-artifact@master
@@ -121,12 +128,12 @@ jobs:
121128
asset_name: spin-linux-x64.zip
122129
asset_content_type: application/gzip
123130

124-
- name: Publish NPM package
125-
run: |
126-
npm config set //registry.npmjs.org/:_authToken=$NODE_AUTH_TOKEN
127-
npm config set scope "@tmattio"
128-
npm config list
129-
npm publish --access public
130-
working-directory: ./_release
131+
- name: Upload spin-windows-x64.zip to Github release
132+
uses: actions/upload-release-asset@v1
131133
env:
132-
NODE_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}
134+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
135+
with:
136+
upload_url: ${{ github.event.release.upload_url }}
137+
asset_path: spin-windows-x64.zip
138+
asset_name: spin-windows-x64.zip
139+
asset_content_type: application/gzip

.ocamlformat

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
version = 0.18.0
12
profile = sparse
23
break-cases = nested
34
break-fun-decl = smart
@@ -15,4 +16,4 @@ ocp-indent-compat = true
1516
wrap-comments = true
1617
parse-docstrings = true
1718
let-binding-spacing = compact
18-
type-decl = sparse
19+
type-decl = sparse

CHANGES.md

+8
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,14 @@
1111

1212
## Changed
1313

14+
- Increase version of `ocamlformat` to `0.18.0` in templates
15+
- Do not install merlin when installing dev dependencies in templates
16+
- Drop support for BuckleScript in PPX
17+
- Drop support for publishing on NPM for CLI and PPX templates
18+
- Update CI scripts to `avsm/setup-ocaml@v2`
19+
- Remove python dependency to serve documentation in Makefile
20+
- Inline release script in Makefile
21+
- Remove global `-open StdLabels` in templates
1422
- The `spa` template has been removed from the official templates and now lives at https://github.com/tmattio/spin-incr-dom
1523
- Spin does not parse binary files by default anymore, they are simply copied to the destination folder
1624
- Use `test` stanza for unit tests now that Alcotest prints colors by default

CONTRIBUTING.md

+1-5
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,7 @@ The, you can run the script `script/release.sh`. The script will perform the fol
7373
- Publish the distribution archive to a Github Release.
7474
- Submit a PR on Opam's repository.
7575

76-
When the release is published on Github, the CI/CD will trigger the `Release` workflow which will perform the following actions
77-
78-
- Compile binaries for all supported platforms.
79-
- Create an NPM release containing the pre-built binaries.
80-
- Publish the NPM release to the registry.
76+
When the release is published on Github, the CI/CD will trigger the `Release` workflow which will compile binaries for all supported platforms and add them to the Github Release as assets.
8177

8278
### Repository Structure
8379

Makefile

+12-33
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,17 @@
11
.DEFAULT_GOAL := all
22

3-
define BROWSER_PYSCRIPT
4-
import os, webbrowser, sys
5-
6-
from urllib.request import pathname2url
7-
8-
webbrowser.open("file://" + pathname2url(os.path.abspath(sys.argv[1])))
9-
endef
10-
export BROWSER_PYSCRIPT
11-
12-
define PRINT_HELP_PYSCRIPT
13-
import re, sys
14-
15-
for line in sys.stdin:
16-
match = re.match(r'^([a-zA-Z_-]+):.*?## (.*)$$', line)
17-
if match:
18-
target, help = match.groups()
19-
print("%-20s %s" % (target, help))
20-
endef
21-
export PRINT_HELP_PYSCRIPT
22-
23-
BROWSER := python -c "$$BROWSER_PYSCRIPT"
24-
253
ARGS := $(wordlist 2,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS))
264
$(eval $(ARGS):;@:)
275

28-
.PHONY: help
29-
help: ## Print this help message
30-
@python -c "$$PRINT_HELP_PYSCRIPT" < $(MAKEFILE_LIST)
31-
326
.PHONY: all
337
all:
348
opam exec -- dune build --root . @install
359

3610
.PHONY: dev
3711
dev: ## Install development dependencies
38-
opam switch create --no-install . ocaml-base-compiler.4.10.1
39-
opam install -y dune-release merlin ocamlformat utop ocaml-lsp-server reason
40-
opam install --locked --deps-only --with-test --with-doc -y .
12+
opam switch create --no-install . ocaml-base-compiler.4.12.0
13+
opam install -y dune-release ocamlformat utop ocaml-lsp-server
14+
opam install --deps-only --with-test --with-doc -y .
4115

4216
.PHONY: build
4317
build: ## Build the project, including non installable libraries and executables
@@ -50,6 +24,7 @@ start: all ## Start the project
5024
.PHONY: install
5125
install: all ## Install the packages on the system
5226
opam exec -- dune install --root .
27+
bash -c "cp $$(opam exec -- which spin) /usr/local/bin/spin"
5328

5429
.PHONY: test
5530
test: ## Run the unit tests
@@ -70,10 +45,10 @@ doc: ## Generate odoc documentation
7045

7146
.PHONY: servedoc
7247
servedoc: doc ## Open odoc documentation with default web browser
73-
$(BROWSER) _build/default/_doc/_html/index.html
48+
open _build/default/_doc/_html/index.html
7449

75-
.PHONY: format
76-
format: ## Format the codebase with ocamlformat
50+
.PHONY: fmt
51+
fmt: ## Format the codebase with ocamlformat
7752
opam exec -- dune build --root . @fmt --auto-promote
7853

7954
.PHONY: watch
@@ -86,4 +61,8 @@ utop: ## Run a REPL and link with the project's libraries
8661

8762
.PHONY: release
8863
release: ## Run the release script
89-
opam exec -- sh script/release.sh
64+
opam exec -- dune-release tag
65+
opam exec -- dune-release distrib
66+
opam exec -- dune-release publish distrib -y
67+
opam exec -- dune-release opam pkg
68+
opam exec -- dune-release opam submit --no-auto-open -y

README.md

+1-9
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,6 @@ brew install tmattio/tap/spin
5353
opam install spin
5454
```
5555

56-
### Using npm
57-
58-
```bash
59-
yarn global add @tmattio/spin
60-
# Or
61-
npm -g install @tmattio/spin
62-
```
63-
6456
### Using a script
6557

6658
```bash
@@ -86,7 +78,7 @@ The official Spin templates templates are the following:
8678
- **bin** - Native project containing a binary.
8779
- **cli** - Command Line Interface releasable on Opam.
8880
- **lib** - Library releasable on Opam.
89-
- **ppx** - PPX library with prebuilt binaries for native and bucklescript.
81+
- **ppx** - PPX library.
9082
- **c-bindings** - Bindings to a C library.
9183
- **js** - Js application with Js_of_ocaml.
9284

bin/common.ml

+10-6
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,13 @@ let handle_errors = function
8787

8888
let exits =
8989
Term.exit_info 3 ~doc:"on indiscriminate errors reported on stderr."
90-
:: Term.exit_info 4 ~doc:"on missing required environment variable."
91-
:: Term.exit_info 5 ~doc:"on failure to parse a file."
92-
:: Term.exit_info 6 ~doc:"on invalid spin template."
93-
:: Term.exit_info 7 ~doc:"on failure to generate project."
94-
:: Term.exit_info 8 ~doc:"on failure to run a generator."
95-
:: Term.default_exits
90+
::
91+
Term.exit_info 4 ~doc:"on missing required environment variable."
92+
::
93+
Term.exit_info 5 ~doc:"on failure to parse a file."
94+
::
95+
Term.exit_info 6 ~doc:"on invalid spin template."
96+
::
97+
Term.exit_info 7 ~doc:"on failure to generate project."
98+
::
99+
Term.exit_info 8 ~doc:"on failure to run a generator." :: Term.default_exits

dune-project

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
(>= 4.08.0))
2727
dune
2828
(alcotest :with-test)
29+
(reason :with-test)
2930
(odoc :with-doc)
3031
(crunch :build)
3132
base

lib/spin/decoder.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ let one_of decoders sexp =
277277
| Error error ->
278278
go
279279
(tag_errors ~msg:(Printf.sprintf "%S decoder" name) [ error ]
280-
:: errors)
280+
:: errors)
281281
rest)
282282
| [] ->
283283
Error

0 commit comments

Comments
 (0)