Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix 55 #69

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 44 additions & 4 deletions invoke-pwsh.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,54 @@

const core = require('@actions/core');
const exec = require('@actions/exec');
const which = require('which');
const os = require('os');

async function run() {
try {
// Check if pwsh is available
let pwshPath = which.sync('pwsh', { nothrow: true });
if (!pwshPath) {
// Check if the OS is Ubuntu
if (os.platform() === 'linux' && os.release().toLowerCase().includes('ubuntu')) {
await exec.exec('sudo apt-get update && sudo apt-get install -y powershell');
pwshPath = which.sync('pwsh', { nothrow: true });
if (!pwshPath) {
throw new Error('PowerShell (pwsh) installation failed on Ubuntu.');
}
}
else if (os.platform() === 'darwin') {
await exec.exec('brew install --cask powershell');
pwshPath = which.sync('pwsh', { nothrow: true });
if (!pwshPath) {
throw new Error('PowerShell (pwsh) installation failed on macOS.');
}
}
else if (os.platform() === 'win32') {
// if choco is found in PATH, install pwsh using choco
let chocoPath = which.sync('choco', { nothrow: true });
if (chocoPath) {
await exec.exec('choco install powershell -y');
}
else {
// if choco is not found, download and install pwsh
let wingetPath = which.sync('winget', { nothrow: true });
if (wingetPath) {
await exec.exec('winget install --id Microsoft.PowerShell --source winget');
}
}
}
else
{
throw new Error('PowerShell (pwsh) not found.');
}
}

const pwshFolder = __dirname.replace(/[/\\]_init$/, '');
const pwshScript = `${pwshFolder}/action.ps1`
await exec.exec('pwsh', [ '-f', pwshScript ]);
const pwshScript = `${pwshFolder}/action.ps1`;
await exec.exec('pwsh', ['-f', pwshScript]);
} catch (error) {
core.setFailed(error.message);
}
}
run();

run();
Loading