Skip to content

Commit eb31af6

Browse files
authored
Use init-pants-action in gha workflow (#106)
This shows the new init-pants-action in GHA.
1 parent e6cfdb4 commit eb31af6

File tree

1 file changed

+19
-42
lines changed

1 file changed

+19
-42
lines changed

.github/workflows/pants.yaml

Lines changed: 19 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -18,61 +18,38 @@ jobs:
1818
build:
1919
name: Perform CI Checks
2020
needs: org-check
21-
env:
22-
PANTS_CONFIG_FILES: pants.ci.toml
2321
runs-on: ubuntu-latest
2422
strategy:
2523
matrix:
2624
python-version: [3.7]
2725
steps:
2826
- uses: actions/checkout@v2
29-
- name: Get Pants version
30-
id: pants_version
31-
run: |
32-
# Capture the "pants_version = " line from config.
33-
PANTS_VERSION=$(grep -E '^pants_version\s*=' pants.toml)
34-
echo "::set-output name=pants_version::$PANTS_VERSION"
35-
- uses: actions/cache@v2
36-
id: cache_pants_setup
37-
with:
38-
path: |
39-
~/.cache/pants/setup
40-
key: pants-setup-${{ steps.pants_version.outputs.pants_version }}
41-
- uses: actions/cache@v2
42-
id: cached_named_caches
27+
- uses: pantsbuild/actions/init-pants@c0ce05ee4ba288bb2a729a2b77294e9cb6ab66f7
28+
# This action bootstraps pants and manages 2-3 GHA caches.
29+
# See: github.com/pantsbuild/actions/tree/init-pants/
30+
# We use an action SHA because there are no tags yet.
4331
with:
44-
path: |
45-
~/.cache/pants/named_caches
32+
# cache0 makes it easy to bust the cache if needed
33+
# just increase the integer to start with a fresh cache
34+
gha-cache-key: cache0-py${{ matrix.python-version }}
4635
# The Python backend uses named_caches for Pip/PEX state,
47-
# so it is appropriate to invalidate on requirements.txt changes.
48-
key: pants-named-caches-${{ runner.os }}-${{ hashFiles('pants.toml') }}-${{ hashFiles('requirements.txt') }}
49-
# Note that falling back to a restore key may give a useful partial result that will save time
50-
# over completely clean state, but will cause the cache entry to grow without bound over time.
36+
# so it is appropriate to invalidate on lockfile changes.
37+
named-caches-hash: ${{ hashFiles('lockfile.txt') }}
38+
# If you're not using a fine-grained remote caching service (see https://www.pantsbuild.org/docs/remote-caching),
39+
# then you may also want to preserve the local Pants cache (lmdb_store). However this must invalidate for
40+
# changes to any file that can affect the build, so may not be practical in larger repos.
41+
# A remote cache service integrates with Pants's fine-grained invalidation and avoids these problems.
42+
cache-lmdb-store: 'true' # defaults to 'false'
43+
# Note that named_caches and lmdb_store falls back to partial restore keys which
44+
# may give a useful partial result that will save time over completely clean state,
45+
# but will cause the cache entry to grow without bound over time.
5146
# See https://pants.readme.io/docs/using-pants-in-ci for tips on how to periodically clean it up.
52-
# Alternatively you may want to avoid using restore keys.
53-
restore-keys: |
54-
pants-named-caches-${{ runner.os }}-${{ hashFiles('pants.toml') }}-${{ hashFiles('requirements.txt') }}
55-
pants-named-caches-${{ runner.os }}-${{ hashFiles('pants.toml') }}-
56-
pants-named-caches-${{ runner.os }}-
57-
# If you're not using a fine-grained remote caching service (see https://www.pantsbuild.org/docs/remote-caching),
58-
# then you may also want to preserve the local Pants cache (lmdb_store). However this must invalidate for
59-
# changes to any file that can affect the build, so may not be practical in larger repos.
60-
# A remote cache service integrates with Pants's fine-grained invalidation and avoids these problems.
61-
- uses: actions/cache@v2
62-
id: cache_lmdb_store
63-
with:
64-
path: |
65-
~/.cache/pants/lmdb_store
66-
key: pants-lmdb-store-${{ runner.os }}-${{ hashFiles('**/*') }}
67-
# Same caveat as above regarding the issues with restore keys.
68-
restore-keys: pants-lmdb-store-${{ runner.os }}-
47+
# Alternatively you change gha-cache-key to ignore old caches.
48+
6949
- name: Setup Python ${{ matrix.python-version }}
7050
uses: actions/setup-python@v1
7151
with:
7252
python-version: ${{ matrix.python-version }}
73-
- name: Bootstrap Pants
74-
run: |
75-
./pants --version
7653
- name: Check BUILD files
7754
run: ./pants tailor --check update-build-files --check
7855
- name: Lint and typecheck

0 commit comments

Comments
 (0)