Applied code to delete the file if cancelled the workflow

This commit is contained in:
shaanmugapriya 2024-02-12 18:28:15 +05:30
parent d03d4fe9c6
commit 66808a5f19
2 changed files with 50 additions and 10 deletions

29
dist/setup/index.js vendored
View File

@ -93328,6 +93328,7 @@ const cache_utils_1 = __nccwpck_require__(1678);
const cache_restore_1 = __nccwpck_require__(9517);
const constants_1 = __nccwpck_require__(9042);
const json5_1 = __importDefault(__nccwpck_require__(6904));
const os = __importStar(__nccwpck_require__(2037));
const qualityOptions = [
'daily',
'signed',
@ -93336,6 +93337,7 @@ const qualityOptions = [
'ga'
];
let cancelled = false;
let errorOccurred = false;
process.on('SIGINT', () => {
cancelled = true;
});
@ -93362,6 +93364,8 @@ function run() {
versions.push(getVersionFromGlobalJson(globalJsonPath));
}
if (!versions.length) {
// Try to fall back to global.json
core.debug('No version found, trying to find version from global.json');
const globalJsonPath = path_1.default.join(process.cwd(), 'global.json');
if (fs.existsSync(globalJsonPath)) {
versions.push(getVersionFromGlobalJson(globalJsonPath));
@ -93401,11 +93405,28 @@ function run() {
core.info(`##[add-matcher]${path_1.default.join(matchersPath, 'csc.json')}`);
}
catch (error) {
if (error.message === 'Cancelled') {
core.setFailed(error.message);
errorOccurred = true;
}
finally {
if (errorOccurred || cancelled) {
console.log('Cleaning up...');
}
else {
core.setFailed(error.message);
let directoryPath;
switch (os.platform()) {
case 'win32':
directoryPath = 'C:\\Program Files\\dotnet';
break;
case 'darwin':
directoryPath = '/usr/local/share/dotnet';
break;
case 'linux':
directoryPath = '/usr/share/dotnet';
break;
default:
throw new Error(`Unsupported platform: ${os.platform()}`);
}
fs.rmdirSync(directoryPath, { recursive: true });
console.log(`Directory ${directoryPath} has been deleted.`);
}
}
});

View File

@ -8,6 +8,7 @@ import {isCacheFeatureAvailable} from './cache-utils';
import {restoreCache} from './cache-restore';
import {Outputs} from './constants';
import JSON5 from 'json5';
import * as os from 'os';
const qualityOptions = [
'daily',
@ -20,6 +21,8 @@ const qualityOptions = [
export type QualityOptions = (typeof qualityOptions)[number];
let cancelled = false;
let errorOccurred = false;
let unsupportedPlatform = false;
process.on('SIGINT', () => {
cancelled = true;
});
@ -97,13 +100,29 @@ export async function run() {
await restoreCache(cacheDependencyPath);
}
const matchersPath = path.join(__dirname, '..', '..', '.github');
core.info(`##[add-matcher]${path.join(matchersPath, 'csc.json')}`);
} catch (error) {
if (error.message === 'Cancelled') {
'Cleaning up...';
} else {
core.setFailed(error.message);
core.setFailed(error.message);
errorOccurred = true;
} finally {
if (errorOccurred || cancelled) {
('Cleaning up...');
let directoryPath: string;
switch (os.platform()) {
case 'win32':
directoryPath = 'C:\\Program Files\\dotnet';
break;
case 'darwin':
directoryPath = '/usr/local/share/dotnet';
break;
case 'linux':
directoryPath = '/usr/share/dotnet';
break;
default:
directoryPath = 'Unsupported platform';
}
if (!unsupportedPlatform && fs.existsSync(directoryPath)) {
fs.rmdirSync(directoryPath, { recursive: true });
core.info(`Directory ${directoryPath} has been deleted.`);
}
}
}