Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 93 additions & 0 deletions .github/actions/build-rewatch/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
name: Build rewatch
description: Restore or build rewatch and copy its executable into the platform package.

inputs:
cache-target:
description: Target identifier used in the build cache key.
required: true
rust-target:
description: Explicit Rust compilation target. Empty builds for the runner's native target.
required: false
default: ""
exe-suffix:
description: Executable suffix for the target platform.
required: false
default: ""
run-quality-checks:
description: Run Clippy and Rust unit tests when populating the cache.
required: false
default: "false"

runs:
using: composite
steps:
- name: Restore rewatch build cache
id: build-cache
uses: actions/cache@v6
with:
path: rewatch/target
key: rewatch-build-v4-${{ inputs.cache-target }}-${{ hashFiles('rewatch/src/**', 'rewatch/Cargo.toml', 'rewatch/Cargo.lock', 'rewatch/rust-toolchain.toml', 'rewatch/.cargo/config.toml') }}

- name: Determine Rust toolchain version
id: rust-version
shell: bash
run: |
version="$(awk -F '"' '/^rust-version[[:space:]]*=/ { print $2; exit }' rewatch/Cargo.toml)"
if [ -z "$version" ]; then
echo "rust-version missing in rewatch/Cargo.toml" >&2
exit 1
fi
echo "version=${version}" >> "$GITHUB_OUTPUT"

- name: Install Rust toolchain for native target
if: steps.build-cache.outputs.cache-hit != 'true' && inputs.rust-target == ''
uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ steps.rust-version.outputs.version }}
components: clippy, rustfmt

- name: Install Rust toolchain for explicit target
if: steps.build-cache.outputs.cache-hit != 'true' && inputs.rust-target != ''
uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ steps.rust-version.outputs.version }}
targets: ${{ inputs.rust-target }}
components: clippy, rustfmt

- name: Build rewatch for native target
if: steps.build-cache.outputs.cache-hit != 'true' && inputs.rust-target == ''
shell: bash
run: cargo build --manifest-path rewatch/Cargo.toml --release

- name: Build rewatch for explicit target
if: steps.build-cache.outputs.cache-hit != 'true' && inputs.rust-target != ''
shell: bash
run: cargo build --manifest-path rewatch/Cargo.toml --target "${{ inputs.rust-target }}" --release

- name: Lint rewatch
if: steps.build-cache.outputs.cache-hit != 'true' && inputs.run-quality-checks == 'true'
shell: bash
run: cargo clippy --manifest-path rewatch/Cargo.toml --all-targets --all-features

- name: Run rewatch unit tests
if: steps.build-cache.outputs.cache-hit != 'true' && inputs.run-quality-checks == 'true'
shell: bash
run: cargo test --manifest-path rewatch/Cargo.toml --release

- name: Copy rewatch binary
shell: bash
env:
RUST_TARGET: ${{ inputs.rust-target }}
EXE_SUFFIX: ${{ inputs.exe-suffix }}
run: |
if [[ -n "$RUST_TARGET" ]]; then
source="rewatch/target/$RUST_TARGET/release/rescript$EXE_SUFFIX"
else
source="rewatch/target/release/rescript$EXE_SUFFIX"
fi
cp "$source" rescript
if [[ -n "$RUST_TARGET" ]]; then
mkdir -p rewatch/target/release
cp "$source" rewatch/target/release
fi
./scripts/copyExes.js --rewatch
12 changes: 12 additions & 0 deletions .github/actions/setup-linux-dependencies/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: Setup Linux dependencies
description: Install and cache the system packages required to build ReScript.

runs:
using: composite
steps:
- name: Install system dependencies
uses: awalsh128/cache-apt-pkgs-action@v1.4.3
with:
# Dependencies required by setup-ocaml, plus cmake for OPAM.
packages: bubblewrap darcs g++-multilib gcc-multilib mercurial musl-tools rsync cmake
version: v4
16 changes: 16 additions & 0 deletions .github/actions/setup-node/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Setup Node and dependencies
description: Install the repository Node.js version and immutable Yarn dependencies.

runs:
using: composite
steps:
- name: Use Node.js
uses: actions/setup-node@v6
with:
cache: yarn
node-version-file: .nvmrc
registry-url: https://registry.npmjs.org

- name: Install npm packages
shell: bash
run: yarn install --immutable
131 changes: 131 additions & 0 deletions .github/actions/setup-ocaml/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
name: Setup OCaml
description: Restore or install the repository OPAM environment.

inputs:
compiler:
description: OCaml compiler switch specification.
required: true
os:
description: Runner identifier used in the cache key.
required: true
cache-prefix:
description: Cache namespace and version.
required: true
dependency-flags:
description: Flags passed to opam install after the package path.
required: false
default: --deps-only --with-test
outputs:
setup_version:
description: Version of ocaml/setup-ocaml used by this action.
value: ${{ steps.cache-key.outputs.setup-version }}

