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

Better guidance on how to set up CI with Pants. #104

Merged
merged 5 commits into from
Aug 13, 2022
Merged
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
38 changes: 35 additions & 3 deletions .github/workflows/pants.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,46 @@ jobs:
python-version: [3.7]
steps:
- uses: actions/checkout@v2
- name: Get Pants version
id: pants_version
run: |
# Capture the "pants_version = " line from config.
PANTS_VERSION=$(grep -E '^pants_version\s*=' pants.toml)
Copy link
Member

Choose a reason for hiding this comment

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

Grep is so much easier, lol 😅

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 less accurate in that we're pulling out the entire line, and not just the version string. But for invalidation purposes that is fine! As long as no one tries to use that string for other purposes.

echo "::set-output name=pants_version::$PANTS_VERSION"
- uses: actions/cache@v2
id: cache
id: cache_pants_setup
with:
path: |
~/.cache/pants/setup
~/.cache/pants/lmdb_store
key: pants-setup-${{ steps.pants_version.outputs.pants_version }}
- uses: actions/cache@v2
id: cached_named_caches
with:
path: |
~/.cache/pants/named_caches
benjyw marked this conversation as resolved.
Show resolved Hide resolved
key: ${{ runner.os }}-
# The Python backend uses named_caches for Pip/PEX state,
# so it is appropriate to invalidate on requirements.txt changes.
key: named-caches-${{ runner.os }}-${{ hashFiles('pants.toml') }}-${{ hashFiles('requirements.txt') }}
# Note that falling back to a restore key may give a useful partial result that will save time
# over completely clean state, but will cause the cache entry to grow without bound over time.
# See https://pants.readme.io/docs/using-pants-in-ci for tips on how to periodically clean it up.
# Alternatively you may want to avoid using restore keys.
restore-keys: |
pants-setup-${{ runner.os }}-${{ hashFiles('pants.toml') }}-${{ hashFiles('requirements.txt') }}
pants-setup-${{ runner.os }}-${{ hashFiles('pants.toml') }}-
pants-setup-${{ runner.os }}-
benjyw marked this conversation as resolved.
Show resolved Hide resolved
# If you're not using a fine-grained remote caching service (see https://www.pantsbuild.org/docs/remote-caching),
# then you may also want to preserve the local Pants cache (lmdb_store). However this must invalidate for
# changes to any file that can affect the build, so may not be practical in larger repos.
# A remote cache service integrates with Pants's fine-grained invalidation and avoids these problems.
- uses: actions/cache@v2
id: cache_lmdb_store
with:
path: |
~/.cache/pants/lmdb_store
key: pants-setup-${{ runner.os }}-${{ hashFiles('**/*') }}
Copy link
Member

Choose a reason for hiding this comment

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

Doesn't this mean that you will essentially never hit this cache, unless a PR doesn't change any files?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, exactly. Which is why it's not practical for repos above a certain size. The advantage of it is that with the restore keys you would get some other "close" cache value (the most recent one with the pants-setup-${{ runner.os }}- prefix). I can see this possibly being useful in some scenarios, but probably not generally.

# Same caveat as above regarding the issues with restore keys.
restore-keys: pants-setup-${{ runner.os }}-
benjyw marked this conversation as resolved.
Show resolved Hide resolved
- name: Setup Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
with:
Expand Down