From a5623c54ae0216edd876edbd351e175d62304045 Mon Sep 17 00:00:00 2001 From: Jonathan Cubides Date: Tue, 31 Jan 2023 19:34:05 +0100 Subject: [PATCH] Use restore/save github action to speed up the CI testing (#1783) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This PR addresses a caching issue in our CI by streamlining each operating system's build and test processes, reducing CI time. 🤞 Also, our caching strategy has been updated with the new restore/save actions. For example, we aim to cache the .stack folder, and if the stack build is successful, the .stack-build. The building documentation job continues depending on the Linux build. Upon merging this PR, we get back to the point where the CI maintain a cache for each OS to be shared among all PRs, significantly reducing CI testing time. The expected scenario is as follows. The CI can take, on average, 35' in Linux to build and test everything. Using caching, that time is reduced to less than 10'. macOS is a different story. It can easily take one hour, and even more, the first time to build and test the project. After that, it might take an average of 20'. - Caching strategies [descriptions](https://github.com/actions/cache/blob/main/caching-strategies.md#saving-cache-even-if-the-build-fails) - Closes #1776 --- .github/workflows/ci.yml | 445 +++++++++++++++++++-------------------- 1 file changed, 216 insertions(+), 229 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8337afd3b9..a1af89b0c2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,12 +1,11 @@ name: The Juvix compiler CI - -on: +'on': workflow_dispatch: inputs: ref: - description: 'the repository ref to build' - required: true - default: 'main' + description: the repository ref to build + required: true + default: main push: branches: - main @@ -18,15 +17,14 @@ on: - reopened - synchronize - ready_for_review - concurrency: - group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} + group: '${{ github.workflow }}-${{ github.head_ref || github.run_id }}' cancel-in-progress: true - env: - STACKFLAGS: --pedantic + STACKFLAGS: '--pedantic --stack-root ${{ github.workspace }}/.stack' jobs: + ormolu: runs-on: ubuntu-latest steps: @@ -34,13 +32,9 @@ jobs: - uses: mrkkrp/ormolu-action@v9 with: extra-args: >- - --ghc-opt -XDerivingStrategies - --ghc-opt -XImportQualifiedPost - --ghc-opt -XMultiParamTypeClasses - --ghc-opt -XStandaloneDeriving - --ghc-opt -XTemplateHaskell - --ghc-opt -XUnicodeSyntax - + --ghc-opt -XDerivingStrategies --ghc-opt -XImportQualifiedPost + --ghc-opt -XMultiParamTypeClasses --ghc-opt -XStandaloneDeriving + --ghc-opt -XTemplateHaskell --ghc-opt -XUnicodeSyntax clang-format: runs-on: ubuntu-latest steps: @@ -48,218 +42,108 @@ jobs: - uses: jidicula/clang-format-action@v4.10.1 with: clang-format-version: '15' - check-path: 'runtime/src' - + check-path: runtime/src pre-commit: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - uses: actions/setup-python@v4 - with: - python-version: '3.9' - - uses: pre-commit/action@v3.0.0 - with: - extra_args: - trailing-whitespace --all-files - - uses: pre-commit/action@v3.0.0 - with: - extra_args: - end-of-file-fixer --all-files - - uses: pre-commit/action@v3.0.0 - with: - extra_args: - check-yaml --all-files - - uses: pre-commit/action@v3.0.0 - with: - extra_args: - check-added-large-files --all-files - - uses: pre-commit/action@v3.0.0 - with: - extra_args: - check-case-conflict --all-files - - uses: pre-commit/action@v3.0.0 - with: - extra_args: - mixed-line-ending --all-files - - build: - runs-on: ${{ matrix.os }} - strategy: - matrix: - os: [macos-12 , ubuntu-20.04] - ghc: ["9.2.5"] - steps: - - name: Checkout our repository - uses: actions/checkout@v3 + - uses: actions/checkout@v3 + - uses: actions/setup-python@v4 with: - path: main - submodules: true - - - uses: actions/cache@v3 - name: Cache ~/.stack + python-version: '3.9' + - uses: pre-commit/action@v3.0.0 with: - path: ~/.stack - key: ${{ runner.os }}-${{ matrix.ghc }}-stack-global-${{ hashFiles('main/stack.yaml') }}-${{ hashFiles('main/package.yaml') }} - restore-keys: | - ${{ runner.os }}-${{ matrix.ghc }}-stack-global- - - - uses: actions/cache@v3 - name: Cache .stack-work + extra_args: trailing-whitespace --all-files + - uses: pre-commit/action@v3.0.0 with: - path: main/.stack-work - key: ${{ runner.os }}-${{ matrix.ghc }}-stack-work-${{ hashFiles('main/stack.yaml') }}-${{ hashFiles('main/package.yaml') }}-${{ hashFiles('main/**/*.hs') }} - restore-keys: | - ${{ runner.os }}-${{ matrix.ghc }}-stack-work- - - - uses: haskell/actions/setup@v2 - name: Setup Haskell + extra_args: end-of-file-fixer --all-files + - uses: pre-commit/action@v3.0.0 with: - ghc-version: ${{ matrix.ghc }} - enable-stack: true - stack-version: 'latest' - - - name: Cache LLVM and Clang (Linux) - if: runner.os == 'Linux' - id: cache-llvm - uses: actions/cache@v3 + extra_args: check-yaml --all-files + - uses: pre-commit/action@v3.0.0 with: - path: | - C:/Program Files/LLVM - ./llvm - key: ${{ runner.os }}-llvm-13 - - - name: Install LLVM and Clang (Linux) - if: runner.os == 'Linux' - uses: KyleMayes/install-llvm-action@v1 + extra_args: check-added-large-files --all-files + - uses: pre-commit/action@v3.0.0 with: - version: "13.0" - cached: ${{ steps.cache-llvm.outputs.cache-hit }} - - - name: Set homebrew LLVM CC and LIBTOOL vars (macOS) - if: runner.os == 'macOS' - run: | - echo "CC=$(brew --prefix llvm)/bin/clang" >> $GITHUB_ENV - echo "LIBTOOL=$(brew --prefix llvm)/bin/llvm-ar" >> $GITHUB_ENV - - - name: Install ICU4C - if: startsWith(matrix.os, 'macos-') - run: | - brew install icu4c - brew link icu4c --force - - - name: Install libicu for testing - if: startsWith(matrix.os, 'ubuntu-') - run: sudo apt install -y libicu66 - - - name: Build Project (macOS) - if: runner.os == 'macOS' - run: | - cd main - make CC=$CC LIBTOOL=$LIBTOOL build - - - name: Build Project (Linux) - if: runner.os == 'Linux' - run: | - cd main - make build + extra_args: check-case-conflict --all-files + - uses: pre-commit/action@v3.0.0 + with: + extra_args: mixed-line-ending --all-files - test: - needs: build - runs-on: ${{ matrix.os }} - strategy: - matrix: - os: [ubuntu-20.04, macos-12] - ghc: ["9.2.5"] + build-and-test-linux: + runs-on: ubuntu-20.04 steps: - - name: Checkout the main repository + - name: Checkout our repository uses: actions/checkout@v3 with: path: main - submodules: recursive - - - uses: actions/cache@v3 - name: Cache ~/.stack + submodules: true + - uses: actions/cache/restore@v3 + id: stack-cache + name: Restore .stack cache with: - path: ~/.stack - key: ${{ runner.os }}-${{ matrix.ghc }}-stack-global-${{ hashFiles('main/stack.yaml') }}-${{ hashFiles('main/package.yaml') }} - restore-keys: | - ${{ runner.os }}-${{ matrix.ghc }}-stack-global- + path: ${{ github.workspace }}/.stack + key: ${{ runner.os }}-stack- - - uses: actions/cache@v3 - name: Cache .stack-work + - uses: actions/cache/restore@v3 + id: stack-work-cache + name: Restore main/.stack-work cache with: path: main/.stack-work - key: ${{ runner.os }}-${{ matrix.ghc }}-stack-work-${{ hashFiles('main/stack.yaml') }}-${{ hashFiles('main/package.yaml') }}-${{ hashFiles('main/**/*.hs') }} - restore-keys: | - ${{ runner.os }}-${{ matrix.ghc }}-stack-work- + key: ${{ runner.os }}-stack-work- - uses: haskell/actions/setup@v2 name: Setup Haskell with: - ghc-version: ${{ matrix.ghc }} + ghc-version: 9.2.5 enable-stack: true - stack-version: 'latest' + stack-version: latest - - name: Cache LLVM and Clang (Linux) - if: runner.os == 'Linux' + - name: Cache LLVM and Clang id: cache-llvm uses: actions/cache@v3 with: path: | C:/Program Files/LLVM ./llvm - key: ${{ runner.os }}-llvm-13 + key: '${{ runner.os }}-llvm-13' - - name: Install LLVM and Clang (Linux) - if: runner.os == 'Linux' + - name: Install LLVM and Clang uses: KyleMayes/install-llvm-action@v1 with: - version: "13.0" - cached: ${{ steps.cache-llvm.outputs.cache-hit }} + version: '13.0' + cached: '${{ steps.cache-llvm.outputs.cache-hit }}' - name: Download and extract wasi-sysroot - run: | - curl https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-15/wasi-sysroot-15.0.tar.gz -OL - tar xfv wasi-sysroot-15.0.tar.gz + run: > + curl + https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-15/wasi-sysroot-15.0.tar.gz + -OL + tar xfv wasi-sysroot-15.0.tar.gz - name: Set WASI_SYSROOT_PATH run: | echo "WASI_SYSROOT_PATH=$GITHUB_WORKSPACE/wasi-sysroot" >> $GITHUB_ENV - name: Install the latest Wasmer version - uses: jonaprieto/action-install-gh-release@1 + uses: jonaprieto/action-install-gh-release@2 with: repo: wasmerio/wasmer tag: latest binaries-location: bin cache: true - - name: Set homebrew LLVM CC and LIBTOOL vars (macOS) - if: runner.os == 'macOS' - run: | - echo "CC=$(brew --prefix llvm)/bin/clang" >> $GITHUB_ENV - echo "LIBTOOL=$(brew --prefix llvm)/bin/llvm-ar" >> $GITHUB_ENV - - - name: stack setup (macOS) - if: runner.os == 'macOS' - run: | - cd main - stack setup - - - name: Add homebrew clang to the PATH (macOS) - if: runner.os == 'macOS' - run: | - echo "$(brew --prefix llvm)/bin" >> $GITHUB_PATH + - name: Install libicu for testing + run: sudo apt install -y libicu66 - - name: Test suite (macOS) - if: runner.os == 'macOS' + - name: Build Project run: | cd main - make CC=$CC LIBTOOL=$LIBTOOL test + stack path --stack-root + make build - - name: Test suite (linux) + - name: Test suite id: test - if: runner.os == 'Linux' + if: ${{ success() }} run: | cd main make test @@ -268,52 +152,43 @@ jobs: run: | echo "$HOME/.local/bin" >> $GITHUB_PATH - - name: Download Smoke binary - uses: jaxxstorm/action-install-gh-release@v1.9.0 - if: runner.os == 'macOS' - with: - repo: jonaprieto/smoke - tag: v2.3.2 - cache: enable - extension-matching: disable - rename-to: smoke - chmod: 0755 - - - name : Smoke testing (macOS) - id: smoke-macos - if: runner.os == 'macOS' - run : | - cd main - make CC=$CC LIBTOOL=$LIBTOOL smoke - - uses: actions/checkout@v3 - if: runner.os == 'Linux' with: repository: jonaprieto/smoke path: smoke - name: Install Smoke - if: runner.os == 'Linux' run: | cd smoke - stack install + stack install --stack-root ${{ github.workspace }}/.stack shell: bash - - name : Smoke testing (linux) + - name: Smoke testing id: smoke-linux - if: runner.os == 'Linux' - run : | + if: ${{ success() }} + run: | cd main make smoke - docs: - needs: build - if: github.ref == 'refs/heads/main' || github.event_name == 'workflow_dispatch' - strategy: - matrix: - os: [ubuntu-20.04] - ghc: ["9.2.5"] - runs-on: ${{ matrix.os }} + - name: Save cache .stack + uses: actions/cache/save@v3 + if: always() + with: + path: ${{ github.workspace }}/.stack + key: '${{ steps.stack-cache.outputs.cache-primary-key }}' + + - name: Save cache main/.stack-work if the job was successful + uses: actions/cache/save@v3 + with: + path: main/.stack-work + key: '${{ steps.stack-work-cache.outputs.cache-primary-key }}' + + docs-linux: + needs: build-and-test-linux + if: >- + github.ref == 'refs/heads/main' || github.event_name == + 'workflow_dispatch' + runs-on: ubuntu-20.04 steps: - name: Checkout our repository uses: actions/checkout@v3 @@ -321,37 +196,37 @@ jobs: path: main submodules: recursive - - uses: actions/cache@v3 - name: Cache ~/.stack + - uses: actions/cache/restore@v3 + name: Restore .stack cache + id: stack-cache with: - path: ~/.stack - key: ${{ runner.os }}-${{ matrix.ghc }}-stack-global-${{ hashFiles('main/stack.yaml') }}-${{ hashFiles('main/package.yaml') }} - restore-keys: | - ${{ runner.os }}-${{ matrix.ghc }}-stack-global- + fail-on-cache-miss: true + path: ${{ github.workspace }}/.stack + key: ${{ runner.os }}-stack- - - uses: actions/cache@v3 - name: Cache .stack-work + - uses: actions/cache/restore@v3 + name: Restore main/.stack-work cache + id: stack-work-cache with: + fail-on-cache-miss: true path: main/.stack-work - key: ${{ runner.os }}-${{ matrix.ghc }}-stack-work-${{ hashFiles('main/stack.yaml') }}-${{ hashFiles('main/package.yaml') }}-${{ hashFiles('main/**/*.hs') }} - restore-keys: | - ${{ runner.os }}-${{ matrix.ghc }}-stack-work- + key: ${{ runner.os }}-stack-work- - uses: r-lib/actions/setup-pandoc@v2 with: - pandoc-version: '2.19.2' + pandoc-version: 2.19.2 - name: MDBook setup uses: peaceiris/actions-mdbook@v1 with: - mdbook-version: '0.4.22' + mdbook-version: 0.4.22 - uses: haskell/actions/setup@v2 name: Setup Haskell with: - ghc-version: ${{ matrix.ghc }} + ghc-version: 9.2.5 enable-stack: true - stack-version: 'latest' + stack-version: latest - name: Cache LLVM and Clang id: cache-llvm @@ -360,21 +235,21 @@ jobs: path: | C:/Program Files/LLVM ./llvm - key: ${{ runner.os }}-llvm-13 + key: '${{ runner.os }}-llvm-13' - name: Install LLVM and Clang uses: KyleMayes/install-llvm-action@v1 with: - version: "13.0" - cached: ${{ steps.cache-llvm.outputs.cache-hit }} + version: '13.0' + cached: '${{ steps.cache-llvm.outputs.cache-hit }}' - name: Generate Markdown files for each Org file run: | cd main make markdown-docs - - name : Generate HTML and Web App files from milestone examples - run : | + - name: Generate HTML and Web App files from milestone examples + run: | cd main echo "$GITHUB_WORKSPACE/.local/bin" >> $GITHUB_PATH make install @@ -385,7 +260,119 @@ jobs: - name: Deploy HTML to github pages uses: peaceiris/actions-gh-pages@v3 with: - github_token: ${{ secrets.GITHUB_TOKEN }} + github_token: '${{ secrets.GITHUB_TOKEN }}' publish_dir: main/_docs enable_jekyll: false cname: docs.juvix.org + + build-and-test-macos: + runs-on: macos-12 + steps: + - name: Checkout our repository + uses: actions/checkout@v3 + with: + path: main + submodules: true + + - uses: actions/cache/restore@v3 + id: stack-cache + name: Restore .stack cache + with: + path: ${{ github.workspace }}/.stack + key: ${{ runner.os }}-stack- + + - uses: actions/cache/restore@v3 + name: Restore main/.stack-work cache + id: stack-work-cache + with: + path: main/.stack-work + key: ${{ runner.os }}-stack-work- + + - uses: haskell/actions/setup@v2 + name: Setup Haskell + with: + ghc-version: 9.2.5 + enable-stack: true + stack-version: latest + - name: Set homebrew LLVM CC and LIBTOOL vars (macOS) + run: | + echo "CC=$(brew --prefix llvm)/bin/clang" >> $GITHUB_ENV + echo "LIBTOOL=$(brew --prefix llvm)/bin/llvm-ar" >> $GITHUB_ENV + - name: Install ICU4C + run: | + brew install icu4c + brew link icu4c --force + - name: Build Project (macOS) + run: | + cd main + stack path --stack-root + make CC=$CC LIBTOOL=$LIBTOOL build + + - name: Download and extract wasi-sysroot + run: > + curl + https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-15/wasi-sysroot-15.0.tar.gz + -OL + + tar xfv wasi-sysroot-15.0.tar.gz + - name: Set WASI_SYSROOT_PATH + run: | + echo "WASI_SYSROOT_PATH=$GITHUB_WORKSPACE/wasi-sysroot" >> $GITHUB_ENV + - name: Install the latest Wasmer version + uses: jonaprieto/action-install-gh-release@2 + with: + repo: wasmerio/wasmer + tag: latest + binaries-location: bin + cache: true + + - name: Set homebrew LLVM CC and LIBTOOL vars (macOS) + run: | + echo "CC=$(brew --prefix llvm)/bin/clang" >> $GITHUB_ENV + echo "LIBTOOL=$(brew --prefix llvm)/bin/llvm-ar" >> $GITHUB_ENV + - name: stack setup (macOS) + run: | + cd main + stack setup + - name: Add homebrew clang to the PATH (macOS) + run: | + echo "$(brew --prefix llvm)/bin" >> $GITHUB_PATH + - name: Test suite (macOS) + if: ${{ success() }} + run: | + cd main + make CC=$CC LIBTOOL=$LIBTOOL test + + - name: Save stack cache + uses: actions/cache/save@v3 + if: always() + with: + path: ${{ github.workspace }}/.stack + key: '${{ steps.stack-cache.outputs.cache-primary-key }}' + + - name: Save stack-work cache + uses: actions/cache/save@v3 + if: always() + with: + path: main/.stack-work + key: '${{ steps.stack-work-cache.outputs.cache-primary-key }}' + + - name: Add ~/.local/bin to PATH + run: | + echo "$HOME/.local/bin" >> $GITHUB_PATH + + - name: Install Smoke + uses: jonaprieto/action-install-gh-release@2 + with: + repo: jonaprieto/smoke + tag: latest + extension-matching: disable + rename-to: smoke + chmod: 0755 + + - name: Smoke testing (macOS) + id: smoke-macos + if: ${{ success() }} + run: | + cd main + make CC=$CC LIBTOOL=$LIBTOOL smoke