Skip to content

Commit

Permalink
Add validation for post step (#3)
Browse files Browse the repository at this point in the history
* work on fixing cache post step

* fix tests
  • Loading branch information
dmitry-shibanov authored Aug 18, 2021
1 parent 5f3f74c commit 53f73ba
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 4 deletions.
4 changes: 4 additions & 0 deletions __tests__/cleanup-java.test.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
import { run as cleanup } from '../src/cleanup-java';
import * as core from '@actions/core';
import * as cache from '@actions/cache';
import * as util from '../src/util';

describe('cleanup', () => {
let spyWarning: jest.SpyInstance<void, Parameters<typeof core.warning>>;
let spyCacheSave: jest.SpyInstance<
ReturnType<typeof cache.saveCache>,
Parameters<typeof cache.saveCache>
>;
let spyJobStatusSuccess: jest.SpyInstance;

beforeEach(() => {
spyWarning = jest.spyOn(core, 'warning');
spyCacheSave = jest.spyOn(cache, 'saveCache');
spyJobStatusSuccess = jest.spyOn(util, 'isJobStatusSuccess');
spyJobStatusSuccess.mockReturnValue(true);
createStateForSuccessfulRestore();
});
afterEach(() => {
Expand Down
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ inputs:
cache:
description: 'Name of the build platform to cache dependencies. It can be "maven" or "gradle".'
required: false
job-status:
description: 'Workaround to pass job status to post job step. This variable is not intended for manual setting'
default: ${{ job.status }}
outputs:
distribution:
description: 'Distribution of Java that has been installed'
Expand Down
11 changes: 9 additions & 2 deletions dist/cleanup/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6185,6 +6185,7 @@ exports.run = void 0;
const core = __importStar(__webpack_require__(470));
const gpg = __importStar(__webpack_require__(884));
const constants = __importStar(__webpack_require__(694));
const util_1 = __webpack_require__(322);
const cache_1 = __webpack_require__(913);
function removePrivateKeyFromKeychain() {
return __awaiter(this, void 0, void 0, function* () {
Expand All @@ -6206,8 +6207,9 @@ function removePrivateKeyFromKeychain() {
*/
function saveCache() {
return __awaiter(this, void 0, void 0, function* () {
const jobStatus = util_1.isJobStatusSuccess();
const cache = core.getInput(constants.INPUT_CACHE);
return cache ? cache_1.save(cache) : Promise.resolve();
return jobStatus && cache ? cache_1.save(cache) : Promise.resolve();
});
}
/**
Expand Down Expand Up @@ -9894,7 +9896,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getToolcachePath = exports.isVersionSatisfies = exports.getDownloadArchiveExtension = exports.extractJdkFile = exports.getVersionFromToolcachePath = exports.getBooleanInput = exports.getTempDir = void 0;
exports.isJobStatusSuccess = exports.getToolcachePath = exports.isVersionSatisfies = exports.getDownloadArchiveExtension = exports.extractJdkFile = exports.getVersionFromToolcachePath = exports.getBooleanInput = exports.getTempDir = void 0;
const os_1 = __importDefault(__webpack_require__(87));
const path_1 = __importDefault(__webpack_require__(622));
const fs = __importStar(__webpack_require__(747));
Expand Down Expand Up @@ -9965,6 +9967,11 @@ function getToolcachePath(toolName, version, architecture) {
return null;
}
exports.getToolcachePath = getToolcachePath;
function isJobStatusSuccess() {
const jobStatus = core.getInput('job-status');
return jobStatus === 'success';
}
exports.isJobStatusSuccess = isJobStatusSuccess;


/***/ }),
Expand Down
7 changes: 6 additions & 1 deletion dist/setup/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19083,7 +19083,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getToolcachePath = exports.isVersionSatisfies = exports.getDownloadArchiveExtension = exports.extractJdkFile = exports.getVersionFromToolcachePath = exports.getBooleanInput = exports.getTempDir = void 0;
exports.isJobStatusSuccess = exports.getToolcachePath = exports.isVersionSatisfies = exports.getDownloadArchiveExtension = exports.extractJdkFile = exports.getVersionFromToolcachePath = exports.getBooleanInput = exports.getTempDir = void 0;
const os_1 = __importDefault(__webpack_require__(87));
const path_1 = __importDefault(__webpack_require__(622));
const fs = __importStar(__webpack_require__(747));
Expand Down Expand Up @@ -19154,6 +19154,11 @@ function getToolcachePath(toolName, version, architecture) {
return null;
}
exports.getToolcachePath = getToolcachePath;
function isJobStatusSuccess() {
const jobStatus = core.getInput('job-status');
return jobStatus === 'success';
}
exports.isJobStatusSuccess = isJobStatusSuccess;


/***/ }),
Expand Down
4 changes: 3 additions & 1 deletion src/cleanup-java.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as core from '@actions/core';
import * as gpg from './gpg';
import * as constants from './constants';
import { isJobStatusSuccess } from './util';
import { save } from './cache';

async function removePrivateKeyFromKeychain() {
Expand All @@ -20,8 +21,9 @@ async function removePrivateKeyFromKeychain() {
* @returns Promise that will be resolved when the save process finishes
*/
async function saveCache() {
const jobStatus = isJobStatusSuccess();
const cache = core.getInput(constants.INPUT_CACHE);
return cache ? save(cache) : Promise.resolve();
return jobStatus && cache ? save(cache) : Promise.resolve();
}

/**
Expand Down
6 changes: 6 additions & 0 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,9 @@ export function getToolcachePath(toolName: string, version: string, architecture

return null;
}

export function isJobStatusSuccess() {
const jobStatus = core.getInput('job-status');

return jobStatus === 'success';
}

0 comments on commit 53f73ba

Please sign in to comment.