You've already forked setup-msbuild
mirror of
https://github.com/microsoft/setup-msbuild.git
synced 2025-07-16 20:10:34 +07:00
Compare commits
68 Commits
Author | SHA1 | Date | |
---|---|---|---|
b381dbabab | |||
36d6f2fae1 | |||
65aeb87ed1 | |||
50f8578df5 | |||
fbf0ccc42a | |||
fbf959e541 | |||
ce3de01b52 | |||
c7c2934c87 | |||
c4a66a0e8a | |||
e48d8c6605 | |||
ab534842b4 | |||
84e0d709b2 | |||
613696a2a0 | |||
6c2e301a93 | |||
0cd944e169 | |||
aaa8d4fac0 | |||
323ede3ce9 | |||
dfaf113754 | |||
33941d8101 | |||
8611b39e1b | |||
2cbcfcb795 | |||
a7d39343f8 | |||
9546707e6b | |||
f9e64ce582 | |||
6387a9728e | |||
412f270368 | |||
455ec54ae7 | |||
4917605713 | |||
7561732237 | |||
047d9a0678 | |||
9afe006fef | |||
babd7930ed | |||
7626c90a39 | |||
1982f45c48 | |||
0e477eda77 | |||
f032e55f3f | |||
6a8fedefe9 | |||
a0858ffef3 | |||
9fe8dba406 | |||
0b5643901b | |||
45346b5e09 | |||
06c9a7f31c | |||
f25dd68be2 | |||
3fedb575b0 | |||
84ff5b46d8 | |||
e4874c190b | |||
41a4f5dd79 | |||
9c8b0140a4 | |||
57920ca044 | |||
0d4f73260b | |||
341cfb53e3 | |||
c4f3bee2c4 | |||
20e1303853 | |||
e9f4898311 | |||
9499ca8787 | |||
0ddbddf06e | |||
80d0deb83b | |||
2f9b9c17d6 | |||
7d7af37b7e | |||
5cf04033c1 | |||
f6890ff843 | |||
f486e795bf | |||
4652bfc96e | |||
bb70c6a023 | |||
dc59c705e4 | |||
f05df80b32 | |||
43cd4ebaec | |||
9c9a1a34a4 |
33
.github/workflows/test.yml
vendored
33
.github/workflows/test.yml
vendored
@ -1,5 +1,10 @@
|
||||
name: "build-test-dev"
|
||||
on:
|
||||
pull_request:
|
||||
branches:
|
||||
- dev
|
||||
paths-ignore:
|
||||
- '*.md'
|
||||
push:
|
||||
branches:
|
||||
- dev
|
||||
@ -12,14 +17,34 @@ jobs:
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
|
||||
- name: Setup MSBuild
|
||||
id: setup_msbuild
|
||||
- name: Setup MSBuild (vswhere-path)
|
||||
id: setup_msbuild_explicit
|
||||
uses: ./
|
||||
with:
|
||||
vs-version: "[16.4,16.5]"
|
||||
vswhere-path: C:\ProgramData\chocolatey\bin
|
||||
|
||||
- name: Setup MSBuild (PATH)
|
||||
id: setup_msbuild_path
|
||||
uses: ./
|
||||
|
||||
- name: Setup MSBuild (fallback)
|
||||
id: setup_msbuild_fallback
|
||||
uses: ./
|
||||
env:
|
||||
PATH: ''
|
||||
|
||||
- name: Setup MSBuild (x64)
|
||||
id: setup_msbuild_path
|
||||
uses: ./
|
||||
with:
|
||||
vs-prerelease: true
|
||||
msbuild-architecture: 'x64'
|
||||
|
||||
- name: echo msbuild path
|
||||
run: echo "${{ steps.setup_msbuild.outputs.msbuildPath }}"
|
||||
run: |
|
||||
echo "vswhere-path: ${{ steps.setup_msbuild_explicit.outputs.msbuildPath }}"
|
||||
echo "PATH: ${{ steps.setup_msbuild_path.outputs.msbuildPath }}"
|
||||
echo "Fallback: ${{ steps.setup_msbuild_fallback.outputs.msbuildPath }}"
|
||||
|
||||
- name: echo MSBuild
|
||||
run: msbuild -version
|
65
README.md
65
README.md
@ -1,37 +1,70 @@
|
||||
# microsoft/setup-msbuild
|
||||
You know how handy that 'Visual Studio Developer Command Prompt' is on your local machine? And how it adds several things to `PATH` to allow you to just issue commands like `msbuild` or otherwise? Use this action to setup similar flexibility in your Windows-based GitHub Actions runners. This will let you discover where those tool paths are and automatically add them to the `PATH` environment variables for you so future steps in your Actions workflow can just initiate commands without knowing the full path.
|
||||
This action will help discover where the `MSBuild` tool is and automatically add it to the `PATH` environment variables for you so future steps in your Actions workflow can just initiate `msbuild` commands without knowing the full path.
|
||||
|
||||
## Usage
|
||||
> Please note this tool does NOT add other Visual Studio tools (like VSTest, cl, cmake, or others) to `PATH`
|
||||
|
||||
```
|
||||
## Example Usage
|
||||
|
||||
```yml
|
||||
- name: Add msbuild to PATH
|
||||
uses: microsoft/setup-msbuild@v1.0.0
|
||||
uses: microsoft/setup-msbuild@v1.1
|
||||
|
||||
- name: Build app for release
|
||||
run: msbuild src\YourProjectFile.csproj -t:rebuild -verbosity:diag -property:Configuration=Release
|
||||
```
|
||||
|
||||
## Specifying specific versions of Visual Studio
|
||||
You may have a situation where your Actions runner has multiple versions of Visual Studio and you need to find a specific version of the tool. Simply add the `vs-version` input to specify the range of versions to find. If looking for a specific version, enter that version number twice as a range.
|
||||
## Optional Parameters
|
||||
There are a few additional parameters that can be set if you need them. These are optional and should only be set if you know that you need them or what you are doing.
|
||||
|
||||
```
|
||||
### Specifying specific versions of Visual Studio (optional)
|
||||
You may have a situation where your Actions runner has multiple versions of Visual Studio and you need to find a specific version of the tool. Simply add the `vs-version` input to specify the range of versions to find. If looking for a specific version, specify the minimum and maximum versions as shown in the example below, which will look for just 16.4.
|
||||
|
||||
```yml
|
||||
- name: Add msbuild to PATH
|
||||
uses: microsoft/setup-msbuild@v1.0.0
|
||||
with:
|
||||
vs-version: [16.4,16.5]
|
||||
uses: microsoft/setup-msbuild@v1.1
|
||||
with:
|
||||
vs-version: '[16.4,16.5)'
|
||||
```
|
||||
|
||||
The syntax is the same used for Visual Studio extensions, where square brackets like "[" mean inclusive, and parenthesis like "(" mean exclusive. A comma is always required, but eliding the minimum version looks for all older versions and eliding the maximum version looks for all newer versions. See the [vswhere wiki](https://github.com/microsoft/vswhere/wiki) for more details.
|
||||
|
||||
### Use pre-release versions of Visual Studio (optional)
|
||||
If you need your Actions runner to target a pre-release version of Visual Studio, simply add the `vs-prerelease` input. This is necessary if you want to run an action on a virtual environment that contains a pre-release version of Visual Studio or self-hosted images that you may have that also have pre-release versions of Visual Studio installed.
|
||||
|
||||
```yml
|
||||
- name: Add msbuild to PATH
|
||||
uses: microsoft/setup-msbuild@v1.1
|
||||
with:
|
||||
vs-prerelease: true
|
||||
```
|
||||
|
||||
### Specifying MSBuild architecture (optional)
|
||||
By default the action will use the x86 architecture for MSBuild, but it is possible to target the x64 versions instead. Simply add the `msbuild-architecture` input. Valid input values are `x86` (default) and `x64`.
|
||||
|
||||
```yml
|
||||
- name: Add msbuild to PATH
|
||||
uses: microsoft/setup-msbuild@v1.1
|
||||
with:
|
||||
msbuild-architecture: x64
|
||||
```
|
||||
|
||||
## How does this work?
|
||||
This makes use of the vswhere tool which is a tool is delivered by Microsoft to help in identifying Visual Studio installs and various components. This tool is installed on the hosted Windows runners for GitHub Actions. If you are using a self-hosted runner, you either need to make sure vswhere.exe is in your agent's PATH or specify a full path to the location using:
|
||||
This makes use of the vswhere tool which is a tool delivered by Microsoft to help in identifying Visual Studio installs and various components. This tool is installed on the hosted Windows runners for GitHub Actions. If you are using a self-hosted runner, you either need to make sure vswhere.exe is in your agent's PATH or specify a full path to the location using:
|
||||
|
||||
```
|
||||
```yml
|
||||
- name: Add msbuild to PATH
|
||||
uses: microsoft/setup-msbuild@v1.0.0
|
||||
with:
|
||||
vswhere-path: 'C:\path\to\your\tools\'
|
||||
uses: microsoft/setup-msbuild@v1.1
|
||||
with:
|
||||
vswhere-path: 'C:\path\to\your\tools\'
|
||||
```
|
||||
|
||||
## Notes on arguments
|
||||
While the Action enables you to specify a `vswhere` path as well as a `vs-version`, these are more advanced options and when using GitHub-hosted runners you should not need these and is recommended you don't specify them as they are optional. Using these require you to fully understand the runner environment, updates to the tools on the runner, and can cause failures if you are out of sync. For GitHub-hosted runners, omitting these arguments is the preferred usage.
|
||||
|
||||
## Building this repo
|
||||
As with most GitHub Actions, this requires NodeJS development tools. After installing NodeJS, you can build this by executing:
|
||||
|
||||
```
|
||||
```bash
|
||||
npm install
|
||||
npm run build
|
||||
npm run pack
|
||||
|
@ -11,10 +11,17 @@ inputs:
|
||||
vs-version:
|
||||
description: 'Version of Visual Studio to search; defaults to latest if not specified'
|
||||
required: false
|
||||
vs-prerelease:
|
||||
description: 'Enable searching for pre-release versions of Visual Studio/MSBuild'
|
||||
required: false
|
||||
msbuild-architecture:
|
||||
description: 'The preferred processor architecture of MSBuild. Can be either "x86" or "x64". "x64" is only available from Visual Studio version 17.0 and later.'
|
||||
required: false
|
||||
default: 'x86'
|
||||
outputs:
|
||||
msbuildPath:
|
||||
description: 'The resulting location of msbuild for your inputs'
|
||||
|
||||
runs:
|
||||
using: 'node12'
|
||||
using: 'node16'
|
||||
main: 'dist/index.js'
|
||||
|
29
building-release.md
Normal file
29
building-release.md
Normal file
@ -0,0 +1,29 @@
|
||||
# Building a release
|
||||
This is a quick document to walk through the process of building and releasing.
|
||||
|
||||
## Building the version
|
||||
- Create a new branch [vMajor.Minor.Revision] for the version from `dev`
|
||||
- Make changes in the new branch
|
||||
- Build the branch/package
|
||||
- `npm install`
|
||||
- `npm run build`
|
||||
- `npm run pack`
|
||||
- Prune the dependencies to only production
|
||||
- `npm prune --production`
|
||||
- Uncomment `node_modules` in `.gitignore` **for this branch only**
|
||||
- Commit the changes to the branch
|
||||
- Push the new version branch
|
||||
- `git push origin [vMajor.Minor.Revision]`
|
||||
|
||||
## Releasing the new version
|
||||
- Draft a new release to [vMajor.Minor.Revision]
|
||||
|
||||
## Update major version tag
|
||||
If the update is non-breaking and the major version binding you can update the version tag to make the new release available to those binding to the major version tag ([GitHub Actions Versioning](https://github.com/actions/toolkit/blob/master/docs/action-versioning.md)).
|
||||
|
||||
Do this from the version branch after push (using a v1 tag as example only here)
|
||||
|
||||
```
|
||||
git tag -fa v1 -m "Update v1 tag"
|
||||
git push origin v1 --force
|
||||
```
|
236
dist/index.js
vendored
236
dist/index.js
vendored
@ -934,6 +934,32 @@ class ExecState extends events.EventEmitter {
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 82:
|
||||
/***/ (function(__unusedmodule, exports) {
|
||||
|
||||
"use strict";
|
||||
|
||||
// We use any as a valid input type
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
/**
|
||||
* 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;
|
||||
//# sourceMappingURL=utils.js.map
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 87:
|
||||
/***/ (function(module) {
|
||||
|
||||
@ -941,6 +967,42 @@ module.exports = require("os");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 102:
|
||||
/***/ (function(__unusedmodule, exports, __webpack_require__) {
|
||||
|
||||
"use strict";
|
||||
|
||||
// For internal use, subject to change.
|
||||
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 });
|
||||
// We use any as a valid input type
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
const fs = __importStar(__webpack_require__(747));
|
||||
const os = __importStar(__webpack_require__(87));
|
||||
const utils_1 = __webpack_require__(82);
|
||||
function issueCommand(command, message) {
|
||||
const filePath = process.env[`GITHUB_${command}`];
|
||||
if (!filePath) {
|
||||
throw new Error(`Unable to find environment variable for file command ${command}`);
|
||||
}
|
||||
if (!fs.existsSync(filePath)) {
|
||||
throw new Error(`Missing file at path: ${filePath}`);
|
||||
}
|
||||
fs.appendFileSync(filePath, `${utils_1.toCommandValue(message)}${os.EOL}`, {
|
||||
encoding: 'utf8'
|
||||
});
|
||||
}
|
||||
exports.issueCommand = issueCommand;
|
||||
//# sourceMappingURL=file-command.js.map
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 129:
|
||||
/***/ (function(module) {
|
||||
|
||||
@ -972,22 +1034,22 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const core = __importStar(__webpack_require__(470));
|
||||
const exec = __importStar(__webpack_require__(986));
|
||||
const fs = __importStar(__webpack_require__(747));
|
||||
const path = __importStar(__webpack_require__(622));
|
||||
const io = __importStar(__webpack_require__(1));
|
||||
const IS_WINDOWS = process.platform === 'win32';
|
||||
const VS_VERSION = core.getInput('vs-version') || 'latest';
|
||||
const VSWHERE_PATH = core.getInput('vswhere-path') ||
|
||||
path.join(process.env['ProgramFiles(x86)'], 'Microsoft Visual Studio\\Installer');
|
||||
const VSWHERE_PATH = core.getInput('vswhere-path');
|
||||
const ALLOW_PRERELEASE = core.getInput('vs-prerelease') || 'false';
|
||||
const MSBUILD_ARCH = core.getInput('msbuild-architecture') || 'x86';
|
||||
// if a specific version of VS is requested
|
||||
let VSWHERE_EXEC = '';
|
||||
if (VS_VERSION === 'latest') {
|
||||
VSWHERE_EXEC += '-latest ';
|
||||
let VSWHERE_EXEC = '-products * -requires Microsoft.Component.MSBuild -property installationPath -latest ';
|
||||
if (ALLOW_PRERELEASE === 'true') {
|
||||
VSWHERE_EXEC += ' -prerelease ';
|
||||
}
|
||||
else {
|
||||
VSWHERE_EXEC += `-version ${VS_VERSION} `;
|
||||
if (VS_VERSION !== 'latest') {
|
||||
VSWHERE_EXEC += `-version "${VS_VERSION}" `;
|
||||
}
|
||||
VSWHERE_EXEC +=
|
||||
'-requires Microsoft.Component.MSBuild -find MSBuild\\**\\Bin\\MSBuild.exe';
|
||||
core.debug(`Execution arguments: ${VSWHERE_EXEC}`);
|
||||
function run() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
@ -1001,6 +1063,7 @@ function run() {
|
||||
let vswhereToolExe = '';
|
||||
if (VSWHERE_PATH) {
|
||||
// specified a path for vswhere, use it
|
||||
core.debug(`Using given vswhere-path: ${VSWHERE_PATH}`);
|
||||
vswhereToolExe = path.join(VSWHERE_PATH, 'vswhere.exe');
|
||||
}
|
||||
else {
|
||||
@ -1008,29 +1071,52 @@ function run() {
|
||||
try {
|
||||
const vsWhereInPath = yield io.which('vswhere', true);
|
||||
core.debug(`Found tool in PATH: ${vsWhereInPath}`);
|
||||
vswhereToolExe = path.join(vsWhereInPath, 'vswhere.exe');
|
||||
vswhereToolExe = vsWhereInPath;
|
||||
}
|
||||
catch (_a) {
|
||||
// wasn't found because which threw
|
||||
}
|
||||
finally {
|
||||
core.setFailed('setup-msbuild requires the path to where vswhere.exe exists');
|
||||
// fall back to VS-installed path
|
||||
vswhereToolExe = path.join(process.env['ProgramFiles(x86)'], 'Microsoft Visual Studio\\Installer\\vswhere.exe');
|
||||
core.debug(`Trying Visual Studio-installed path: ${vswhereToolExe}`);
|
||||
}
|
||||
}
|
||||
if (!fs.existsSync(vswhereToolExe)) {
|
||||
core.setFailed('setup-msbuild requires the path to where vswhere.exe exists');
|
||||
return;
|
||||
}
|
||||
core.debug(`Full tool exe: ${vswhereToolExe}`);
|
||||
let foundToolPath = '';
|
||||
const options = {};
|
||||
options.listeners = {
|
||||
stdout: (data) => {
|
||||
// eslint-disable-next-line prefer-const
|
||||
let output = data.toString();
|
||||
foundToolPath += output;
|
||||
const installationPath = data.toString().trim();
|
||||
core.debug(`Found installation path: ${installationPath}`);
|
||||
// x64 only exists in one possible location, so no fallback probing
|
||||
if (MSBUILD_ARCH === "x64") {
|
||||
let toolPath = path.join(installationPath, 'MSBuild\\Current\\Bin\\amd64\\MSBuild.exe');
|
||||
core.debug(`Checking for path: ${toolPath}`);
|
||||
if (!fs.existsSync(toolPath)) {
|
||||
return;
|
||||
}
|
||||
foundToolPath = toolPath;
|
||||
}
|
||||
else {
|
||||
let toolPath = path.join(installationPath, 'MSBuild\\Current\\Bin\\MSBuild.exe');
|
||||
core.debug(`Checking for path: ${toolPath}`);
|
||||
if (!fs.existsSync(toolPath)) {
|
||||
toolPath = path.join(installationPath, 'MSBuild\\15.0\\Bin\\MSBuild.exe');
|
||||
core.debug(`Checking for path: ${toolPath}`);
|
||||
if (!fs.existsSync(toolPath)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
foundToolPath = toolPath;
|
||||
}
|
||||
}
|
||||
};
|
||||
// execute the find putting the result of the command in the options foundToolPath
|
||||
yield exec.exec(`"${vswhereToolExe}" ${VSWHERE_EXEC}`, [], options);
|
||||
if (!foundToolPath) {
|
||||
core.setFailed('Unable to find msbuild.');
|
||||
core.setFailed('Unable to find MSBuild.');
|
||||
return;
|
||||
}
|
||||
// extract the folder location for the tool
|
||||
@ -1063,17 +1149,25 @@ module.exports = require("assert");
|
||||
|
||||
"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 = __webpack_require__(87);
|
||||
const os = __importStar(__webpack_require__(87));
|
||||
const utils_1 = __webpack_require__(82);
|
||||
/**
|
||||
* Commands
|
||||
*
|
||||
* Command Format:
|
||||
* ##[name key=value;key=value]message
|
||||
* ::name key=value,key=value::message
|
||||
*
|
||||
* Examples:
|
||||
* ##[warning]This is the user warning message
|
||||
* ##[set-secret name=mypassword]definitelyNotAPassword!
|
||||
* ::warning::This is the message
|
||||
* ::set-env name=MY_VAR::some value
|
||||
*/
|
||||
function issueCommand(command, properties, message) {
|
||||
const cmd = new Command(command, properties, message);
|
||||
@ -1098,34 +1192,39 @@ class Command {
|
||||
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) {
|
||||
// safely append the val - avoid blowing up when attempting to
|
||||
// call .replace() if message is not a string for some reason
|
||||
cmdStr += `${key}=${escape(`${val || ''}`)},`;
|
||||
if (first) {
|
||||
first = false;
|
||||
}
|
||||
else {
|
||||
cmdStr += ',';
|
||||
}
|
||||
cmdStr += `${key}=${escapeProperty(val)}`;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
cmdStr += CMD_STRING;
|
||||
// safely append the message - avoid blowing up when attempting to
|
||||
// call .replace() if message is not a string for some reason
|
||||
const message = `${this.message || ''}`;
|
||||
cmdStr += escapeData(message);
|
||||
cmdStr += `${CMD_STRING}${escapeData(this.message)}`;
|
||||
return cmdStr;
|
||||
}
|
||||
}
|
||||
function escapeData(s) {
|
||||
return s.replace(/\r/g, '%0D').replace(/\n/g, '%0A');
|
||||
return utils_1.toCommandValue(s)
|
||||
.replace(/%/g, '%25')
|
||||
.replace(/\r/g, '%0D')
|
||||
.replace(/\n/g, '%0A');
|
||||
}
|
||||
function escape(s) {
|
||||
return s
|
||||
function escapeProperty(s) {
|
||||
return utils_1.toCommandValue(s)
|
||||
.replace(/%/g, '%25')
|
||||
.replace(/\r/g, '%0D')
|
||||
.replace(/\n/g, '%0A')
|
||||
.replace(/]/g, '%5D')
|
||||
.replace(/;/g, '%3B');
|
||||
.replace(/:/g, '%3A')
|
||||
.replace(/,/g, '%2C');
|
||||
}
|
||||
//# sourceMappingURL=command.js.map
|
||||
|
||||
@ -1145,10 +1244,19 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
||||
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 = __webpack_require__(87);
|
||||
const path = __webpack_require__(622);
|
||||
const file_command_1 = __webpack_require__(102);
|
||||
const utils_1 = __webpack_require__(82);
|
||||
const os = __importStar(__webpack_require__(87));
|
||||
const path = __importStar(__webpack_require__(622));
|
||||
/**
|
||||
* The code to exit an action
|
||||
*/
|
||||
@ -1169,11 +1277,21 @@ var ExitCode;
|
||||
/**
|
||||
* 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
|
||||
* @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) {
|
||||
process.env[name] = val;
|
||||
command_1.issueCommand('set-env', { name }, val);
|
||||
const convertedVal = utils_1.toCommandValue(val);
|
||||
process.env[name] = convertedVal;
|
||||
const filePath = process.env['GITHUB_ENV'] || '';
|
||||
if (filePath) {
|
||||
const delimiter = '_GitHubActionsFileCommandDelimeter_';
|
||||
const commandValue = `${name}<<${delimiter}${os.EOL}${convertedVal}${os.EOL}${delimiter}`;
|
||||
file_command_1.issueCommand('ENV', commandValue);
|
||||
}
|
||||
else {
|
||||
command_1.issueCommand('set-env', { name }, convertedVal);
|
||||
}
|
||||
}
|
||||
exports.exportVariable = exportVariable;
|
||||
/**
|
||||
@ -1189,7 +1307,13 @@ exports.setSecret = setSecret;
|
||||
* @param inputPath
|
||||
*/
|
||||
function addPath(inputPath) {
|
||||
command_1.issueCommand('add-path', {}, inputPath);
|
||||
const filePath = process.env['GITHUB_PATH'] || '';
|
||||
if (filePath) {
|
||||
file_command_1.issueCommand('PATH', inputPath);
|
||||
}
|
||||
else {
|
||||
command_1.issueCommand('add-path', {}, inputPath);
|
||||
}
|
||||
process.env['PATH'] = `${inputPath}${path.delimiter}${process.env['PATH']}`;
|
||||
}
|
||||
exports.addPath = addPath;
|
||||
@ -1212,12 +1336,22 @@ exports.getInput = getInput;
|
||||
* Sets the value of an output.
|
||||
*
|
||||
* @param name name of the output to set
|
||||
* @param value value 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 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
|
||||
//-----------------------------------------------------------------------
|
||||
@ -1234,6 +1368,13 @@ 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
|
||||
@ -1244,18 +1385,18 @@ function debug(message) {
|
||||
exports.debug = debug;
|
||||
/**
|
||||
* Adds an error issue
|
||||
* @param message error issue message
|
||||
* @param message error issue message. Errors will be converted to string via toString()
|
||||
*/
|
||||
function error(message) {
|
||||
command_1.issue('error', message);
|
||||
command_1.issue('error', message instanceof Error ? message.toString() : message);
|
||||
}
|
||||
exports.error = error;
|
||||
/**
|
||||
* Adds an warning issue
|
||||
* @param message warning issue message
|
||||
* @param message warning issue message. Errors will be converted to string via toString()
|
||||
*/
|
||||
function warning(message) {
|
||||
command_1.issue('warning', message);
|
||||
command_1.issue('warning', message instanceof Error ? message.toString() : message);
|
||||
}
|
||||
exports.warning = warning;
|
||||
/**
|
||||
@ -1313,8 +1454,9 @@ exports.group = group;
|
||||
* 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
|
||||
* @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);
|
||||
}
|
||||
|
8354
package-lock.json
generated
8354
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "setup-msbuild",
|
||||
"version": "1.0.0",
|
||||
"version": "1.1.1",
|
||||
"private": true,
|
||||
"description": "Helps set up specific MSBuild tool into PATH for later usage.",
|
||||
"main": "lib/main.js",
|
||||
@ -11,7 +11,7 @@
|
||||
"lint": "eslint src/**/*.ts",
|
||||
"pack": "ncc build",
|
||||
"test": "jest",
|
||||
"all": "npm run build && npm run format && npm run lint && npm run pack && npm test"
|
||||
"all": "npm run build && npm run format && npm run lint && npm run pack"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
@ -28,7 +28,7 @@
|
||||
"author": "Microsoft",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@actions/core": "^1.2.0",
|
||||
"@actions/core": "^1.2.6",
|
||||
"@actions/exec": "^1.0.3",
|
||||
"@actions/tool-cache": "^1.3.0"
|
||||
},
|
||||
|
84
src/main.ts
84
src/main.ts
@ -1,27 +1,25 @@
|
||||
import * as core from '@actions/core'
|
||||
import * as exec from '@actions/exec'
|
||||
import * as fs from 'fs'
|
||||
import * as path from 'path'
|
||||
import * as io from '@actions/io'
|
||||
import {ExecOptions} from '@actions/exec/lib/interfaces'
|
||||
|
||||
const IS_WINDOWS = process.platform === 'win32'
|
||||
const VS_VERSION = core.getInput('vs-version') || 'latest'
|
||||
const VSWHERE_PATH =
|
||||
core.getInput('vswhere-path') ||
|
||||
path.join(
|
||||
process.env['ProgramFiles(x86)'] as string,
|
||||
'Microsoft Visual Studio\\Installer'
|
||||
)
|
||||
const VSWHERE_PATH = core.getInput('vswhere-path')
|
||||
const ALLOW_PRERELEASE = core.getInput('vs-prerelease') || 'false'
|
||||
const MSBUILD_ARCH = core.getInput('msbuild-architecture') || 'x86'
|
||||
|
||||
// if a specific version of VS is requested
|
||||
let VSWHERE_EXEC = ''
|
||||
if (VS_VERSION === 'latest') {
|
||||
VSWHERE_EXEC += '-latest '
|
||||
} else {
|
||||
VSWHERE_EXEC += `-version ${VS_VERSION} `
|
||||
let VSWHERE_EXEC = '-products * -requires Microsoft.Component.MSBuild -property installationPath -latest '
|
||||
if (ALLOW_PRERELEASE === 'true') {
|
||||
VSWHERE_EXEC += ' -prerelease '
|
||||
}
|
||||
|
||||
if (VS_VERSION !== 'latest') {
|
||||
VSWHERE_EXEC += `-version "${VS_VERSION}" `
|
||||
}
|
||||
VSWHERE_EXEC +=
|
||||
'-requires Microsoft.Component.MSBuild -find MSBuild\\**\\Bin\\MSBuild.exe'
|
||||
|
||||
core.debug(`Execution arguments: ${VSWHERE_EXEC}`)
|
||||
|
||||
@ -38,31 +36,73 @@ async function run(): Promise<void> {
|
||||
|
||||
if (VSWHERE_PATH) {
|
||||
// specified a path for vswhere, use it
|
||||
core.debug(`Using given vswhere-path: ${VSWHERE_PATH}`)
|
||||
vswhereToolExe = path.join(VSWHERE_PATH, 'vswhere.exe')
|
||||
} else {
|
||||
// check in PATH to see if it is there
|
||||
try {
|
||||
const vsWhereInPath: string = await io.which('vswhere', true)
|
||||
core.debug(`Found tool in PATH: ${vsWhereInPath}`)
|
||||
vswhereToolExe = path.join(vsWhereInPath, 'vswhere.exe')
|
||||
vswhereToolExe = vsWhereInPath
|
||||
} catch {
|
||||
// wasn't found because which threw
|
||||
} finally {
|
||||
core.setFailed(
|
||||
'setup-msbuild requires the path to where vswhere.exe exists'
|
||||
// fall back to VS-installed path
|
||||
vswhereToolExe = path.join(
|
||||
process.env['ProgramFiles(x86)'] as string,
|
||||
'Microsoft Visual Studio\\Installer\\vswhere.exe'
|
||||
)
|
||||
core.debug(`Trying Visual Studio-installed path: ${vswhereToolExe}`)
|
||||
}
|
||||
}
|
||||
|
||||
if (!fs.existsSync(vswhereToolExe)) {
|
||||
core.setFailed(
|
||||
'setup-msbuild requires the path to where vswhere.exe exists'
|
||||
)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
core.debug(`Full tool exe: ${vswhereToolExe}`)
|
||||
|
||||
let foundToolPath = ''
|
||||
const options: ExecOptions = {}
|
||||
options.listeners = {
|
||||
stdout: (data: Buffer) => {
|
||||
// eslint-disable-next-line prefer-const
|
||||
let output = data.toString()
|
||||
foundToolPath += output
|
||||
const installationPath = data.toString().trim()
|
||||
core.debug(`Found installation path: ${installationPath}`)
|
||||
|
||||
// x64 only exists in one possible location, so no fallback probing
|
||||
if (MSBUILD_ARCH === "x64") {
|
||||
let toolPath = path.join(
|
||||
installationPath,
|
||||
'MSBuild\\Current\\Bin\\amd64\\MSBuild.exe'
|
||||
);
|
||||
core.debug(`Checking for path: ${toolPath}`)
|
||||
if (!fs.existsSync(toolPath)) {
|
||||
return
|
||||
}
|
||||
foundToolPath = toolPath
|
||||
} else {
|
||||
let toolPath = path.join(
|
||||
installationPath,
|
||||
'MSBuild\\Current\\Bin\\MSBuild.exe'
|
||||
)
|
||||
|
||||
core.debug(`Checking for path: ${toolPath}`)
|
||||
if (!fs.existsSync(toolPath)) {
|
||||
toolPath = path.join(
|
||||
installationPath,
|
||||
'MSBuild\\15.0\\Bin\\MSBuild.exe'
|
||||
)
|
||||
|
||||
core.debug(`Checking for path: ${toolPath}`)
|
||||
if (!fs.existsSync(toolPath)) {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
foundToolPath = toolPath
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -70,7 +110,7 @@ async function run(): Promise<void> {
|
||||
await exec.exec(`"${vswhereToolExe}" ${VSWHERE_EXEC}`, [], options)
|
||||
|
||||
if (!foundToolPath) {
|
||||
core.setFailed('Unable to find msbuild.')
|
||||
core.setFailed('Unable to find MSBuild.')
|
||||
return
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user