MarkusJx / install-boost

Install boost on Github actions
MIT License
62 stars 3 forks source link

Cache? #6

Closed MichaelVoelkel closed 2 years ago

MichaelVoelkel commented 2 years ago

Hi,

looks like a great repo, thanks in advance for that!

By the way, can it be cached?

MarkusJx commented 2 years ago

Hey,

glad you like my work!

If you look for (GitHub-) caching, you might want to take a look at this actions file.

I might want to add this information to the documentation, as this seems useful, since caching the downloaded binaries may speed up the builds by a lot.

As I am not able to call other actions inside my action (or at least this was the case some time ago), you'll need to add the caching step to your actions file manually. From the file linked earlier (minimal example):

# Retrieve the cache, uses cache@v2, you may want to change that as this version may be quite old
- name: Cache boost
  uses: actions/cache@v2
  id: cache-boost
  with:
    # Set the default path as the path to cache (or at least this should be the default path...I think)
    # If you want to change this, check the documentation on how to do that
    path: ${{env.GITHUB_WORKSPACE}}/boost/boost
    # Use the version as the key to only cache the correct version
    key: boost-${{BOOST_VERSION}}

# Actual install step (only runs if the cache is empty)
- name: Install boost
  if: steps.cache-boost.outputs.cache-hit != 'true'
  uses: MarkusJx/install-boost@v2.0.0
  with:
    # Set the boost version (required)
    boost_version: ${{BOOST_VERSION}}

I hope this helps and if you have any further questions, please let me know. If this was not what you were searching for, feel free to re-open this issue.

Have a nice day!

MichaelVoelkel commented 2 years ago

Hmm, by the way, if boost is cached, how do I know the output path from the step? Or should I just assume it's always workspacedir/boost/boost?

MarkusJx commented 2 years ago

If you are referring to this action, the default install location is ${{env.GITHUB_WORKSPACE}}/boost/boost, but this can be changed by setting the boost_install_dir option in your actions file. So if you want to change the install directory, I'd recommend setting an environment variable for setting the path for both actions/cache and this action. Although the BOOST_ROOT output variable gets changed accordingly if you choose to change the install directory, in the setup I suggested (which can only work this way as you'll need to know if boost was found in the cache), this action runs after actions/cache, thus, leaving BOOST_ROOT unset once the cache step runs.

If you are referring to actions/cache, that action always stores the data retrieved from the cache where it was originally located (read more about that here). So if you set the path argument to ${{env.GITHUB_WORKSPACE}}/boost/boost, the cache will always be restored to that path. If you change this, the cache will be restored to the directory you specified. But you may want to test different directory setups as I don't know how actions/cache handles subdirectories and non-existent ones, as the last time I tried this was about a year ago (with a different setup), but this should work, theoretically.

But again, remember if you set the boost_install_dir parameter of this action, you'll have to adapt the path parameter of actions/cache accordingly. So your actions file may actually look like this (using environment variables):

jobs:
  build:
    runs-on: windows-latest
    env:
      # Set your boost version
      BOOST_VERSION: 1.77.0
      # Set you boost path to the default one (I don't know if you can use variables here)
      BOOST_PATH: ${{env.GITHUB_WORKSPACE}}/boost/boost

    steps:
    - uses: actions/checkout@v2

    # Additional steps...

    # Retrieve the cache, uses cache@v2, you may want to change that as this version may be quite old
    - name: Cache boost
      uses: actions/cache@v2
      id: cache-boost
      with:
        # Set the path to cache
        path: ${{env.BOOST_PATH}}
        # Use the version as the key to only cache the correct version
        key: boost-${{env.BOOST_VERSION}}

    # Actual install step (only runs if the cache is empty)
    - name: Install boost
      if: steps.cache-boost.outputs.cache-hit != 'true'
      uses: MarkusJx/install-boost@v2.0.0
      with:
        # Set the boost version (required)
        boost_version: ${{env.BOOST_VERSION}}
        # Set the install directory
        boost_install_dir: ${{env.BOOST_PATH}}