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

Allow explicitly specifying openssl-version (on self-hosted environments the openssl command may not be on $PATH) #98

Merged
merged 2 commits into from
Aug 30, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ inputs:
yarn-version:
description: 'Version Spec of the yarn version to use. Examples: 1.6.x, 10.15.1, >=10.15.0'
default: ''
openssl-version:
description: 'Version Spec of the openssl version to use. Examples: 1.0, 1.1'
default: ''
registry-url:
description: 'Optional registry to set up for auth. Will set the registry in a project level .npmrc file, and set up auth to read in from env.NODE_AUTH_TOKEN'
scope:
Expand Down
3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ async function run(): Promise<void> {
try {
const authToken = core.getInput('token', { required: false });
const voltaVersion = core.getInput('volta-version', { required: false });
const openSSLVersion = core.getInput('openssl-version', { required: false });

await installer.getVolta(voltaVersion, authToken);
await installer.getVolta(voltaVersion, authToken, openSSLVersion);

const hasPackageJSON = await findUp('package.json');
const nodeVersion = core.getInput('node-version', { required: false });
Expand Down
10 changes: 10 additions & 0 deletions src/installer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ describe('buildDownloadUrl', () => {
);
});

test('linux with openssl-version input', async function () {
expect(await buildDownloadUrl('linux', '0.6.4', '1.0')).toMatchInlineSnapshot(
`"https://github.com/volta-cli/volta/releases/download/v0.6.4/volta-0.6.4-linux-openssl-1.0.tar.gz"`
);

expect(await buildDownloadUrl('linux', '0.6.4', '1.1')).toMatchInlineSnapshot(
`"https://github.com/volta-cli/volta/releases/download/v0.6.4/volta-0.6.4-linux-openssl-1.1.tar.gz"`
);
});

test('win32', async function () {
expect(await buildDownloadUrl('win32', '0.7.2')).toMatchInlineSnapshot(
`"https://github.com/volta-cli/volta/releases/download/v0.7.2/volta-0.7.2-windows-x86_64.msi"`
Expand Down
44 changes: 29 additions & 15 deletions src/installer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,22 +65,28 @@ async function execOpenSSLVersion() {
}

async function getOpenSSLVersion(version = ''): Promise<string> {
if (version === '') {
version = await execOpenSSLVersion();
}
const specificVersionViaInput = /^\d{1,3}\.\d{1,3}$/.test(version);

// typical version string looks like 'OpenSSL 1.0.1e-fips 11 Feb 2013'
const openSSLVersionPattern = /^([^\s]*)\s([0-9]+\.[0-9]+)/;
const match = openSSLVersionPattern.exec(version);
if (!specificVersionViaInput) {
scalvert marked this conversation as resolved.
Show resolved Hide resolved
if (version === '') {
version = await execOpenSSLVersion();
}

if (match === null) {
throw new Error(
`No version of OpenSSL was found. @volta-cli/action requires a valid version of OpenSSL. ('openssl version' output: ${version})`
);
// typical version string looks like 'OpenSSL 1.0.1e-fips 11 Feb 2013'
const openSSLVersionPattern = /^([^\s]*)\s([0-9]+\.[0-9]+)/;
const match = openSSLVersionPattern.exec(version);

if (match === null) {
throw new Error(
`No version of OpenSSL was found. @volta-cli/action requires a valid version of OpenSSL. ('openssl version' output: ${version})`
);
}

version = match[2];
}

// should return in openssl-1.1 format
return `openssl-${match[2]}`;
return `openssl-${version}`;
}

/*
Expand Down Expand Up @@ -131,14 +137,18 @@ export async function buildLayout(voltaHome: string): Promise<void> {
await setupShims(voltaHome);
}

async function acquireVolta(version: string, authToken: string): Promise<string> {
async function acquireVolta(
version: string,
authToken: string,
openSSLVersion: string
): Promise<string> {
//
// Download - a tool installer intimately knows how to get the tool (and construct urls)
//

core.info(`downloading volta@${version}`);

const downloadUrl = await buildDownloadUrl(os.platform(), version);
const downloadUrl = await buildDownloadUrl(os.platform(), version, openSSLVersion);

core.debug(`downloading from \`${downloadUrl}\``);
const downloadPath = await tc.downloadTool(downloadUrl, undefined, authToken);
Expand Down Expand Up @@ -252,14 +262,18 @@ export async function getVoltaVersion(versionSpec: string): Promise<string> {
return version;
}

export async function getVolta(versionSpec: string, authToken: string): Promise<void> {
export async function getVolta(
versionSpec: string,
authToken: string,
openSSLVersion: string
): Promise<void> {
const version = await getVoltaVersion(versionSpec);

let voltaHome = tc.find('volta', version);

if (voltaHome === '') {
// download, extract, cache
const toolRoot = await acquireVolta(version, authToken);
const toolRoot = await acquireVolta(version, authToken, openSSLVersion);

await setupVolta(version, toolRoot);

Expand Down