mirror of
https://github.com/actions/setup-node.git
synced 2026-06-20 14:33:48 +08:00
Compare commits
2 Commits
v4.0.2
...
ba94aebe4c
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ba94aebe4c | ||
|
|
0d716b2cd5 |
78
.github/workflows/azure-webapps-node.yml
vendored
Normal file
78
.github/workflows/azure-webapps-node.yml
vendored
Normal file
@@ -0,0 +1,78 @@
|
|||||||
|
# This workflow will build and push a node.js application to an Azure Web App when a commit is pushed to your default branch.
|
||||||
|
#
|
||||||
|
# This workflow assumes you have already created the target Azure App Service web app.
|
||||||
|
# For instructions see https://docs.microsoft.com/en-us/azure/app-service/quickstart-nodejs?tabs=linux&pivots=development-environment-cli
|
||||||
|
#
|
||||||
|
# To configure this workflow:
|
||||||
|
#
|
||||||
|
# 1. Download the Publish Profile for your Azure Web App. You can download this file from the Overview page of your Web App in the Azure Portal.
|
||||||
|
# For more information: https://docs.microsoft.com/en-us/azure/app-service/deploy-github-actions?tabs=applevel#generate-deployment-credentials
|
||||||
|
#
|
||||||
|
# 2. Create a secret in your repository named AZURE_WEBAPP_PUBLISH_PROFILE, paste the publish profile contents as the value of the secret.
|
||||||
|
# For instructions on obtaining the publish profile see: https://docs.microsoft.com/azure/app-service/deploy-github-actions#configure-the-github-secret
|
||||||
|
#
|
||||||
|
# 3. Change the value for the AZURE_WEBAPP_NAME. Optionally, change the AZURE_WEBAPP_PACKAGE_PATH and NODE_VERSION environment variables below.
|
||||||
|
#
|
||||||
|
# For more information on GitHub Actions for Azure: https://github.com/Azure/Actions
|
||||||
|
# For more information on the Azure Web Apps Deploy action: https://github.com/Azure/webapps-deploy
|
||||||
|
# For more samples to get started with GitHub Action workflows to deploy to Azure: https://github.com/Azure/actions-workflow-samples
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [ "main" ]
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
env:
|
||||||
|
AZURE_WEBAPP_NAME: your-app-name # set this to your application's name
|
||||||
|
AZURE_WEBAPP_PACKAGE_PATH: '.' # set this to the path to your web app project, defaults to the repository root
|
||||||
|
NODE_VERSION: '14.x' # set this to the node version to use
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Set up Node.js
|
||||||
|
uses: actions/setup-node@v3
|
||||||
|
with:
|
||||||
|
node-version: ${{ env.NODE_VERSION }}
|
||||||
|
cache: 'npm'
|
||||||
|
|
||||||
|
- name: npm install, build, and test
|
||||||
|
run: |
|
||||||
|
npm install
|
||||||
|
npm run build --if-present
|
||||||
|
npm run test --if-present
|
||||||
|
|
||||||
|
- name: Upload artifact for deployment job
|
||||||
|
uses: actions/upload-artifact@v3
|
||||||
|
with:
|
||||||
|
name: node-app
|
||||||
|
path: .
|
||||||
|
|
||||||
|
deploy:
|
||||||
|
permissions:
|
||||||
|
contents: none
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
needs: build
|
||||||
|
environment:
|
||||||
|
name: 'Development'
|
||||||
|
url: ${{ steps.deploy-to-webapp.outputs.webapp-url }}
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Download artifact from build job
|
||||||
|
uses: actions/download-artifact@v3
|
||||||
|
with:
|
||||||
|
name: node-app
|
||||||
|
|
||||||
|
- name: 'Deploy to Azure WebApp'
|
||||||
|
id: deploy-to-webapp
|
||||||
|
uses: azure/webapps-deploy@v2
|
||||||
|
with:
|
||||||
|
app-name: ${{ env.AZURE_WEBAPP_NAME }}
|
||||||
|
publish-profile: ${{ secrets.AZURE_WEBAPP_PUBLISH_PROFILE }}
|
||||||
|
package: ${{ env.AZURE_WEBAPP_PACKAGE_PATH }}
|
||||||
@@ -2,7 +2,6 @@ import * as core from '@actions/core';
|
|||||||
import * as exec from '@actions/exec';
|
import * as exec from '@actions/exec';
|
||||||
import * as tc from '@actions/tool-cache';
|
import * as tc from '@actions/tool-cache';
|
||||||
import * as cache from '@actions/cache';
|
import * as cache from '@actions/cache';
|
||||||
import * as io from '@actions/io';
|
|
||||||
|
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
@@ -25,10 +24,6 @@ describe('main tests', () => {
|
|||||||
let startGroupSpy: jest.SpyInstance;
|
let startGroupSpy: jest.SpyInstance;
|
||||||
let endGroupSpy: jest.SpyInstance;
|
let endGroupSpy: jest.SpyInstance;
|
||||||
|
|
||||||
let whichSpy: jest.SpyInstance;
|
|
||||||
|
|
||||||
let existsSpy: jest.SpyInstance;
|
|
||||||
|
|
||||||
let getExecOutputSpy: jest.SpyInstance;
|
let getExecOutputSpy: jest.SpyInstance;
|
||||||
|
|
||||||
let getNodeVersionFromFileSpy: jest.SpyInstance;
|
let getNodeVersionFromFileSpy: jest.SpyInstance;
|
||||||
@@ -60,8 +55,6 @@ describe('main tests', () => {
|
|||||||
inSpy = jest.spyOn(core, 'getInput');
|
inSpy = jest.spyOn(core, 'getInput');
|
||||||
inSpy.mockImplementation(name => inputs[name]);
|
inSpy.mockImplementation(name => inputs[name]);
|
||||||
|
|
||||||
whichSpy = jest.spyOn(io, 'which');
|
|
||||||
|
|
||||||
getExecOutputSpy = jest.spyOn(exec, 'getExecOutput');
|
getExecOutputSpy = jest.spyOn(exec, 'getExecOutput');
|
||||||
|
|
||||||
findSpy = jest.spyOn(tc, 'find');
|
findSpy = jest.spyOn(tc, 'find');
|
||||||
@@ -147,10 +140,6 @@ describe('main tests', () => {
|
|||||||
return {stdout: obj[command], stderr: '', exitCode: 0};
|
return {stdout: obj[command], stderr: '', exitCode: 0};
|
||||||
});
|
});
|
||||||
|
|
||||||
whichSpy.mockImplementation(cmd => {
|
|
||||||
return `some/${cmd}/path`;
|
|
||||||
});
|
|
||||||
|
|
||||||
await util.printEnvDetailsAndSetOutput();
|
await util.printEnvDetailsAndSetOutput();
|
||||||
|
|
||||||
expect(setOutputSpy).toHaveBeenCalledWith('node-version', obj['node']);
|
expect(setOutputSpy).toHaveBeenCalledWith('node-version', obj['node']);
|
||||||
|
|||||||
@@ -248,9 +248,6 @@ describe('setup-node', () => {
|
|||||||
const toolPath = path.normalize('/cache/node/12.16.2/x64');
|
const toolPath = path.normalize('/cache/node/12.16.2/x64');
|
||||||
exSpy.mockImplementation(async () => '/some/other/temp/path');
|
exSpy.mockImplementation(async () => '/some/other/temp/path');
|
||||||
cacheSpy.mockImplementation(async () => toolPath);
|
cacheSpy.mockImplementation(async () => toolPath);
|
||||||
whichSpy.mockImplementation(cmd => {
|
|
||||||
return `some/${cmd}/path`;
|
|
||||||
});
|
|
||||||
|
|
||||||
await main.run();
|
await main.run();
|
||||||
|
|
||||||
|
|||||||
4
dist/cache-save/index.js
vendored
4
dist/cache-save/index.js
vendored
@@ -83336,7 +83336,6 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|||||||
exports.unique = exports.printEnvDetailsAndSetOutput = exports.getNodeVersionFromFile = void 0;
|
exports.unique = exports.printEnvDetailsAndSetOutput = exports.getNodeVersionFromFile = void 0;
|
||||||
const core = __importStar(__nccwpck_require__(2186));
|
const core = __importStar(__nccwpck_require__(2186));
|
||||||
const exec = __importStar(__nccwpck_require__(1514));
|
const exec = __importStar(__nccwpck_require__(1514));
|
||||||
const io = __importStar(__nccwpck_require__(7436));
|
|
||||||
const fs_1 = __importDefault(__nccwpck_require__(7147));
|
const fs_1 = __importDefault(__nccwpck_require__(7147));
|
||||||
const path_1 = __importDefault(__nccwpck_require__(1017));
|
const path_1 = __importDefault(__nccwpck_require__(1017));
|
||||||
function getNodeVersionFromFile(versionFilePath) {
|
function getNodeVersionFromFile(versionFilePath) {
|
||||||
@@ -83388,8 +83387,7 @@ function printEnvDetailsAndSetOutput() {
|
|||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
core.startGroup('Environment details');
|
core.startGroup('Environment details');
|
||||||
const promises = ['node', 'npm', 'yarn'].map((tool) => __awaiter(this, void 0, void 0, function* () {
|
const promises = ['node', 'npm', 'yarn'].map((tool) => __awaiter(this, void 0, void 0, function* () {
|
||||||
const pathTool = yield io.which(tool, false);
|
const output = yield getToolVersion(tool, ['--version']);
|
||||||
const output = pathTool ? yield getToolVersion(tool, ['--version']) : '';
|
|
||||||
return { tool, output };
|
return { tool, output };
|
||||||
}));
|
}));
|
||||||
const tools = yield Promise.all(promises);
|
const tools = yield Promise.all(promises);
|
||||||
|
|||||||
36
dist/setup/index.js
vendored
36
dist/setup/index.js
vendored
@@ -93110,11 +93110,7 @@ class BaseDistribution {
|
|||||||
const fileName = this.osPlat == 'win32'
|
const fileName = this.osPlat == 'win32'
|
||||||
? `node-v${version}-win-${osArch}`
|
? `node-v${version}-win-${osArch}`
|
||||||
: `node-v${version}-${this.osPlat}-${osArch}`;
|
: `node-v${version}-${this.osPlat}-${osArch}`;
|
||||||
const urlFileName = this.osPlat == 'win32'
|
const urlFileName = this.osPlat == 'win32' ? `${fileName}.7z` : `${fileName}.tar.gz`;
|
||||||
? this.nodeInfo.arch === 'arm64'
|
|
||||||
? `${fileName}.zip`
|
|
||||||
: `${fileName}.7z`
|
|
||||||
: `${fileName}.tar.gz`;
|
|
||||||
const initialUrl = this.getDistributionUrl();
|
const initialUrl = this.getDistributionUrl();
|
||||||
const url = `${initialUrl}/v${version}/${urlFileName}`;
|
const url = `${initialUrl}/v${version}/${urlFileName}`;
|
||||||
return {
|
return {
|
||||||
@@ -93198,23 +93194,10 @@ class BaseDistribution {
|
|||||||
let extPath;
|
let extPath;
|
||||||
info = info || {}; // satisfy compiler, never null when reaches here
|
info = info || {}; // satisfy compiler, never null when reaches here
|
||||||
if (this.osPlat == 'win32') {
|
if (this.osPlat == 'win32') {
|
||||||
const extension = this.nodeInfo.arch === 'arm64' ? '.zip' : '.7z';
|
const _7zPath = path.join(__dirname, '../..', 'externals', '7zr.exe');
|
||||||
// Rename archive to add extension because after downloading
|
extPath = yield tc.extract7z(downloadPath, undefined, _7zPath);
|
||||||
// archive does not contain extension type and it leads to some issues
|
|
||||||
// on Windows runners without PowerShell Core.
|
|
||||||
//
|
|
||||||
// For default PowerShell Windows it should contain extension type to unpack it.
|
|
||||||
if (extension === '.zip') {
|
|
||||||
const renamedArchive = `${downloadPath}.zip`;
|
|
||||||
fs_1.default.renameSync(downloadPath, renamedArchive);
|
|
||||||
extPath = yield tc.extractZip(renamedArchive);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
const _7zPath = path.join(__dirname, '../..', 'externals', '7zr.exe');
|
|
||||||
extPath = yield tc.extract7z(downloadPath, undefined, _7zPath);
|
|
||||||
}
|
|
||||||
// 7z extracts to folder matching file name
|
// 7z extracts to folder matching file name
|
||||||
const nestedPath = path.join(extPath, path.basename(info.fileName, extension));
|
const nestedPath = path.join(extPath, path.basename(info.fileName, '.7z'));
|
||||||
if (fs_1.default.existsSync(nestedPath)) {
|
if (fs_1.default.existsSync(nestedPath)) {
|
||||||
extPath = nestedPath;
|
extPath = nestedPath;
|
||||||
}
|
}
|
||||||
@@ -93246,12 +93229,7 @@ class BaseDistribution {
|
|||||||
dataFileName = `osx-${osArch}-tar`;
|
dataFileName = `osx-${osArch}-tar`;
|
||||||
break;
|
break;
|
||||||
case 'win32':
|
case 'win32':
|
||||||
if (this.nodeInfo.arch === 'arm64') {
|
dataFileName = `win-${osArch}-exe`;
|
||||||
dataFileName = `win-${osArch}-zip`;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
dataFileName = `win-${osArch}-exe`;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new Error(`Unexpected OS '${this.osPlat}'`);
|
throw new Error(`Unexpected OS '${this.osPlat}'`);
|
||||||
@@ -93805,7 +93783,6 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|||||||
exports.unique = exports.printEnvDetailsAndSetOutput = exports.getNodeVersionFromFile = void 0;
|
exports.unique = exports.printEnvDetailsAndSetOutput = exports.getNodeVersionFromFile = void 0;
|
||||||
const core = __importStar(__nccwpck_require__(2186));
|
const core = __importStar(__nccwpck_require__(2186));
|
||||||
const exec = __importStar(__nccwpck_require__(1514));
|
const exec = __importStar(__nccwpck_require__(1514));
|
||||||
const io = __importStar(__nccwpck_require__(7436));
|
|
||||||
const fs_1 = __importDefault(__nccwpck_require__(7147));
|
const fs_1 = __importDefault(__nccwpck_require__(7147));
|
||||||
const path_1 = __importDefault(__nccwpck_require__(1017));
|
const path_1 = __importDefault(__nccwpck_require__(1017));
|
||||||
function getNodeVersionFromFile(versionFilePath) {
|
function getNodeVersionFromFile(versionFilePath) {
|
||||||
@@ -93857,8 +93834,7 @@ function printEnvDetailsAndSetOutput() {
|
|||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
core.startGroup('Environment details');
|
core.startGroup('Environment details');
|
||||||
const promises = ['node', 'npm', 'yarn'].map((tool) => __awaiter(this, void 0, void 0, function* () {
|
const promises = ['node', 'npm', 'yarn'].map((tool) => __awaiter(this, void 0, void 0, function* () {
|
||||||
const pathTool = yield io.which(tool, false);
|
const output = yield getToolVersion(tool, ['--version']);
|
||||||
const output = pathTool ? yield getToolVersion(tool, ['--version']) : '';
|
|
||||||
return { tool, output };
|
return { tool, output };
|
||||||
}));
|
}));
|
||||||
const tools = yield Promise.all(promises);
|
const tools = yield Promise.all(promises);
|
||||||
|
|||||||
@@ -112,11 +112,7 @@ export default abstract class BaseDistribution {
|
|||||||
? `node-v${version}-win-${osArch}`
|
? `node-v${version}-win-${osArch}`
|
||||||
: `node-v${version}-${this.osPlat}-${osArch}`;
|
: `node-v${version}-${this.osPlat}-${osArch}`;
|
||||||
const urlFileName: string =
|
const urlFileName: string =
|
||||||
this.osPlat == 'win32'
|
this.osPlat == 'win32' ? `${fileName}.7z` : `${fileName}.tar.gz`;
|
||||||
? this.nodeInfo.arch === 'arm64'
|
|
||||||
? `${fileName}.zip`
|
|
||||||
: `${fileName}.7z`
|
|
||||||
: `${fileName}.tar.gz`;
|
|
||||||
const initialUrl = this.getDistributionUrl();
|
const initialUrl = this.getDistributionUrl();
|
||||||
const url = `${initialUrl}/v${version}/${urlFileName}`;
|
const url = `${initialUrl}/v${version}/${urlFileName}`;
|
||||||
|
|
||||||
@@ -219,24 +215,12 @@ export default abstract class BaseDistribution {
|
|||||||
let extPath: string;
|
let extPath: string;
|
||||||
info = info || ({} as INodeVersionInfo); // satisfy compiler, never null when reaches here
|
info = info || ({} as INodeVersionInfo); // satisfy compiler, never null when reaches here
|
||||||
if (this.osPlat == 'win32') {
|
if (this.osPlat == 'win32') {
|
||||||
const extension = this.nodeInfo.arch === 'arm64' ? '.zip' : '.7z';
|
const _7zPath = path.join(__dirname, '../..', 'externals', '7zr.exe');
|
||||||
// Rename archive to add extension because after downloading
|
extPath = await tc.extract7z(downloadPath, undefined, _7zPath);
|
||||||
// archive does not contain extension type and it leads to some issues
|
|
||||||
// on Windows runners without PowerShell Core.
|
|
||||||
//
|
|
||||||
// For default PowerShell Windows it should contain extension type to unpack it.
|
|
||||||
if (extension === '.zip') {
|
|
||||||
const renamedArchive = `${downloadPath}.zip`;
|
|
||||||
fs.renameSync(downloadPath, renamedArchive);
|
|
||||||
extPath = await tc.extractZip(renamedArchive);
|
|
||||||
} else {
|
|
||||||
const _7zPath = path.join(__dirname, '../..', 'externals', '7zr.exe');
|
|
||||||
extPath = await tc.extract7z(downloadPath, undefined, _7zPath);
|
|
||||||
}
|
|
||||||
// 7z extracts to folder matching file name
|
// 7z extracts to folder matching file name
|
||||||
const nestedPath = path.join(
|
const nestedPath = path.join(
|
||||||
extPath,
|
extPath,
|
||||||
path.basename(info.fileName, extension)
|
path.basename(info.fileName, '.7z')
|
||||||
);
|
);
|
||||||
if (fs.existsSync(nestedPath)) {
|
if (fs.existsSync(nestedPath)) {
|
||||||
extPath = nestedPath;
|
extPath = nestedPath;
|
||||||
@@ -276,11 +260,7 @@ export default abstract class BaseDistribution {
|
|||||||
dataFileName = `osx-${osArch}-tar`;
|
dataFileName = `osx-${osArch}-tar`;
|
||||||
break;
|
break;
|
||||||
case 'win32':
|
case 'win32':
|
||||||
if (this.nodeInfo.arch === 'arm64') {
|
dataFileName = `win-${osArch}-exe`;
|
||||||
dataFileName = `win-${osArch}-zip`;
|
|
||||||
} else {
|
|
||||||
dataFileName = `win-${osArch}-exe`;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new Error(`Unexpected OS '${this.osPlat}'`);
|
throw new Error(`Unexpected OS '${this.osPlat}'`);
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
import * as core from '@actions/core';
|
import * as core from '@actions/core';
|
||||||
import * as exec from '@actions/exec';
|
import * as exec from '@actions/exec';
|
||||||
import * as io from '@actions/io';
|
|
||||||
|
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
@@ -62,9 +61,9 @@ export function getNodeVersionFromFile(versionFilePath: string): string | null {
|
|||||||
|
|
||||||
export async function printEnvDetailsAndSetOutput() {
|
export async function printEnvDetailsAndSetOutput() {
|
||||||
core.startGroup('Environment details');
|
core.startGroup('Environment details');
|
||||||
|
|
||||||
const promises = ['node', 'npm', 'yarn'].map(async tool => {
|
const promises = ['node', 'npm', 'yarn'].map(async tool => {
|
||||||
const pathTool = await io.which(tool, false);
|
const output = await getToolVersion(tool, ['--version']);
|
||||||
const output = pathTool ? await getToolVersion(tool, ['--version']) : '';
|
|
||||||
|
|
||||||
return {tool, output};
|
return {tool, output};
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user