Giter VIP home page Giter VIP logo

setup-ocaml's Introduction

Set up OCaml

Main workflow CodeQL

Set up an OCaml and opam environment in GitHub Actions and add to PATH.

Action

The action does the following:

Main

  1. Change the file system behavioral parameters
    • Windows only
  2. Retrieve the Cygwin cache
    • Windows only
    • If the cache already exists
  3. Retrieve the opam cache
    • If the cache already exists
  4. Prepare the Cygwin environment
    • Windows only
  5. Save the Cygwin cache
    • Windows only
  6. Install opam
  7. Initialise the opam state
  8. Install the OCaml compiler
    • If the opam cache was not hit
  9. Remove the opam repositories
  10. Save the opam cache
    • If the opam cache was not hit
  11. Initialise the opam repositories
  12. Retrieve the opam download cache
  13. Install depext
    • On Windows, not only opam-depext is installed, but depext-cygwinports is installed as well
  14. Retrieve the dune cache
    • If the dune cache feature is enabled
    • If the cache already exists
  15. Install the latest dune and enable the dune cache feature
    • If the dune cache feature is enabled
  16. Pin the opam files, if they exist
    • If the opam pin feature is not disabled
    • If there is an opam file in the workspace that matches the glob pattern
  17. Install the system dependencies required by the opam files via depext
    • If the opam depext feature is enabled
    • If there is an opam file in the workspace that matches the glob pattern

Post

The reason for not caching opam stuff in the post stage (more precisely, why you can't) is due to the size of the cache and repeatability. They should be cached immediately after initialisation to minimize the size of the cache.

  1. Remove oldest dune cache files to free space
    • If the dune cache feature is enabled
  2. Save the dune cache
    • If the dune cache feature is enabled
  3. Save the opam download cache

What is the difference between opam dependencies and depext dependencies?

  • opam dependencies: opam packages installed by opam install.
  • depext dependencies: System packages installed by apt-get install, yum install, brew install, etc.

Usage

We adhere to semantic versioning, it's safe to use the major version (v2) in your workflow. If you use the master branch, this could break your workflow when we publish a breaking update and increase the major version.

- name: Use OCaml ${{ matrix.ocaml-compiler }}
  uses: ocaml/setup-ocaml@v2
  #                      ^^^
  with:
    ocaml-compiler: ${{ matrix.ocaml-compiler }}
steps:
  # Reference the major version of a release (most recommended)
  - uses: ocaml/setup-ocaml@v2
  # Reference a specific commit (most strict)
  - uses: ocaml/setup-ocaml@<SHA>
  # Reference a semver version of a release (not recommended)
  - uses: ocaml/[email protected]
  # Reference a branch (most dangerous)
  - uses: ocaml/setup-ocaml@master

Example workflow

See the Hello World OCaml Action that uses Dune and opam to build a simple library.

It's possible to feed different values to the input depending on the platform of the runner. The syntax of GitHub's workflows is flexible enough to offer several methods to do this.

name: Main workflow

on:
  pull_request:
  push:
  schedule:
    # Prime the caches every Monday
    - cron: 0 1 * * MON

jobs:
  build:
    strategy:
      fail-fast: false
      matrix:
        os:
          - macos-latest
          - ubuntu-latest
          - windows-latest
        ocaml-compiler:
          - 4.13.x

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

    steps:
      - name: Checkout code
        uses: actions/checkout@v3

      - name: Use OCaml ${{ matrix.ocaml-compiler }}
        uses: ocaml/setup-ocaml@v2
        with:
          ocaml-compiler: ${{ matrix.ocaml-compiler }}

      - run: opam install . --deps-only --with-test

      - run: opam exec -- dune build

      - run: opam exec -- dune runtest

Extends

STATUS: EXPERIMENTAL

Note: All extends are recommended to use in separate jobs run on ubuntu-latest.

deploy-doc

name: Deploy odoc

on:
  push:
    branches:
      - master

jobs:
  deploy-doc:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v3

      - name: Use OCaml 4.13.x
        uses: ocaml/setup-ocaml@v2
        with:
          ocaml-compiler: 4.13.x
          dune-cache: true

      - name: Deploy odoc to GitHub Pages
        uses: ocaml/setup-ocaml/deploy-doc@v2

See action.yml for inputs.

lint-doc

jobs:
  lint-doc:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v3

      - name: Use OCaml 4.13.x
        uses: ocaml/setup-ocaml@v2
        with:
          ocaml-compiler: 4.13.x
          dune-cache: true

      - name: Lint doc
        uses: ocaml/setup-ocaml/lint-doc@v2

See action.yml for inputs.

lint-fmt

Note: The ocamlformat configuration file must have the version of the ocamlformat used in the project.

jobs:
  lint-fmt:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v3

      - name: Use OCaml 4.13.x
        uses: ocaml/setup-ocaml@v2
        with:
          ocaml-compiler: 4.13.x
          dune-cache: true

      - name: Lint fmt
        uses: ocaml/setup-ocaml/lint-fmt@v2

See action.yml for inputs.

lint-opam

jobs:
  lint-opam:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v3

      - name: Use OCaml 4.13.x
        uses: ocaml/setup-ocaml@v2
        with:
          ocaml-compiler: 4.13.x
          dune-cache: true

      - name: Lint opam
        uses: ocaml/setup-ocaml/lint-opam@v2

See action.yml for inputs.

Advanced Configurations

See Examples for more complex patterns.

Inputs

Name Required Description Type Default
ocaml-compiler Yes The OCaml compiler packages to initialise. The packages must be separated by the comma. (e.g. 4.13.x, ocaml-base-compiler.4.13.0, ocaml-variants.4.13.0+options,ocaml-option-flambda,ocaml-option-musl,ocaml-option-static) string
opam-repositories No The name and URL pair of the repository to fetch the packages from. string
opam-pin No Enable the automation feature for opam pin. bool true
opam-depext No Enable the automation feature for opam depext. bool true
opam-depext-flags No The flags for the opam depext command. The flags must be separated by the comma. string
opam-local-packages No The local packages to be used by opam-pin or opam-depext. See @actions/glob for supported patterns. string *.opam
opam-disable-sandboxing No Disable the opam sandboxing feature. bool false
dune-cache No Enable the dune cache feature. This feature requires dune 2.8.5 or later on the Windows runners. bool false
cache-prefix No The prefix of the cache keys. string v1

Roadmap

This action aims to provide an OS-neutral interface to opam, and so will not add features that only work on one operating system. It will also track the latest stable release of opam.

Support

Please feel free to post to the discuss.ocaml.org forum with any questions you have about this action.

Previous discussions include:

setup-ocaml's People

Contributors

smorimoto avatar dependabot[bot] avatar avsm avatar dra27 avatar tmattio avatar phated avatar hikaruegashira avatar psafont avatar aantron avatar misterda avatar rivy avatar giltho avatar tyoverby avatar favonia avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.