From 264190f397d8bc7f513275bcc4ec3269bdbf6f26 Mon Sep 17 00:00:00 2001 From: Maxim Lobanov Date: Fri, 1 May 2020 19:32:08 +0300 Subject: [PATCH 01/22] Implement first version of action --- .github/workflows/test.yml | 49 ++++ .github/workflows/workflow.yml | 20 ++ .gitignore | 2 + LICENSE | 22 ++ README.md | 33 ++- action.yml | 21 ++ dist/index.js | 453 +++++++++++++++++++++++++++++++++ package-lock.json | 31 +++ package.json | 30 +++ scripts/SetPageFileSize.ps1 | 193 ++++++++++++++ src/configure-pagefile.ts | 48 ++++ tsconfig.json | 22 ++ 12 files changed, 923 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/test.yml create mode 100644 .github/workflows/workflow.yml create mode 100644 .gitignore create mode 100644 LICENSE create mode 100644 action.yml create mode 100644 dist/index.js create mode 100644 package-lock.json create mode 100644 package.json create mode 100644 scripts/SetPageFileSize.ps1 create mode 100644 src/configure-pagefile.ts create mode 100644 tsconfig.json diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..9f6d432 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,49 @@ +name: Validate action +on: + pull_request: + schedule: + - cron: 0 0 * * * + +jobs: + default parameters: + strategy: + matrix: + os: [ windows-2016, windows-2019 ] + runs-on: ${{ matrix.os }} + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: configure-pagefile-action + uses: ./ + with: + minimum-size: 8 + + - name: validation + shell: pwsh + runs: | + (Get-CimInstance Win32_PageFileUsage).AllocatedBaseSize + Invoke-Expression "wmic pagefile list /format:list" + + custom-parameters: + strategy: + matrix: + os: [ windows-2016, windows-2019 ] + disk-root: [ "C:", "D:" ] + runs-on: ${{ matrix.os }} + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: configure-pagefile-action + uses: ./ + with: + minimum-size: 4 + maximum-size: 8 + disk-root: ${{ matrix.disk-root }} + + - name: validation + shell: pwsh + runs: | + (Get-CimInstance Win32_PageFileUsage).AllocatedBaseSize + Invoke-Expression "wmic pagefile list /format:list" diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml new file mode 100644 index 0000000..df8679d --- /dev/null +++ b/.github/workflows/workflow.yml @@ -0,0 +1,20 @@ +name: Build action +on: [pull_request] + +jobs: + Build: + runs-on: macos-latest + steps: + - name: Checkout + uses: actions/checkout@master + + - name: Set Node.JS + uses: actions/setup-node@master + with: + node-version: 12.x + + - name: npm install + run: npm install + + - name: Build + run: npm run build diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..140d803 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +node_modules/ +lib \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..2e02d83 --- /dev/null +++ b/LICENSE @@ -0,0 +1,22 @@ + +The MIT License (MIT) + +Copyright (c) 2020 Maxim Lobanov and contributors + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. \ No newline at end of file diff --git a/README.md b/README.md index 601ddd9..0d8e2e6 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,33 @@ # configure-pagefile-action -Set PageFileSize on GitHub Windows Hosted Agents +This action is intended to configure Pagefile size and location for Windows images in GitHub Actions. + +# Available parameters +| Argument | Description | Default value | +|-------------------------|--------------------------|--------------------| +| `minimum-size` | Set minimum size of Pagefile (GB) | `8` | +| `maximum-size` | Set maximum size of Pagefile (GB) | `minimum-size` | +| `disk-root` | Set disk root where Pagefile will be located | `C:`, `D:` | + +# Usage +``` +name: CI +on: [push] +jobs: + build: + runs-on: windows-latest + steps: + - name: configure Pagefile + uses: al-cheb/configure-pagefile-action@v1.0 + with: + minimum-size: 8 + + - name: configure Pagefile + uses: al-cheb/configure-pagefile-action@v1.0 + with: + minimum-size: 8 + maximum-size: 16 + disk-root: "D:" +``` + +# License +The scripts and documentation in this project are released under the [MIT License](LICENSE) \ No newline at end of file diff --git a/action.yml b/action.yml new file mode 100644 index 0000000..b9e338b --- /dev/null +++ b/action.yml @@ -0,0 +1,21 @@ +name: 'Configure Pagefile' +author: 'Aleksandr Chebotov & Maxim Lobanov' +description: 'Configure Pagefile on Windows agents in GitHub Actions' +inputs: + minimum-size: + description: 'Set minimum size of Pagefile (GB)' + required: false + default: 8 + maximum-size: + description: 'Set maximum size of Pagefile (GB)' + required: false + disk-root: + description: 'Set disk root where pagefile.sys will be located' + required: false + default: D:\ +runs: + using: 'node12' + main: 'dist/index.js' +branding: + icon: 'cpu' + color: 'purple' \ No newline at end of file diff --git a/dist/index.js b/dist/index.js new file mode 100644 index 0000000..6dd54fc --- /dev/null +++ b/dist/index.js @@ -0,0 +1,453 @@ +module.exports = +/******/ (function(modules, runtime) { // webpackBootstrap +/******/ "use strict"; +/******/ // The module cache +/******/ var installedModules = {}; +/******/ +/******/ // The require function +/******/ function __webpack_require__(moduleId) { +/******/ +/******/ // Check if module is in cache +/******/ if(installedModules[moduleId]) { +/******/ return installedModules[moduleId].exports; +/******/ } +/******/ // Create a new module (and put it into the cache) +/******/ var module = installedModules[moduleId] = { +/******/ i: moduleId, +/******/ l: false, +/******/ exports: {} +/******/ }; +/******/ +/******/ // Execute the module function +/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); +/******/ +/******/ // Flag the module as loaded +/******/ module.l = true; +/******/ +/******/ // Return the exports of the module +/******/ return module.exports; +/******/ } +/******/ +/******/ +/******/ __webpack_require__.ab = __dirname + "/"; +/******/ +/******/ // the startup function +/******/ function startup() { +/******/ // Load entry module and return exports +/******/ return __webpack_require__(465); +/******/ }; +/******/ +/******/ // run startup +/******/ return startup(); +/******/ }) +/************************************************************************/ +/******/ ({ + +/***/ 87: +/***/ (function(module) { + +module.exports = require("os"); + +/***/ }), + +/***/ 129: +/***/ (function(module) { + +module.exports = require("child_process"); + +/***/ }), + +/***/ 431: +/***/ (function(__unusedmodule, exports, __webpack_require__) { + +"use strict"; + +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; + result["default"] = mod; + return result; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +const os = __importStar(__webpack_require__(87)); +/** + * Commands + * + * Command Format: + * ::name key=value,key=value::message + * + * Examples: + * ::warning::This is the message + * ::set-env name=MY_VAR::some value + */ +function issueCommand(command, properties, message) { + const cmd = new Command(command, properties, message); + process.stdout.write(cmd.toString() + os.EOL); +} +exports.issueCommand = issueCommand; +function issue(name, message = '') { + issueCommand(name, {}, message); +} +exports.issue = issue; +const CMD_STRING = '::'; +class Command { + constructor(command, properties, message) { + if (!command) { + command = 'missing.command'; + } + this.command = command; + this.properties = properties; + this.message = message; + } + toString() { + let cmdStr = CMD_STRING + this.command; + if (this.properties && Object.keys(this.properties).length > 0) { + cmdStr += ' '; + let first = true; + for (const key in this.properties) { + if (this.properties.hasOwnProperty(key)) { + const val = this.properties[key]; + if (val) { + if (first) { + first = false; + } + else { + cmdStr += ','; + } + cmdStr += `${key}=${escapeProperty(val)}`; + } + } + } + } + cmdStr += `${CMD_STRING}${escapeData(this.message)}`; + return cmdStr; + } +} +/** + * Sanitizes an input into a string so it can be passed into issueCommand safely + * @param input input to sanitize into a string + */ +function toCommandValue(input) { + if (input === null || input === undefined) { + return ''; + } + else if (typeof input === 'string' || input instanceof String) { + return input; + } + return JSON.stringify(input); +} +exports.toCommandValue = toCommandValue; +function escapeData(s) { + return toCommandValue(s) + .replace(/%/g, '%25') + .replace(/\r/g, '%0D') + .replace(/\n/g, '%0A'); +} +function escapeProperty(s) { + return toCommandValue(s) + .replace(/%/g, '%25') + .replace(/\r/g, '%0D') + .replace(/\n/g, '%0A') + .replace(/:/g, '%3A') + .replace(/,/g, '%2C'); +} +//# sourceMappingURL=command.js.map + +/***/ }), + +/***/ 465: +/***/ (function(__unusedmodule, exports, __webpack_require__) { + +"use strict"; + +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; + result["default"] = mod; + return result; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +const path = __importStar(__webpack_require__(622)); +const child = __importStar(__webpack_require__(129)); +const core = __importStar(__webpack_require__(470)); +const getSizeInput = (inputName, defaultValue) => { + const inputValue = core.getInput(inputName, { required: !defaultValue }); + if (defaultValue && !inputValue) { + return defaultValue; + } + let size = parseInt(inputValue); + if (isNaN(size)) { + throw new Error(`Unable to parse input '${inputName}'. Value '${inputValue}' is invalid.`); + } + // convert GB to Byte + return size * 1024 * 1024 * 1024; +}; +const run = () => { + try { + if (process.platform !== "win32") { + throw new Error(`This task is intended only for Windows platform. It can't be run on '${process.platform}' platform`); + } + const minimumSize = getSizeInput("minimum-size"); + const maximumSize = getSizeInput("maximum-size", minimumSize); + const diskRoot = core.getInput("disk-root", { required: true }); + core.info("Pagefile configuration:"); + core.info(`- Minimum size: ${minimumSize}`); + core.info(`- Maximum size: ${maximumSize}`); + core.info(`- Disk root: ${diskRoot}`); + const scriptPath = path.resolve(path.join("..", "scripts", "SetPageFileSize.ps1")); + const scriptArguments = [minimumSize, maximumSize, diskRoot].map(String); + core.debug("Invoke configuration script:"); + core.debug(`Script path: ${scriptPath}`); + core.debug(`Script arguments: ${scriptArguments}`); + child.execFileSync(scriptPath, scriptArguments, { + timeout: 60 * 1000 // 60 seconds + }); + } + catch (error) { + core.setFailed(error.message); + } +}; +run(); + + +/***/ }), + +/***/ 470: +/***/ (function(__unusedmodule, exports, __webpack_require__) { + +"use strict"; + +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; + result["default"] = mod; + return result; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +const command_1 = __webpack_require__(431); +const os = __importStar(__webpack_require__(87)); +const path = __importStar(__webpack_require__(622)); +/** + * The code to exit an action + */ +var ExitCode; +(function (ExitCode) { + /** + * A code indicating that the action was successful + */ + ExitCode[ExitCode["Success"] = 0] = "Success"; + /** + * A code indicating that the action was a failure + */ + ExitCode[ExitCode["Failure"] = 1] = "Failure"; +})(ExitCode = exports.ExitCode || (exports.ExitCode = {})); +//----------------------------------------------------------------------- +// Variables +//----------------------------------------------------------------------- +/** + * Sets env variable for this action and future actions in the job + * @param name the name of the variable to set + * @param val the value of the variable. Non-string values will be converted to a string via JSON.stringify + */ +// eslint-disable-next-line @typescript-eslint/no-explicit-any +function exportVariable(name, val) { + const convertedVal = command_1.toCommandValue(val); + process.env[name] = convertedVal; + command_1.issueCommand('set-env', { name }, convertedVal); +} +exports.exportVariable = exportVariable; +/** + * Registers a secret which will get masked from logs + * @param secret value of the secret + */ +function setSecret(secret) { + command_1.issueCommand('add-mask', {}, secret); +} +exports.setSecret = setSecret; +/** + * Prepends inputPath to the PATH (for this action and future actions) + * @param inputPath + */ +function addPath(inputPath) { + command_1.issueCommand('add-path', {}, inputPath); + process.env['PATH'] = `${inputPath}${path.delimiter}${process.env['PATH']}`; +} +exports.addPath = addPath; +/** + * Gets the value of an input. The value is also trimmed. + * + * @param name name of the input to get + * @param options optional. See InputOptions. + * @returns string + */ +function getInput(name, options) { + const val = process.env[`INPUT_${name.replace(/ /g, '_').toUpperCase()}`] || ''; + if (options && options.required && !val) { + throw new Error(`Input required and not supplied: ${name}`); + } + return val.trim(); +} +exports.getInput = getInput; +/** + * Sets the value of an output. + * + * @param name name of the output to set + * @param value value to store. Non-string values will be converted to a string via JSON.stringify + */ +// eslint-disable-next-line @typescript-eslint/no-explicit-any +function setOutput(name, value) { + command_1.issueCommand('set-output', { name }, value); +} +exports.setOutput = setOutput; +/** + * Enables or disables the echoing of commands into stdout for the rest of the step. + * Echoing is disabled by default if ACTIONS_STEP_DEBUG is not set. + * + */ +function setCommandEcho(enabled) { + command_1.issue('echo', enabled ? 'on' : 'off'); +} +exports.setCommandEcho = setCommandEcho; +//----------------------------------------------------------------------- +// Results +//----------------------------------------------------------------------- +/** + * Sets the action status to failed. + * When the action exits it will be with an exit code of 1 + * @param message add error issue message + */ +function setFailed(message) { + process.exitCode = ExitCode.Failure; + error(message); +} +exports.setFailed = setFailed; +//----------------------------------------------------------------------- +// Logging Commands +//----------------------------------------------------------------------- +/** + * Gets whether Actions Step Debug is on or not + */ +function isDebug() { + return process.env['RUNNER_DEBUG'] === '1'; +} +exports.isDebug = isDebug; +/** + * Writes debug message to user log + * @param message debug message + */ +function debug(message) { + command_1.issueCommand('debug', {}, message); +} +exports.debug = debug; +/** + * Adds an error issue + * @param message error issue message. Errors will be converted to string via toString() + */ +function error(message) { + command_1.issue('error', message instanceof Error ? message.toString() : message); +} +exports.error = error; +/** + * Adds an warning issue + * @param message warning issue message. Errors will be converted to string via toString() + */ +function warning(message) { + command_1.issue('warning', message instanceof Error ? message.toString() : message); +} +exports.warning = warning; +/** + * Writes info to log with console.log. + * @param message info message + */ +function info(message) { + process.stdout.write(message + os.EOL); +} +exports.info = info; +/** + * Begin an output group. + * + * Output until the next `groupEnd` will be foldable in this group + * + * @param name The name of the output group + */ +function startGroup(name) { + command_1.issue('group', name); +} +exports.startGroup = startGroup; +/** + * End an output group. + */ +function endGroup() { + command_1.issue('endgroup'); +} +exports.endGroup = endGroup; +/** + * Wrap an asynchronous function call in a group. + * + * Returns the same type as the function itself. + * + * @param name The name of the group + * @param fn The function to wrap in the group + */ +function group(name, fn) { + return __awaiter(this, void 0, void 0, function* () { + startGroup(name); + let result; + try { + result = yield fn(); + } + finally { + endGroup(); + } + return result; + }); +} +exports.group = group; +//----------------------------------------------------------------------- +// Wrapper action state +//----------------------------------------------------------------------- +/** + * Saves state for current action, the state can only be retrieved by this action's post job execution. + * + * @param name name of the state to store + * @param value value to store. Non-string values will be converted to a string via JSON.stringify + */ +// eslint-disable-next-line @typescript-eslint/no-explicit-any +function saveState(name, value) { + command_1.issueCommand('save-state', { name }, value); +} +exports.saveState = saveState; +/** + * Gets the value of an state set by this action's main execution. + * + * @param name name of the state to get + * @returns string + */ +function getState(name) { + return process.env[`STATE_${name}`] || ''; +} +exports.getState = getState; +//# sourceMappingURL=core.js.map + +/***/ }), + +/***/ 622: +/***/ (function(module) { + +module.exports = require("path"); + +/***/ }) + +/******/ }); \ No newline at end of file diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..dbf2c94 --- /dev/null +++ b/package-lock.json @@ -0,0 +1,31 @@ +{ + "name": "configure-pagefile-action", + "version": "1.0.0", + "lockfileVersion": 1, + "requires": true, + "dependencies": { + "@actions/core": { + "version": "1.2.4", + "resolved": "https://registry.npmjs.org/@actions/core/-/core-1.2.4.tgz", + "integrity": "sha512-YJCEq8BE3CdN8+7HPZ/4DxJjk/OkZV2FFIf+DlZTC/4iBlzYCD5yjRR6eiOS5llO11zbRltIRuKAjMKaWTE6cg==" + }, + "@types/node": { + "version": "12.12.37", + "resolved": "https://registry.npmjs.org/@types/node/-/node-12.12.37.tgz", + "integrity": "sha512-4mXKoDptrXAwZErQHrLzpe0FN/0Wmf5JRniSVIdwUrtDf9wnmEV1teCNLBo/TwuXhkK/bVegoEn/wmb+x0AuPg==", + "dev": true + }, + "@zeit/ncc": { + "version": "0.21.1", + "resolved": "https://registry.npmjs.org/@zeit/ncc/-/ncc-0.21.1.tgz", + "integrity": "sha512-M9WzgquSOt2nsjRkYM9LRylBLmmlwNCwYbm3Up3PDEshfvdmIfqpFNSK8EJvR18NwZjGHE5z2avlDtYQx2JQnw==", + "dev": true + }, + "typescript": { + "version": "3.8.3", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.8.3.tgz", + "integrity": "sha512-MYlEfn5VrLNsgudQTVJeNaQFUAI7DkhnOjdpAp4T+ku1TfQClewlbSuTVHiA+8skNBgaf02TL/kLOvig4y3G8w==", + "dev": true + } + } +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..ad44415 --- /dev/null +++ b/package.json @@ -0,0 +1,30 @@ +{ + "name": "configure-pagefile-action", + "version": "1.0.0", + "private": true, + "description": "Configure Pagefile on Windows agents in GitHub Actions", + "main": "lib/configure-pagefile.js", + "scripts": { + "build": "tsc && ncc build" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/al-cheb/configure-pagefile-action.git" + }, + "keywords": [ + "actions", + "pagefile", + "configure", + "windows" + ], + "author": "Aleksandr Chebotov & Maxim Lobanov", + "license": "MIT", + "dependencies": { + "@actions/core": "^1.2.3" + }, + "devDependencies": { + "@types/node": "^12.0.4", + "@zeit/ncc": "^0.21.1", + "typescript": "^3.8.3" + } +} diff --git a/scripts/SetPageFileSize.ps1 b/scripts/SetPageFileSize.ps1 new file mode 100644 index 0000000..8407efd --- /dev/null +++ b/scripts/SetPageFileSize.ps1 @@ -0,0 +1,193 @@ +<# +.SYNOPSIS + Configure Pagefile on Windows machine +.NOTES + Author: Aleksandr Chebotov +.EXAMPLE + SetPageFileSize.ps1 -MinimumSize 4GB -MaximumSize 8GB -DiskRoot "D:" +#> + +param( + [System.UInt64] $MinimumSize = 8gb , + [System.UInt64] $MaximumSize = 8gb , + [System.String] $DiskRoot = "D:" +) + +# https://referencesource.microsoft.com/#System.IdentityModel/System/IdentityModel/NativeMethods.cs,619688d876febbe1 +# https://www.geoffchappell.com/studies/windows/km/ntoskrnl/api/mm/modwrite/create.htm +# https://referencesource.microsoft.com/#mscorlib/microsoft/win32/safehandles/safefilehandle.cs,9b08210f3be75520 +# https://referencesource.microsoft.com/#mscorlib/system/security/principal/tokenaccesslevels.cs,6eda91f498a38586 +# https://www.autoitscript.com/forum/topic/117993-api-ntcreatepagingfile/ + +$source = @' +using System; +using System.ComponentModel; +using System.Diagnostics; +using System.Runtime.InteropServices; +using System.Security.Principal; +using System.Text; +using Microsoft.Win32; +using Microsoft.Win32.SafeHandles; + +namespace Util +{ + class NativeMethods + { + [StructLayout(LayoutKind.Sequential)] + internal struct LUID + { + internal uint LowPart; + internal uint HighPart; + } + + [StructLayout(LayoutKind.Sequential)] + internal struct LUID_AND_ATTRIBUTES + { + internal LUID Luid; + internal uint Attributes; + } + + [StructLayout(LayoutKind.Sequential)] + internal struct TOKEN_PRIVILEGE + { + internal uint PrivilegeCount; + internal LUID_AND_ATTRIBUTES Privilege; + + internal static readonly uint Size = (uint)Marshal.SizeOf(typeof(TOKEN_PRIVILEGE)); + } + + [StructLayoutAttribute(LayoutKind.Sequential, CharSet = CharSet.Unicode)] + internal struct UNICODE_STRING + { + internal UInt16 length; + internal UInt16 maximumLength; + internal string buffer; + } + + [DllImport("kernel32.dll", SetLastError=true)] + internal static extern IntPtr LocalFree(IntPtr handle); + + [DllImport("advapi32.dll", ExactSpelling = true, CharSet = CharSet.Unicode, SetLastError = true, PreserveSig = false)] + internal static extern bool LookupPrivilegeValueW( + [In] string lpSystemName, + [In] string lpName, + [Out] out LUID luid + ); + + [DllImport("advapi32.dll", SetLastError = true, PreserveSig = false)] + internal static extern bool AdjustTokenPrivileges( + [In] SafeCloseHandle tokenHandle, + [In] bool disableAllPrivileges, + [In] ref TOKEN_PRIVILEGE newState, + [In] uint bufferLength, + [Out] out TOKEN_PRIVILEGE previousState, + [Out] out uint returnLength + ); + + [DllImport("advapi32.dll", CharSet = CharSet.Auto, SetLastError = true, PreserveSig = false)] + internal static extern bool OpenProcessToken( + [In] IntPtr processToken, + [In] int desiredAccess, + [Out] out SafeCloseHandle tokenHandle + ); + + [DllImport("ntdll.dll", CharSet = CharSet.Unicode, SetLastError = true, CallingConvention = CallingConvention.StdCall)] + internal static extern Int32 NtCreatePagingFile( + [In] ref UNICODE_STRING pageFileName, + [In] ref Int64 minimumSize, + [In] ref Int64 maximumSize, + [In] UInt32 flags + ); + + [DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)] + internal static extern uint QueryDosDeviceW( + string lpDeviceName, + StringBuilder lpTargetPath, + int ucchMax + ); + } + + public sealed class SafeCloseHandle: SafeHandleZeroOrMinusOneIsInvalid + { + [DllImport("kernel32.dll", ExactSpelling = true, SetLastError = true)] + internal extern static bool CloseHandle(IntPtr handle); + + private SafeCloseHandle() : base(true) + { + } + + public SafeCloseHandle(IntPtr preexistingHandle, bool ownsHandle) : base(ownsHandle) + { + SetHandle(preexistingHandle); + } + + override protected bool ReleaseHandle() + { + return CloseHandle(handle); + } + } + + public class PageFile + { + public static void SetPageFileSize(long minimumValue, long maximumValue, string lpDeviceName) + { + SetPageFilePrivilege(); + StringBuilder lpTargetPath = new StringBuilder(260); + + UInt32 resultQueryDosDevice = NativeMethods.QueryDosDeviceW(lpDeviceName, lpTargetPath, lpTargetPath.Capacity); + if (resultQueryDosDevice == 0) + { + throw new Win32Exception(Marshal.GetLastWin32Error()); + } + + string pageFilePath = lpTargetPath.ToString() + "\\pagefile.sys"; + + NativeMethods.UNICODE_STRING pageFileName = new NativeMethods.UNICODE_STRING + { + length = (ushort)(pageFilePath.Length * 2), + maximumLength = (ushort)(2 * (pageFilePath.Length + 1)), + buffer = pageFilePath + }; + + Int32 resultNtCreatePagingFile = NativeMethods.NtCreatePagingFile(ref pageFileName, ref minimumValue, ref maximumValue, 0); + if (resultNtCreatePagingFile != 0) + { + throw new Win32Exception(Marshal.GetLastWin32Error()); + } + + Console.WriteLine("PageFile: {0} / {1} bytes for {2}", minimumValue, maximumValue, pageFilePath); + } + + static void SetPageFilePrivilege() + { + const int SE_PRIVILEGE_ENABLED = 0x00000002; + const int AdjustPrivileges = 0x00000020; + const int Query = 0x00000008; + + NativeMethods.LUID luid; + NativeMethods.LookupPrivilegeValueW(null, "SeCreatePagefilePrivilege", out luid); + + SafeCloseHandle hToken; + NativeMethods.OpenProcessToken( + Process.GetCurrentProcess().Handle, + AdjustPrivileges | Query, + out hToken + ); + + NativeMethods.TOKEN_PRIVILEGE previousState; + NativeMethods.TOKEN_PRIVILEGE newState; + uint previousSize = 0; + newState.PrivilegeCount = 1; + newState.Privilege.Luid = luid; + newState.Privilege.Attributes = SE_PRIVILEGE_ENABLED; + + NativeMethods.AdjustTokenPrivileges(hToken, false, ref newState, NativeMethods.TOKEN_PRIVILEGE.Size, out previousState, out previousSize); + } + } +} +'@ + +Add-Type -TypeDefinition $source + +# Set SetPageFileSize +[Util.PageFile]::SetPageFileSize($minimumSize, $maximumSize, $diskRoot) \ No newline at end of file diff --git a/src/configure-pagefile.ts b/src/configure-pagefile.ts new file mode 100644 index 0000000..ab3f074 --- /dev/null +++ b/src/configure-pagefile.ts @@ -0,0 +1,48 @@ +import * as path from "path"; +import * as child from "child_process"; +import * as core from "@actions/core"; + +const getSizeInput = (inputName: string, defaultValue?: number): number => { + const inputValue = core.getInput(inputName, { required: !defaultValue }); + if (defaultValue && !inputValue) { + return defaultValue; + } + + let size = parseInt(inputValue); + if (isNaN(size)) { + throw new Error(`Unable to parse input '${inputName}'. Value '${inputValue}' is invalid.`) + } + + // convert GB to Byte + return size * 1024 * 1024 * 1024; +} + +const run = (): void => { + try { + if (process.platform !== "win32") { + throw new Error(`This task is intended only for Windows platform. It can't be run on '${process.platform}' platform`); + } + + const minimumSize = getSizeInput("minimum-size"); + const maximumSize = getSizeInput("maximum-size", minimumSize); + const diskRoot = core.getInput("disk-root", { required: true }); + + core.info("Pagefile configuration:"); + core.info(`- Minimum size: ${minimumSize}`); + core.info(`- Maximum size: ${maximumSize}`); + core.info(`- Disk root: ${diskRoot}`); + + const scriptPath = path.resolve(path.join("..", "scripts", "SetPageFileSize.ps1")); + const scriptArguments = [minimumSize, maximumSize, diskRoot].map(String); + core.debug("Invoke configuration script:"); + core.debug(`Script path: ${scriptPath}`); + core.debug(`Script arguments: ${scriptArguments}`) + child.execFileSync(scriptPath, scriptArguments, { + timeout: 60 * 1000 // 60 seconds + }); + } catch (error) { + core.setFailed(error.message); + } +}; + +run(); diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..f37f328 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,22 @@ +{ + "compilerOptions": { + "target": "ES2019", + "module": "commonjs", + "outDir": "./lib", + "rootDir": "./src", + "esModuleInterop": true, + + /* Strict Type-Checking Options */ + "strict": true, + "noImplicitAny": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + + /* Additional Checks */ + "noUnusedLocals": true, + "noUnusedParameters": true, + "noImplicitReturns": true + }, + "include": ["./src/**/*.ts"], + "exclude": ["node_modules"] + } \ No newline at end of file From 6fdae8af266112c13502c5add56e451ac5a43a72 Mon Sep 17 00:00:00 2001 From: Maxim Lobanov Date: Fri, 1 May 2020 19:34:46 +0300 Subject: [PATCH 02/22] fix test yaml --- .github/workflows/test.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 9f6d432..2747e61 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -21,7 +21,7 @@ jobs: - name: validation shell: pwsh - runs: | + run: | (Get-CimInstance Win32_PageFileUsage).AllocatedBaseSize Invoke-Expression "wmic pagefile list /format:list" @@ -44,6 +44,6 @@ jobs: - name: validation shell: pwsh - runs: | + run: | (Get-CimInstance Win32_PageFileUsage).AllocatedBaseSize Invoke-Expression "wmic pagefile list /format:list" From a40ba3f670f2f1223a67c9f97bff325c9244ca3e Mon Sep 17 00:00:00 2001 From: Maxim Lobanov Date: Fri, 1 May 2020 19:36:01 +0300 Subject: [PATCH 03/22] fix test yaml typos --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 2747e61..10c7ab5 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -5,7 +5,7 @@ on: - cron: 0 0 * * * jobs: - default parameters: + default-parameters: strategy: matrix: os: [ windows-2016, windows-2019 ] From 134f81ae7d96f7f04cd1bc331aa8e58cb3f59ed8 Mon Sep 17 00:00:00 2001 From: Maxim Lobanov Date: Fri, 1 May 2020 19:50:12 +0300 Subject: [PATCH 04/22] fix script invocation --- .github/workflows/test.yml | 1 + dist/index.js | 8 ++++++-- src/configure-pagefile.ts | 8 ++++++-- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 10c7ab5..8e482f5 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -30,6 +30,7 @@ jobs: matrix: os: [ windows-2016, windows-2019 ] disk-root: [ "C:", "D:" ] + fail-fast: false runs-on: ${{ matrix.os }} steps: - name: Checkout diff --git a/dist/index.js b/dist/index.js index 6dd54fc..dcbaa80 100644 --- a/dist/index.js +++ b/dist/index.js @@ -197,11 +197,15 @@ const run = () => { core.info(`- Maximum size: ${maximumSize}`); core.info(`- Disk root: ${diskRoot}`); const scriptPath = path.resolve(path.join("..", "scripts", "SetPageFileSize.ps1")); - const scriptArguments = [minimumSize, maximumSize, diskRoot].map(String); + const scriptArguments = [ + "-MinimumSize", `"${minimumSize}"`, + "-MaximumSize", `"${maximumSize}"`, + "-DiskRoot", `"${diskRoot}"` + ].map(String); core.debug("Invoke configuration script:"); core.debug(`Script path: ${scriptPath}`); core.debug(`Script arguments: ${scriptArguments}`); - child.execFileSync(scriptPath, scriptArguments, { + child.spawnSync("pwsh", ["-File", scriptPath, ...scriptArguments], { timeout: 60 * 1000 // 60 seconds }); } diff --git a/src/configure-pagefile.ts b/src/configure-pagefile.ts index ab3f074..bf601a0 100644 --- a/src/configure-pagefile.ts +++ b/src/configure-pagefile.ts @@ -33,11 +33,15 @@ const run = (): void => { core.info(`- Disk root: ${diskRoot}`); const scriptPath = path.resolve(path.join("..", "scripts", "SetPageFileSize.ps1")); - const scriptArguments = [minimumSize, maximumSize, diskRoot].map(String); + const scriptArguments = [ + "-MinimumSize", `"${minimumSize}"`, + "-MaximumSize", `"${maximumSize}"`, + "-DiskRoot", `"${diskRoot}"` + ].map(String); core.debug("Invoke configuration script:"); core.debug(`Script path: ${scriptPath}`); core.debug(`Script arguments: ${scriptArguments}`) - child.execFileSync(scriptPath, scriptArguments, { + child.spawnSync("pwsh", ["-File", scriptPath, ...scriptArguments], { timeout: 60 * 1000 // 60 seconds }); } catch (error) { From 834e21cfb969367e3e0e5bdb4b17c6bb2c7bccbb Mon Sep 17 00:00:00 2001 From: Maxim Lobanov Date: Fri, 1 May 2020 20:03:42 +0300 Subject: [PATCH 05/22] fix script invocation --- dist/index.js | 3 ++- src/configure-pagefile.ts | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/dist/index.js b/dist/index.js index dcbaa80..54ee54f 100644 --- a/dist/index.js +++ b/dist/index.js @@ -206,7 +206,8 @@ const run = () => { core.debug(`Script path: ${scriptPath}`); core.debug(`Script arguments: ${scriptArguments}`); child.spawnSync("pwsh", ["-File", scriptPath, ...scriptArguments], { - timeout: 60 * 1000 // 60 seconds + timeout: 60 * 1000, + stdio: "inherit" }); } catch (error) { diff --git a/src/configure-pagefile.ts b/src/configure-pagefile.ts index bf601a0..bfb5a19 100644 --- a/src/configure-pagefile.ts +++ b/src/configure-pagefile.ts @@ -42,7 +42,8 @@ const run = (): void => { core.debug(`Script path: ${scriptPath}`); core.debug(`Script arguments: ${scriptArguments}`) child.spawnSync("pwsh", ["-File", scriptPath, ...scriptArguments], { - timeout: 60 * 1000 // 60 seconds + timeout: 60 * 1000, + stdio: "inherit" }); } catch (error) { core.setFailed(error.message); From 181b893dedbc584e212c20c948a2ab0b91e6e6c8 Mon Sep 17 00:00:00 2001 From: Maxim Lobanov Date: Fri, 1 May 2020 20:06:48 +0300 Subject: [PATCH 06/22] Fix script path --- dist/index.js | 2 +- src/configure-pagefile.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/dist/index.js b/dist/index.js index 54ee54f..dcbb3f4 100644 --- a/dist/index.js +++ b/dist/index.js @@ -196,7 +196,7 @@ const run = () => { core.info(`- Minimum size: ${minimumSize}`); core.info(`- Maximum size: ${maximumSize}`); core.info(`- Disk root: ${diskRoot}`); - const scriptPath = path.resolve(path.join("..", "scripts", "SetPageFileSize.ps1")); + const scriptPath = path.resolve(path.join("scripts", "SetPageFileSize.ps1")); const scriptArguments = [ "-MinimumSize", `"${minimumSize}"`, "-MaximumSize", `"${maximumSize}"`, diff --git a/src/configure-pagefile.ts b/src/configure-pagefile.ts index bfb5a19..91c79ce 100644 --- a/src/configure-pagefile.ts +++ b/src/configure-pagefile.ts @@ -32,7 +32,7 @@ const run = (): void => { core.info(`- Maximum size: ${maximumSize}`); core.info(`- Disk root: ${diskRoot}`); - const scriptPath = path.resolve(path.join("..", "scripts", "SetPageFileSize.ps1")); + const scriptPath = path.resolve(path.join("scripts", "SetPageFileSize.ps1")); const scriptArguments = [ "-MinimumSize", `"${minimumSize}"`, "-MaximumSize", `"${maximumSize}"`, From 7572b89b6420b3508c667b46b808b6eb905067fd Mon Sep 17 00:00:00 2001 From: Maxim Lobanov Date: Fri, 1 May 2020 20:08:53 +0300 Subject: [PATCH 07/22] fix parameters --- dist/index.js | 4 ++-- src/configure-pagefile.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/dist/index.js b/dist/index.js index dcbb3f4..310cb3f 100644 --- a/dist/index.js +++ b/dist/index.js @@ -198,8 +198,8 @@ const run = () => { core.info(`- Disk root: ${diskRoot}`); const scriptPath = path.resolve(path.join("scripts", "SetPageFileSize.ps1")); const scriptArguments = [ - "-MinimumSize", `"${minimumSize}"`, - "-MaximumSize", `"${maximumSize}"`, + "-MinimumSize", minimumSize, + "-MaximumSize", maximumSize, "-DiskRoot", `"${diskRoot}"` ].map(String); core.debug("Invoke configuration script:"); diff --git a/src/configure-pagefile.ts b/src/configure-pagefile.ts index 91c79ce..4a7f378 100644 --- a/src/configure-pagefile.ts +++ b/src/configure-pagefile.ts @@ -34,8 +34,8 @@ const run = (): void => { const scriptPath = path.resolve(path.join("scripts", "SetPageFileSize.ps1")); const scriptArguments = [ - "-MinimumSize", `"${minimumSize}"`, - "-MaximumSize", `"${maximumSize}"`, + "-MinimumSize", minimumSize, + "-MaximumSize", maximumSize, "-DiskRoot", `"${diskRoot}"` ].map(String); core.debug("Invoke configuration script:"); From 9615cea9aa4a87e65887fdce0a0de2f25c4abb80 Mon Sep 17 00:00:00 2001 From: Maxim Lobanov Date: Fri, 1 May 2020 20:21:39 +0300 Subject: [PATCH 08/22] change action input --- .github/workflows/test.yml | 6 +++--- action.yml | 2 +- dist/index.js | 25 ++++++++----------------- src/configure-pagefile.ts | 31 ++++++++++--------------------- 4 files changed, 22 insertions(+), 42 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 8e482f5..f83dad4 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -17,7 +17,7 @@ jobs: - name: configure-pagefile-action uses: ./ with: - minimum-size: 8 + minimum-size: 8GB - name: validation shell: pwsh @@ -39,8 +39,8 @@ jobs: - name: configure-pagefile-action uses: ./ with: - minimum-size: 4 - maximum-size: 8 + minimum-size: 4GB + maximum-size: 8GB disk-root: ${{ matrix.disk-root }} - name: validation diff --git a/action.yml b/action.yml index b9e338b..d3c107e 100644 --- a/action.yml +++ b/action.yml @@ -5,7 +5,7 @@ inputs: minimum-size: description: 'Set minimum size of Pagefile (GB)' required: false - default: 8 + default: 8GB maximum-size: description: 'Set maximum size of Pagefile (GB)' required: false diff --git a/dist/index.js b/dist/index.js index 310cb3f..3f0fddd 100644 --- a/dist/index.js +++ b/dist/index.js @@ -172,25 +172,13 @@ Object.defineProperty(exports, "__esModule", { value: true }); const path = __importStar(__webpack_require__(622)); const child = __importStar(__webpack_require__(129)); const core = __importStar(__webpack_require__(470)); -const getSizeInput = (inputName, defaultValue) => { - const inputValue = core.getInput(inputName, { required: !defaultValue }); - if (defaultValue && !inputValue) { - return defaultValue; - } - let size = parseInt(inputValue); - if (isNaN(size)) { - throw new Error(`Unable to parse input '${inputName}'. Value '${inputValue}' is invalid.`); - } - // convert GB to Byte - return size * 1024 * 1024 * 1024; -}; const run = () => { try { if (process.platform !== "win32") { throw new Error(`This task is intended only for Windows platform. It can't be run on '${process.platform}' platform`); } - const minimumSize = getSizeInput("minimum-size"); - const maximumSize = getSizeInput("maximum-size", minimumSize); + const minimumSize = core.getInput("minimum-size", { required: true }); + const maximumSize = core.getInput("maximum-size", { required: false }) || minimumSize; const diskRoot = core.getInput("disk-root", { required: true }); core.info("Pagefile configuration:"); core.info(`- Minimum size: ${minimumSize}`); @@ -201,14 +189,17 @@ const run = () => { "-MinimumSize", minimumSize, "-MaximumSize", maximumSize, "-DiskRoot", `"${diskRoot}"` - ].map(String); + ]; core.debug("Invoke configuration script:"); core.debug(`Script path: ${scriptPath}`); core.debug(`Script arguments: ${scriptArguments}`); - child.spawnSync("pwsh", ["-File", scriptPath, ...scriptArguments], { + const scriptExitCode = child.spawnSync("pwsh", ["-File", scriptPath, ...scriptArguments], { timeout: 60 * 1000, stdio: "inherit" - }); + }).status; + if (scriptExitCode !== 0) { + throw new Error(`Script has finished with exit code '${scriptExitCode}'`); + } } catch (error) { core.setFailed(error.message); diff --git a/src/configure-pagefile.ts b/src/configure-pagefile.ts index 4a7f378..727f5c0 100644 --- a/src/configure-pagefile.ts +++ b/src/configure-pagefile.ts @@ -2,29 +2,14 @@ import * as path from "path"; import * as child from "child_process"; import * as core from "@actions/core"; -const getSizeInput = (inputName: string, defaultValue?: number): number => { - const inputValue = core.getInput(inputName, { required: !defaultValue }); - if (defaultValue && !inputValue) { - return defaultValue; - } - - let size = parseInt(inputValue); - if (isNaN(size)) { - throw new Error(`Unable to parse input '${inputName}'. Value '${inputValue}' is invalid.`) - } - - // convert GB to Byte - return size * 1024 * 1024 * 1024; -} - const run = (): void => { try { if (process.platform !== "win32") { throw new Error(`This task is intended only for Windows platform. It can't be run on '${process.platform}' platform`); } - const minimumSize = getSizeInput("minimum-size"); - const maximumSize = getSizeInput("maximum-size", minimumSize); + const minimumSize = core.getInput("minimum-size", { required: true }); + const maximumSize = core.getInput("maximum-size", { required: false }) || minimumSize; const diskRoot = core.getInput("disk-root", { required: true }); core.info("Pagefile configuration:"); @@ -37,14 +22,18 @@ const run = (): void => { "-MinimumSize", minimumSize, "-MaximumSize", maximumSize, "-DiskRoot", `"${diskRoot}"` - ].map(String); + ]; core.debug("Invoke configuration script:"); core.debug(`Script path: ${scriptPath}`); - core.debug(`Script arguments: ${scriptArguments}`) - child.spawnSync("pwsh", ["-File", scriptPath, ...scriptArguments], { + core.debug(`Script arguments: ${scriptArguments}`); + + const scriptExitCode = child.spawnSync("pwsh", ["-File", scriptPath, ...scriptArguments], { timeout: 60 * 1000, stdio: "inherit" - }); + }).status; + if (scriptExitCode !== 0) { + throw new Error(`Script has finished with exit code '${scriptExitCode}'`) + } } catch (error) { core.setFailed(error.message); } From e72f87dd660379ea34c0415a683f6fd136dae846 Mon Sep 17 00:00:00 2001 From: Maxim Lobanov Date: Fri, 1 May 2020 20:27:39 +0300 Subject: [PATCH 09/22] fix script outpiut --- dist/index.js | 17 +++++++++++------ src/configure-pagefile.ts | 13 ++++++------- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/dist/index.js b/dist/index.js index 3f0fddd..e25c3b2 100644 --- a/dist/index.js +++ b/dist/index.js @@ -193,12 +193,17 @@ const run = () => { core.debug("Invoke configuration script:"); core.debug(`Script path: ${scriptPath}`); core.debug(`Script arguments: ${scriptArguments}`); - const scriptExitCode = child.spawnSync("pwsh", ["-File", scriptPath, ...scriptArguments], { - timeout: 60 * 1000, - stdio: "inherit" - }).status; - if (scriptExitCode !== 0) { - throw new Error(`Script has finished with exit code '${scriptExitCode}'`); + const scriptResult = child.spawnSync("pwsh", ["-File", scriptPath, ...scriptArguments], { + timeout: 60 * 1000 + }); + if (scriptResult.stdout) { + core.info(scriptResult.stdout.toString()); + } + if (scriptResult.stderr) { + core.error(scriptResult.stderr.toString()); + } + if (scriptResult.status !== 0) { + throw new Error(`Script has finished with exit code '${scriptResult.status}'`); } } catch (error) { diff --git a/src/configure-pagefile.ts b/src/configure-pagefile.ts index 727f5c0..3664667 100644 --- a/src/configure-pagefile.ts +++ b/src/configure-pagefile.ts @@ -27,13 +27,12 @@ const run = (): void => { core.debug(`Script path: ${scriptPath}`); core.debug(`Script arguments: ${scriptArguments}`); - const scriptExitCode = child.spawnSync("pwsh", ["-File", scriptPath, ...scriptArguments], { - timeout: 60 * 1000, - stdio: "inherit" - }).status; - if (scriptExitCode !== 0) { - throw new Error(`Script has finished with exit code '${scriptExitCode}'`) - } + const scriptResult = child.spawnSync("pwsh", ["-File", scriptPath, ...scriptArguments], { + timeout: 60 * 1000 + }); + if (scriptResult.stdout) { core.info(scriptResult.stdout.toString()); } + if (scriptResult.stderr) { core.error(scriptResult.stderr.toString()) } + if (scriptResult.status !== 0) { throw new Error(`Script has finished with exit code '${scriptResult.status}'`) } } catch (error) { core.setFailed(error.message); } From 55fadc7f34ecf0a7c8855f13535d51d184cced06 Mon Sep 17 00:00:00 2001 From: Maxim Lobanov Date: Fri, 1 May 2020 21:08:00 +0300 Subject: [PATCH 10/22] debug --- dist/index.js | 1 + scripts/SetPageFileSize.ps1 | 2 ++ src/configure-pagefile.ts | 1 + 3 files changed, 4 insertions(+) diff --git a/dist/index.js b/dist/index.js index e25c3b2..1ceb716 100644 --- a/dist/index.js +++ b/dist/index.js @@ -196,6 +196,7 @@ const run = () => { const scriptResult = child.spawnSync("pwsh", ["-File", scriptPath, ...scriptArguments], { timeout: 60 * 1000 }); + core.info(JSON.stringify(scriptResult, null, 2)); if (scriptResult.stdout) { core.info(scriptResult.stdout.toString()); } diff --git a/scripts/SetPageFileSize.ps1 b/scripts/SetPageFileSize.ps1 index 8407efd..20c7c86 100644 --- a/scripts/SetPageFileSize.ps1 +++ b/scripts/SetPageFileSize.ps1 @@ -13,6 +13,8 @@ param( [System.String] $DiskRoot = "D:" ) +Write-Host "test" + # https://referencesource.microsoft.com/#System.IdentityModel/System/IdentityModel/NativeMethods.cs,619688d876febbe1 # https://www.geoffchappell.com/studies/windows/km/ntoskrnl/api/mm/modwrite/create.htm # https://referencesource.microsoft.com/#mscorlib/microsoft/win32/safehandles/safefilehandle.cs,9b08210f3be75520 diff --git a/src/configure-pagefile.ts b/src/configure-pagefile.ts index 3664667..96fceab 100644 --- a/src/configure-pagefile.ts +++ b/src/configure-pagefile.ts @@ -30,6 +30,7 @@ const run = (): void => { const scriptResult = child.spawnSync("pwsh", ["-File", scriptPath, ...scriptArguments], { timeout: 60 * 1000 }); + core.info(JSON.stringify(scriptResult, null, 2)); if (scriptResult.stdout) { core.info(scriptResult.stdout.toString()); } if (scriptResult.stderr) { core.error(scriptResult.stderr.toString()) } if (scriptResult.status !== 0) { throw new Error(`Script has finished with exit code '${scriptResult.status}'`) } From f53f971c4b025df2636affece26db4edd60f35f8 Mon Sep 17 00:00:00 2001 From: Maxim Lobanov Date: Fri, 1 May 2020 21:11:40 +0300 Subject: [PATCH 11/22] debug --- dist/index.js | 8 ++++++-- src/configure-pagefile.ts | 12 ++++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/dist/index.js b/dist/index.js index 1ceb716..036082e 100644 --- a/dist/index.js +++ b/dist/index.js @@ -198,10 +198,14 @@ const run = () => { }); core.info(JSON.stringify(scriptResult, null, 2)); if (scriptResult.stdout) { - core.info(scriptResult.stdout.toString()); + core.info("stdout"); + const v = String(scriptResult.stdout); + core.info(v); } if (scriptResult.stderr) { - core.error(scriptResult.stderr.toString()); + core.info("stderr"); + const v = String(scriptResult.stderr); + core.error(v); } if (scriptResult.status !== 0) { throw new Error(`Script has finished with exit code '${scriptResult.status}'`); diff --git a/src/configure-pagefile.ts b/src/configure-pagefile.ts index 96fceab..bdce145 100644 --- a/src/configure-pagefile.ts +++ b/src/configure-pagefile.ts @@ -31,8 +31,16 @@ const run = (): void => { timeout: 60 * 1000 }); core.info(JSON.stringify(scriptResult, null, 2)); - if (scriptResult.stdout) { core.info(scriptResult.stdout.toString()); } - if (scriptResult.stderr) { core.error(scriptResult.stderr.toString()) } + if (scriptResult.stdout) { + core.info("stdout"); + const v = String(scriptResult.stdout); + core.info(v); + } + if (scriptResult.stderr) { + core.info("stderr"); + const v = String(scriptResult.stderr); + core.error(v); + } if (scriptResult.status !== 0) { throw new Error(`Script has finished with exit code '${scriptResult.status}'`) } } catch (error) { core.setFailed(error.message); From 5b3b8cdba849ac8217c6b8af4bf29ec805e8f2bd Mon Sep 17 00:00:00 2001 From: Maxim Lobanov Date: Fri, 1 May 2020 21:22:59 +0300 Subject: [PATCH 12/22] debug output --- dist/index.js | 2 +- scripts/SetPageFileSize.ps1 | 2 ++ src/configure-pagefile.ts | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/dist/index.js b/dist/index.js index 036082e..8c16998 100644 --- a/dist/index.js +++ b/dist/index.js @@ -193,7 +193,7 @@ const run = () => { core.debug("Invoke configuration script:"); core.debug(`Script path: ${scriptPath}`); core.debug(`Script arguments: ${scriptArguments}`); - const scriptResult = child.spawnSync("pwsh", ["-File", scriptPath, ...scriptArguments], { + const scriptResult = child.spawnSync("powershell", ["-File", scriptPath, ...scriptArguments], { timeout: 60 * 1000 }); core.info(JSON.stringify(scriptResult, null, 2)); diff --git a/scripts/SetPageFileSize.ps1 b/scripts/SetPageFileSize.ps1 index 20c7c86..6f18e69 100644 --- a/scripts/SetPageFileSize.ps1 +++ b/scripts/SetPageFileSize.ps1 @@ -191,5 +191,7 @@ namespace Util Add-Type -TypeDefinition $source +Write-Host "test2" + # Set SetPageFileSize [Util.PageFile]::SetPageFileSize($minimumSize, $maximumSize, $diskRoot) \ No newline at end of file diff --git a/src/configure-pagefile.ts b/src/configure-pagefile.ts index bdce145..151ec72 100644 --- a/src/configure-pagefile.ts +++ b/src/configure-pagefile.ts @@ -27,7 +27,7 @@ const run = (): void => { core.debug(`Script path: ${scriptPath}`); core.debug(`Script arguments: ${scriptArguments}`); - const scriptResult = child.spawnSync("pwsh", ["-File", scriptPath, ...scriptArguments], { + const scriptResult = child.spawnSync("powershell", ["-File", scriptPath, ...scriptArguments], { timeout: 60 * 1000 }); core.info(JSON.stringify(scriptResult, null, 2)); From 722cd6e0925690b543b2d3399a12e740bbbc07a8 Mon Sep 17 00:00:00 2001 From: Maxim Lobanov Date: Fri, 1 May 2020 21:29:51 +0300 Subject: [PATCH 13/22] debug arguments --- dist/index.js | 2 +- src/configure-pagefile.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/dist/index.js b/dist/index.js index 8c16998..bb508be 100644 --- a/dist/index.js +++ b/dist/index.js @@ -193,7 +193,7 @@ const run = () => { core.debug("Invoke configuration script:"); core.debug(`Script path: ${scriptPath}`); core.debug(`Script arguments: ${scriptArguments}`); - const scriptResult = child.spawnSync("powershell", ["-File", scriptPath, ...scriptArguments], { + const scriptResult = child.spawnSync("pwsh", ["-File", scriptPath], { timeout: 60 * 1000 }); core.info(JSON.stringify(scriptResult, null, 2)); diff --git a/src/configure-pagefile.ts b/src/configure-pagefile.ts index 151ec72..fe442b8 100644 --- a/src/configure-pagefile.ts +++ b/src/configure-pagefile.ts @@ -27,7 +27,7 @@ const run = (): void => { core.debug(`Script path: ${scriptPath}`); core.debug(`Script arguments: ${scriptArguments}`); - const scriptResult = child.spawnSync("powershell", ["-File", scriptPath, ...scriptArguments], { + const scriptResult = child.spawnSync("pwsh", ["-File", scriptPath], { timeout: 60 * 1000 }); core.info(JSON.stringify(scriptResult, null, 2)); From 579127a0bff36fddbb3576027453287011b2a3d8 Mon Sep 17 00:00:00 2001 From: Maxim Lobanov Date: Fri, 1 May 2020 21:35:14 +0300 Subject: [PATCH 14/22] debug action --- dist/index.js | 7 ++----- scripts/SetPageFileSize.ps1 | 3 +++ src/configure-pagefile.ts | 7 ++----- 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/dist/index.js b/dist/index.js index bb508be..3dc058e 100644 --- a/dist/index.js +++ b/dist/index.js @@ -196,16 +196,13 @@ const run = () => { const scriptResult = child.spawnSync("pwsh", ["-File", scriptPath], { timeout: 60 * 1000 }); - core.info(JSON.stringify(scriptResult, null, 2)); if (scriptResult.stdout) { core.info("stdout"); - const v = String(scriptResult.stdout); - core.info(v); + core.info(scriptResult.stdout.toString()); } if (scriptResult.stderr) { core.info("stderr"); - const v = String(scriptResult.stderr); - core.error(v); + core.error(scriptResult.stderr.toString()); } if (scriptResult.status !== 0) { throw new Error(`Script has finished with exit code '${scriptResult.status}'`); diff --git a/scripts/SetPageFileSize.ps1 b/scripts/SetPageFileSize.ps1 index 6f18e69..e7057d5 100644 --- a/scripts/SetPageFileSize.ps1 +++ b/scripts/SetPageFileSize.ps1 @@ -14,6 +14,9 @@ param( ) Write-Host "test" +Write-Host $MinimumSize +Write-Host $MaximumSize +Write-Host $DiskRoot # https://referencesource.microsoft.com/#System.IdentityModel/System/IdentityModel/NativeMethods.cs,619688d876febbe1 # https://www.geoffchappell.com/studies/windows/km/ntoskrnl/api/mm/modwrite/create.htm diff --git a/src/configure-pagefile.ts b/src/configure-pagefile.ts index fe442b8..6cb80cb 100644 --- a/src/configure-pagefile.ts +++ b/src/configure-pagefile.ts @@ -30,16 +30,13 @@ const run = (): void => { const scriptResult = child.spawnSync("pwsh", ["-File", scriptPath], { timeout: 60 * 1000 }); - core.info(JSON.stringify(scriptResult, null, 2)); if (scriptResult.stdout) { core.info("stdout"); - const v = String(scriptResult.stdout); - core.info(v); + core.info(scriptResult.stdout.toString()); } if (scriptResult.stderr) { core.info("stderr"); - const v = String(scriptResult.stderr); - core.error(v); + core.error(scriptResult.stderr.toString()); } if (scriptResult.status !== 0) { throw new Error(`Script has finished with exit code '${scriptResult.status}'`) } } catch (error) { From 579960942c1ccfacbbb0a533ae965024b7d8c3b4 Mon Sep 17 00:00:00 2001 From: Maxim Lobanov Date: Fri, 1 May 2020 21:40:11 +0300 Subject: [PATCH 15/22] next debug --- .github/workflows/test.yml | 4 ++-- dist/index.js | 4 ++-- src/configure-pagefile.ts | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index f83dad4..cf87d15 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -23,7 +23,7 @@ jobs: shell: pwsh run: | (Get-CimInstance Win32_PageFileUsage).AllocatedBaseSize - Invoke-Expression "wmic pagefile list /format:list" + Invoke-Expression "wmic pagefile list /format:list" | Select-String "AllocatedBaseSize=", "Name=" custom-parameters: strategy: @@ -47,4 +47,4 @@ jobs: shell: pwsh run: | (Get-CimInstance Win32_PageFileUsage).AllocatedBaseSize - Invoke-Expression "wmic pagefile list /format:list" + Invoke-Expression "wmic pagefile list /format:list" | Select-String "AllocatedBaseSize=", "Name=" diff --git a/dist/index.js b/dist/index.js index 3dc058e..8e32150 100644 --- a/dist/index.js +++ b/dist/index.js @@ -188,12 +188,12 @@ const run = () => { const scriptArguments = [ "-MinimumSize", minimumSize, "-MaximumSize", maximumSize, - "-DiskRoot", `"${diskRoot}"` + "-DiskRoot", diskRoot ]; core.debug("Invoke configuration script:"); core.debug(`Script path: ${scriptPath}`); core.debug(`Script arguments: ${scriptArguments}`); - const scriptResult = child.spawnSync("pwsh", ["-File", scriptPath], { + const scriptResult = child.spawnSync("pwsh", ["-File", scriptPath, ...scriptArguments], { timeout: 60 * 1000 }); if (scriptResult.stdout) { diff --git a/src/configure-pagefile.ts b/src/configure-pagefile.ts index 6cb80cb..caabf14 100644 --- a/src/configure-pagefile.ts +++ b/src/configure-pagefile.ts @@ -21,13 +21,13 @@ const run = (): void => { const scriptArguments = [ "-MinimumSize", minimumSize, "-MaximumSize", maximumSize, - "-DiskRoot", `"${diskRoot}"` + "-DiskRoot", diskRoot ]; core.debug("Invoke configuration script:"); core.debug(`Script path: ${scriptPath}`); core.debug(`Script arguments: ${scriptArguments}`); - const scriptResult = child.spawnSync("pwsh", ["-File", scriptPath], { + const scriptResult = child.spawnSync("pwsh", ["-File", scriptPath, ...scriptArguments], { timeout: 60 * 1000 }); if (scriptResult.stdout) { From 55005b77a7cda9d2a5658754cc29f40de71671d3 Mon Sep 17 00:00:00 2001 From: Maxim Lobanov Date: Fri, 1 May 2020 21:42:04 +0300 Subject: [PATCH 16/22] remove debug --- scripts/SetPageFileSize.ps1 | 7 ------- src/configure-pagefile.ts | 10 ++-------- 2 files changed, 2 insertions(+), 15 deletions(-) diff --git a/scripts/SetPageFileSize.ps1 b/scripts/SetPageFileSize.ps1 index e7057d5..8407efd 100644 --- a/scripts/SetPageFileSize.ps1 +++ b/scripts/SetPageFileSize.ps1 @@ -13,11 +13,6 @@ param( [System.String] $DiskRoot = "D:" ) -Write-Host "test" -Write-Host $MinimumSize -Write-Host $MaximumSize -Write-Host $DiskRoot - # https://referencesource.microsoft.com/#System.IdentityModel/System/IdentityModel/NativeMethods.cs,619688d876febbe1 # https://www.geoffchappell.com/studies/windows/km/ntoskrnl/api/mm/modwrite/create.htm # https://referencesource.microsoft.com/#mscorlib/microsoft/win32/safehandles/safefilehandle.cs,9b08210f3be75520 @@ -194,7 +189,5 @@ namespace Util Add-Type -TypeDefinition $source -Write-Host "test2" - # Set SetPageFileSize [Util.PageFile]::SetPageFileSize($minimumSize, $maximumSize, $diskRoot) \ No newline at end of file diff --git a/src/configure-pagefile.ts b/src/configure-pagefile.ts index caabf14..0e69350 100644 --- a/src/configure-pagefile.ts +++ b/src/configure-pagefile.ts @@ -30,14 +30,8 @@ const run = (): void => { const scriptResult = child.spawnSync("pwsh", ["-File", scriptPath, ...scriptArguments], { timeout: 60 * 1000 }); - if (scriptResult.stdout) { - core.info("stdout"); - core.info(scriptResult.stdout.toString()); - } - if (scriptResult.stderr) { - core.info("stderr"); - core.error(scriptResult.stderr.toString()); - } + if (scriptResult.stdout) { core.info(scriptResult.stdout.toString()); } + if (scriptResult.stderr) { core.error(scriptResult.stderr.toString()); } if (scriptResult.status !== 0) { throw new Error(`Script has finished with exit code '${scriptResult.status}'`) } } catch (error) { core.setFailed(error.message); From fc100164c6a3b8a6284d30a75581b0ac7592cdf8 Mon Sep 17 00:00:00 2001 From: Maxim Lobanov Date: Fri, 1 May 2020 21:45:15 +0300 Subject: [PATCH 17/22] Update index.js --- dist/index.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/dist/index.js b/dist/index.js index 8e32150..80e3bb8 100644 --- a/dist/index.js +++ b/dist/index.js @@ -197,11 +197,9 @@ const run = () => { timeout: 60 * 1000 }); if (scriptResult.stdout) { - core.info("stdout"); core.info(scriptResult.stdout.toString()); } if (scriptResult.stderr) { - core.info("stderr"); core.error(scriptResult.stderr.toString()); } if (scriptResult.status !== 0) { From 12ad4f9dbcb2cf8ca6343d47294a4d61e3f03c3f Mon Sep 17 00:00:00 2001 From: Maxim Lobanov Date: Fri, 1 May 2020 21:51:56 +0300 Subject: [PATCH 18/22] debug action output --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index cf87d15..c2197d5 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -39,7 +39,7 @@ jobs: - name: configure-pagefile-action uses: ./ with: - minimum-size: 4GB + minimum-size: 8GB maximum-size: 8GB disk-root: ${{ matrix.disk-root }} From 962d7e656c9793ced5b8afcd7be89d961a22fdc0 Mon Sep 17 00:00:00 2001 From: Maxim Lobanov Date: Fri, 1 May 2020 21:54:50 +0300 Subject: [PATCH 19/22] fix test matrix --- .github/workflows/test.yml | 2 +- action.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index c2197d5..cf87d15 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -39,7 +39,7 @@ jobs: - name: configure-pagefile-action uses: ./ with: - minimum-size: 8GB + minimum-size: 4GB maximum-size: 8GB disk-root: ${{ matrix.disk-root }} diff --git a/action.yml b/action.yml index d3c107e..417207d 100644 --- a/action.yml +++ b/action.yml @@ -12,7 +12,7 @@ inputs: disk-root: description: 'Set disk root where pagefile.sys will be located' required: false - default: D:\ + default: 'D:' runs: using: 'node12' main: 'dist/index.js' From ac7221246d6b456d50acf6d40065202a4d6cfb59 Mon Sep 17 00:00:00 2001 From: Maxim Lobanov Date: Fri, 1 May 2020 22:10:14 +0300 Subject: [PATCH 20/22] Update action.yml --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index 417207d..fba8436 100644 --- a/action.yml +++ b/action.yml @@ -12,7 +12,7 @@ inputs: disk-root: description: 'Set disk root where pagefile.sys will be located' required: false - default: 'D:' + default: 'D' runs: using: 'node12' main: 'dist/index.js' From 5092bffe38cb16d8083a65b7163597e33e433f30 Mon Sep 17 00:00:00 2001 From: Maxim Lobanov Date: Fri, 1 May 2020 22:11:28 +0300 Subject: [PATCH 21/22] Update action.yml --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index fba8436..417207d 100644 --- a/action.yml +++ b/action.yml @@ -12,7 +12,7 @@ inputs: disk-root: description: 'Set disk root where pagefile.sys will be located' required: false - default: 'D' + default: 'D:' runs: using: 'node12' main: 'dist/index.js' From 92339d23a8b6ce3ec5d44d3897d47a402c299742 Mon Sep 17 00:00:00 2001 From: Maxim Lobanov Date: Fri, 1 May 2020 22:32:48 +0300 Subject: [PATCH 22/22] Update readme --- README.md | 10 +++++----- action.yml | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 0d8e2e6..0e814af 100644 --- a/README.md +++ b/README.md @@ -2,11 +2,11 @@ This action is intended to configure Pagefile size and location for Windows images in GitHub Actions. # Available parameters -| Argument | Description | Default value | -|-------------------------|--------------------------|--------------------| -| `minimum-size` | Set minimum size of Pagefile (GB) | `8` | -| `maximum-size` | Set maximum size of Pagefile (GB) | `minimum-size` | -| `disk-root` | Set disk root where Pagefile will be located | `C:`, `D:` | +| Argument | Description | Format | Default value | +|----------|-------------|--------|---------------| +| `minimum-size` | Set minimum size of Pagefile | `2048MB`, `4GB`, `8GB` and etc | `8GB` | +| `maximum-size` | Set maximum size of Pagefile | The same like `minimum-size` | `minimum-size` | +| `disk-root` | Set disk root where Pagefile will be located | `C:` or `D:` | `D:` | # Usage ``` diff --git a/action.yml b/action.yml index 417207d..538d7b8 100644 --- a/action.yml +++ b/action.yml @@ -3,11 +3,11 @@ author: 'Aleksandr Chebotov & Maxim Lobanov' description: 'Configure Pagefile on Windows agents in GitHub Actions' inputs: minimum-size: - description: 'Set minimum size of Pagefile (GB)' + description: 'Set minimum size of Pagefile' required: false default: 8GB maximum-size: - description: 'Set maximum size of Pagefile (GB)' + description: 'Set maximum size of Pagefile' required: false disk-root: description: 'Set disk root where pagefile.sys will be located'