runs:
using: composite
steps:
- name: Get OPAM cache key
id: cache-key
shell: bash
env:
CACHE_PREFIX: ${{ inputs.cache-prefix }}
COMPILER: ${{ inputs.compiler }}
DEPENDENCY_FLAGS: ${{ inputs.dependency-flags }}
OS: ${{ inputs.os }}
run: |
dependency_flags_key="${DEPENDENCY_FLAGS//--/}"
dependency_flags_key="${dependency_flags_key// /_}"
key="$CACHE_PREFIX-$OS-3.6.0-$COMPILER-$dependency_flags_key-${{ hashFiles('*.opam') }}"
echo "value=${key//,/-}" >> "$GITHUB_OUTPUT"
echo "setup-version=3.6.0" >> "$GITHUB_OUTPUT"

- name: Restore OPAM environment
id: cache
uses: actions/cache/restore@v6
with:
path: |
${{ runner.tool_cache }}/opam
~/.opam
_opam
.opam-path
C:\cygwin
C:\.opam
key: ${{ steps.cache-key.outputs.value }}

- name: Use OCaml ${{ inputs.compiler }}
if: steps.cache.outputs.cache-hit != 'true'
uses: ocaml/setup-ocaml@v3.6.0
with:
ocaml-compiler: ${{ inputs.compiler }}
opam-pin: false

- name: Get OPAM executable path
if: steps.cache.outputs.cache-hit != 'true'
uses: actions/github-script@v9
with:
script: |
const opamPath = await io.which('opam', true);
console.log('opam executable found: %s', opamPath);

const fs = require('fs/promises');
await fs.writeFile('.opam-path', opamPath, 'utf-8');
console.log('stored path to .opam-path');

- name: Install OPAM dependencies
if: steps.cache.outputs.cache-hit != 'true'
shell: bash
env:
DEPENDENCY_FLAGS: ${{ inputs.dependency-flags }}
run: |
read -ra dependency_flags <<< "$DEPENDENCY_FLAGS"
opam install . "${dependency_flags[@]}"

- name: Cache OPAM environment
# Caches created by pull_request runs are scoped to that PR's merge ref
# and cannot seed other PRs or branches. Only pushes create shared caches.
if: steps.cache.outputs.cache-hit != 'true' && github.event_name == 'push'
Comment on lines +83 to +85

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess the only annoying thing with gating on push is that it won't cache if you have an open PR that changes this and then add another commit.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, but PRs changing this are rather rare, so in most cases PR-scoped caches would be created and stored unnecessarily.

uses: actions/cache/save@v6
with:
path: |
${{ runner.tool_cache }}/opam
~/.opam
_opam
.opam-path
C:\cygwin
C:\.opam
key: ${{ steps.cache-key.outputs.value }}

- name: Use cached OPAM environment
if: steps.cache.outputs.cache-hit == 'true'
shell: bash
run: |
echo "OPAMCOLOR=always" >> "$GITHUB_ENV"
echo "OPAMCONFIRMLEVEL=unsafe-yes" >> "$GITHUB_ENV"
echo "OPAMDOWNLOADJOBS=4" >> "$GITHUB_ENV"
echo "OPAMERRLOGLEN=0" >> "$GITHUB_ENV"
echo "OPAMEXTERNALSOLVER=builtin-0install" >> "$GITHUB_ENV"
echo "OPAMPRECISETRACKING=1" >> "$GITHUB_ENV"
echo "OPAMRETRIES=10" >> "$GITHUB_ENV"
echo "OPAMSOLVERTIMEOUT=600" >> "$GITHUB_ENV"
echo "OPAMYES=1" >> "$GITHUB_ENV"
echo "CLICOLOR_FORCE=1" >> "$GITHUB_ENV"

if [[ "$RUNNER_OS" != "Windows" ]]; then
echo "OPAMROOT=$HOME/.opam" >> "$GITHUB_ENV"
else
echo "OPAMROOT=C:\\.opam" >> "$GITHUB_ENV"
fi

OPAM_PATH="$(cat .opam-path)"
chmod +x "$OPAM_PATH"
dirname "$OPAM_PATH" >> "$GITHUB_PATH"

if [[ "$RUNNER_OS" == "Windows" ]]; then
fsutil behavior query SymlinkEvaluation
fsutil behavior set symlinkEvaluation R2L:1 R2R:1
fsutil behavior query SymlinkEvaluation

echo "HOME=$USERPROFILE" >> "$GITHUB_ENV"
echo "MSYS=winsymlinks:native" >> "$GITHUB_ENV"
echo "CYGWIN=winsymlinks:native" >> "$GITHUB_ENV"
echo "BASH_ENV=C:\\cygwin\\bash_env" >> "$GITHUB_ENV"
fi
Loading
Loading