@@ -4,7 +4,15 @@ import { exists as existsCb } from "fs";
44import { URL } from "url" ;
55import { promisify } from "util" ;
66
7- import { debug , info , setOutput , addPath , warning } from "@actions/core" ;
7+ import {
8+ debug ,
9+ info ,
10+ setOutput ,
11+ addPath ,
12+ warning ,
13+ saveState ,
14+ getState ,
15+ } from "@actions/core" ;
816import { mv , rmRF , mkdirP , which } from "@actions/io" ;
917import { exec } from "@actions/exec" ;
1018import { restoreCache , saveCache } from "@actions/cache" ;
@@ -22,7 +30,9 @@ import { Config, CacheMode } from "./config";
2230const exists = promisify ( existsCb ) ;
2331
2432export default class Installer {
33+ private static CacheStateKey = "cache-result" ;
2534 private static CacheDir = join ( ".cache" , "qt" ) ;
35+
2636 private readonly _config : Config ;
2737 private readonly _platform : IPlatform ;
2838 private readonly _cacheKey : string ;
@@ -106,6 +116,8 @@ export default class Installer {
106116 await this . _platform . runPostInstall ( false , toolPath ) ;
107117 if ( this . _config . cacheMode === CacheMode . Default ) {
108118 await this . storeCache ( ) ;
119+ } else {
120+ saveState ( Installer . CacheStateKey , "true" ) ;
109121 }
110122 } else {
111123 await this . _platform . runPostInstall ( true , toolPath ) ;
@@ -144,7 +156,8 @@ export default class Installer {
144156 }
145157
146158 public async post ( ) : Promise < void > {
147- if ( this . _config . cacheMode === CacheMode . Post ) {
159+ const shouldCache = getState ( Installer . CacheStateKey ) ;
160+ if ( this . _config . cacheMode === CacheMode . Post && shouldCache === "true" ) {
148161 await this . storeCache ( ) ;
149162 }
150163 }
0 commit comments