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

Support caching with use-installer when version not specified #76

Closed
hoffa opened this issue Mar 3, 2023 · 2 comments
Closed

Support caching with use-installer when version not specified #76

hoffa opened this issue Mar 3, 2023 · 2 comments
Labels

Comments

@hoffa
Copy link
Contributor

hoffa commented Mar 3, 2023

Context

With #73 merged, SAM CLI is cached when use-installer is enabled and version is specified.

For example:

- uses: aws-actions/setup-sam@v2
  with:
    version: 1.76.0
    use-installer: true

This is beneficial for self-hosted runners that don't get a fresh machine at every workflow run.

Issue

When version is not specified (i.e. it uses the latest available version), it currently does not cache:

setup-sam/lib/setup.js

Lines 137 to 144 in b42eb7a

// TODO: If not set, check latest version and return from cache if exists
if (version) {
const cachedDir = tc.find("sam", version);
if (cachedDir) {
core.info(`Using cached AWS SAM CLI ${version} from ${cachedDir}`);
return path.join(cachedDir, "dist");
}
}

setup-sam/lib/setup.js

Lines 154 to 159 in b42eb7a

// TODO: If not set, cache with latest version
if (version) {
const cachedDir = await tc.cacheDir(extractedDir, "sam", version);
core.info(`Cached AWS SAM CLI ${version} to ${cachedDir}`);
return path.join(cachedDir, "dist");
}

Proposal

Ideally, it would do something like this when version is not specified:

  1. Get the version number of the latest SAM CLI release.
  2. If the version is in the cache, return it.
  3. If not, set up as usual and add the version to the cache.

Challenges

  1. How to reliably get the latest version number, without downloading the full release? If we use the version field in PyPI (e.g. curl https://pypi.org/pypi/aws-sam-cli/json | jq -r .info.version), there's no guarantee the GitHub release for that version will always exist at the same time (they're separate assets, so there can be a brief delay during releases). If we use the GitHub release directly, there's no robust way of getting the version (but could parse the title or tag).

Alternatives

  1. Something like check-latest from actions/setup-go and actions/setup-python? GitHub-hosted runners already include SAM CLI (see e.g. https://github.com/actions/runner-images/blob/main/images/linux/Ubuntu2204-Readme.md), so perhaps by default if it finds SAM CLI is installed, it could immediately return? Might require a new major version, as it no longer installs latest version by default. Might not be a reliable way to ensure pre-installed version is functioning well. The way check-latest works seems to be a little different; it's because the version can be a range, and so instead of picking whatever fits in the range from the cache, it ensures the latest version is used.
@hoffa hoffa added enhancement New feature or request contributions welcome labels Mar 3, 2023
@hoffa hoffa mentioned this issue Mar 3, 2023
@hoffa hoffa changed the title Support caching with use-installer when version not specified Support caching with use-installer when version not specified Mar 4, 2023
@GavinZZ
Copy link
Contributor

GavinZZ commented Oct 27, 2023

Noticed that we easily parse the latest release tag using curl -s https://api.github.com/repos/aws/aws-sam-cli/releases | jq -r '.[0].tag_name'

@GavinZZ
Copy link
Contributor

GavinZZ commented Oct 27, 2023

We've now support caching with use-installer even when version is not specified. Going to mark this issue as completed. Feel free to open a new issue or re-open this one if there's additional questions.

@GavinZZ GavinZZ closed this as completed Oct 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants