Skip to content
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

Use cabal-cache #4717

Merged
merged 1 commit into from
Dec 21, 2022
Merged

Use cabal-cache #4717

merged 1 commit into from
Dec 21, 2022

Conversation

newhoggy
Copy link
Contributor

@newhoggy newhoggy commented Dec 16, 2022

Use cabal-cache to cache cabal packages.

This is better than using actions/cache@v2 because cabal-cache is a fine grained cache that caches each built cabal package individually.

This means that if any packages were built successfully in CI, even if CI fails, we can still upload those packages that successfully built. This is far superior to the situation we have now which is if CI fails we cache nothing.

This is especially useful for those occasions where we update the index state or change our package dependencies (including package dependency bounds) because currently for those cases, a failed build means we cache nothing which hurts iteration times very badly.

The change keeps the build time more reliably tight:

Screenshot 2022-12-21 at 2 12 17 pm

Compare this to the old caching method:

Screenshot 2022-12-21 at 5 17 59 pm

The PR also fixes a bug which mean that MacOS builds weren't cached at all (ie. the 89m MacOS build time in the old caching method).

@newhoggy newhoggy force-pushed the newhoggy/use-cabal-cache branch 17 times, most recently from 22e09ef to c94fe3e Compare December 20, 2022 23:29
echo "cabal-store=$(dirname "$cabal_config_file")/store" | tee -a "$GITHUB_OUTPUT"
else
echo "cabal-store=C:\\cabal\\store" | tee -a "$GITHUB_OUTPUT"
fi
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unify the computation of the cabal store directory to a single step. This makes referencing the cabal store in later steps easier.

This also fixes the problem where on MacOS, the cabal-store=/home/runner/.cabal/store is incorrect. This should be /Users/runner/.cabal/store.

To avoid this problem in future, on Linux and MacOS, the step queries cabal for the some information to compute the location of the cabal store.

Copy link
Contributor

Choose a reason for hiding this comment

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

Can you put this as a comment in the file?

store-path: ${{ steps.cabal-store.outputs.cabal-store }}
threads: 16
archive-uri: ${{ secrets.BINARY_CACHE_URI }}
skip: "${{ secrets.BINARY_CACHE_URI == '' }}"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This step syncs the cabal store with S3, an object store service (think a service for storing files).

The S3 bucket is set to s3://iohk.cache.haskellworks.io.

Copy link
Contributor

Choose a reason for hiding this comment

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

Likewise

threads: 16
archive-uri: https://iohk.cache.haskellworks.io
skip: "${{ secrets.BINARY_CACHE_URI != '' }}"
enable-save: false
Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's important to ensure that people who fork this repository can not only successfully build in CI by default, but also have meaning cabal store caching.

Because syncing with S3 requires credentials, we cannot rely on S3 for this. For this reason a https fallback is used. The https server mirrors the content of the S3 bucket. The https cabal store archive is read-only for security reasons.

Users who fork this repository who want to have a writable cabal store archive are encouraged to set up their own S3 bucket.

Copy link
Contributor

Choose a reason for hiding this comment

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

and this

@@ -288,6 +291,8 @@ jobs:
# - name: Setup tmate session
# if: ${{ failure() }}
# uses: mxschmitt/action-tmate@v3
# with:
# limit-access-to-actor: true
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Adding this to the commented out tmate step for security reasons in case someone decides to use it.

@newhoggy newhoggy marked this pull request as ready for review December 20, 2022 23:42
@newhoggy newhoggy requested review from Jimbo4350 and a team as code owners December 20, 2022 23:42
@newhoggy newhoggy force-pushed the newhoggy/use-cabal-cache branch 5 times, most recently from ecac7f4 to 54e5140 Compare December 21, 2022 01:30
@newhoggy newhoggy force-pushed the newhoggy/use-cabal-cache branch 2 times, most recently from 33dde0c to f49bfd4 Compare December 21, 2022 07:11
Copy link
Contributor

@Jimbo4350 Jimbo4350 left a comment

Choose a reason for hiding this comment

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

Nice 👍 . Just add the comments to the haskell.yml file

@newhoggy newhoggy force-pushed the newhoggy/use-cabal-cache branch from f49bfd4 to 0d75329 Compare December 21, 2022 22:28
@newhoggy newhoggy merged commit 6c859e0 into master Dec 21, 2022
@iohk-bors iohk-bors bot deleted the newhoggy/use-cabal-cache branch December 21, 2022 22:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants