From 81acac128f7452a7ad2371e25e5dfd146ba19071 Mon Sep 17 00:00:00 2001
From: Miles Johnson <mileswjohnson@gmail.com>
Date: Mon, 17 Apr 2023 14:13:30 -0700
Subject: [PATCH] Polish.

---
 action.yml |  6 +++---
 helpers.ts |  4 ++++
 index.ts   | 22 +++++++++-------------
 post.ts    | 10 ++++------
 4 files changed, 20 insertions(+), 22 deletions(-)

diff --git a/action.yml b/action.yml
index d66ff08..7371bf4 100644
--- a/action.yml
+++ b/action.yml
@@ -7,7 +7,7 @@ inputs:
   bins:
     description: 'Comma-separated list of global binaries to install into Cargo.'
   cache:
-    description: 'Toggle caching of ~/.cargo/registry and /target.'
+    description: 'Toggle caching of ~/.cargo/registry and /target/debug directories.'
     default: true
   channel:
     description: 'Toolchain specification/channel to install.'
@@ -19,9 +19,9 @@ inputs:
     description: 'Profile to install. Defaults to "minimal".'
 outputs:
   cache-key:
-    description: 'The cache key used.'
+    description: 'The generated cache key used.'
   cache-hit:
-    description: 'A boolean to indicate an exact match was found for the cache key.'
+    description: 'Indicates an exact match was found for the cache key.'
 runs:
   using: 'node16'
   main: 'dist/index.js'
diff --git a/helpers.ts b/helpers.ts
index 772676b..369d3f9 100644
--- a/helpers.ts
+++ b/helpers.ts
@@ -1,9 +1,13 @@
 import os from 'os';
 import path from 'path';
+import * as cache from '@actions/cache';
+import * as core from '@actions/core';
 
 // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
 export const CARGO_HOME = process.env.CARGO_HOME || path.join(os.homedir(), '.cargo');
 
+export const CACHE_ENABLED = core.getBooleanInput('cache') || cache.isFeatureAvailable();
+
 export function getPrimaryCacheKey(): string {
 	return `setup-rustcargo-${process.platform}`;
 }
diff --git a/index.ts b/index.ts
index bd29f81..16e3b31 100644
--- a/index.ts
+++ b/index.ts
@@ -5,7 +5,7 @@ import * as core from '@actions/core';
 import * as exec from '@actions/exec';
 import * as tc from '@actions/tool-cache';
 import TOML from '@ltd/j-toml';
-import { CARGO_HOME, getPathsToCache, getPrimaryCacheKey } from './helpers';
+import { CACHE_ENABLED, CARGO_HOME, getPathsToCache, getPrimaryCacheKey } from './helpers';
 
 interface Toolchain {
 	channel: string;
@@ -171,7 +171,7 @@ async function installBins() {
 		.filter(Boolean)
 		.map((bin) => (bin.startsWith('cargo-') ? bin : `cargo-${bin}`));
 
-	if (core.getBooleanInput('cache')) {
+	if (CACHE_ENABLED) {
 		bins.push('cargo-cache');
 	}
 
@@ -191,25 +191,21 @@ async function installBins() {
 }
 
 async function restoreCache() {
-	const enabled = core.getBooleanInput('cache');
-
-	if (!cache.isFeatureAvailable() || !enabled) {
+	if (!CACHE_ENABLED) {
 		return;
 	}
 
 	core.info('Attempting to restore cache');
 
 	const primaryKey = await getPrimaryCacheKey();
-	const cacheKey = await cache.restoreCache(
-		getPathsToCache(),
-		primaryKey,
-		[`setup-rustcargo-${process.platform}`, 'setup-rustcargo'],
-		{},
-		false,
-	);
+
+	const cacheKey = await cache.restoreCache(getPathsToCache(), primaryKey, [
+		`setup-rustcargo-${process.platform}`,
+		'setup-rustcargo',
+	]);
 
 	if (cacheKey) {
-		core.saveState('cacheHitKey', cacheKey);
+		core.saveState('cache-hit-key', cacheKey);
 		core.info(`Cache restored using key ${primaryKey}`);
 	} else {
 		core.warning(`Cache does not exist using key ${primaryKey}`);
diff --git a/post.ts b/post.ts
index dba0814..5ce313b 100644
--- a/post.ts
+++ b/post.ts
@@ -1,17 +1,15 @@
 import * as cache from '@actions/cache';
 import * as core from '@actions/core';
 import * as exec from '@actions/exec';
-import { getPathsToCache, getPrimaryCacheKey } from './helpers';
+import { CACHE_ENABLED, getPathsToCache, getPrimaryCacheKey } from './helpers';
 
 async function saveCache() {
-	const enabled = core.getBooleanInput('cache');
-
-	if (!cache.isFeatureAvailable() || !enabled) {
+	if (!CACHE_ENABLED) {
 		return;
 	}
 
 	const primaryKey = getPrimaryCacheKey();
-	const cacheHitKey = core.getState('cacheHitKey');
+	const cacheHitKey = core.getState('cache-hit-key');
 
 	if (cacheHitKey === primaryKey) {
 		core.info(`Cache hit occured on the key ${cacheHitKey}, not saving cache`);
@@ -24,7 +22,7 @@ async function saveCache() {
 
 	core.info(`Saving cache with key ${primaryKey}`);
 
-	await cache.saveCache(getPathsToCache(), primaryKey, {}, false);
+	await cache.saveCache(getPathsToCache(), primaryKey);
 }
 
 async function run() {