-
Notifications
You must be signed in to change notification settings - Fork 485
Reuse node, ocaml, and rewatch setup between ci.yml and coverage.yml #8506
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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' | ||
| 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 | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.