Skip to content

Commit f8549fc

Browse files
author
Robert Jackson
authored
Merge pull request #102 from scalvert/variant-input
Replace `openssl-version` configuration with `variant`
2 parents e21c9a3 + ef2bf4b commit f8549fc

File tree

5 files changed

+120
-97
lines changed

5 files changed

+120
-97
lines changed

README.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ This action installs [volta](https://volta.sh) by:
1818
| node-version | Version Spec of the node version to use. Examples: 10.6.x, 10.15.1, >=10.15.0 | `false` | |
1919
| npm-version | Version Spec of the npm version to use. Examples: 7.5.x, 7.5.3, >=7.5.3 | `false` | |
2020
| yarn-version | Version Spec of the yarn version to use. Examples: 1.6.x, 10.15.1, >=10.15.0 | `false` | |
21-
| openssl-version | Version Spec of the openssl version to use. Examples: 1.0, 1.1 | `false` | |
21+
| variant | Specific variant to install. Example: providing the variant "linux-openssl-rhel", which will target installing the volta-${version}-linux-openssl-rhel.tar.gz tarball | `false` | |
2222
| registry-url | 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 | `false` | |
2323
| scope | Optional scope for authenticating against scoped registries. Will fall back to the repository owner when using the GitHub Packages registry (https://npm.pkg.github.com/). | `false` | |
2424
| token | Used to avoid low rate limiting for cached tool downloads. Since there's a default, this is typically not supplied by the user. | `false` | ${{ github.token }} |
@@ -91,6 +91,21 @@ steps:
9191
- run: npm test
9292
```
9393

94+
In some cases, you may know the particular variant of the installer that you want to use for Volta. You can specify the `variant` input to the action to use a specific installer:
95+
96+
```yaml
97+
steps:
98+
- uses: actions/checkout@v3
99+
- uses: volta-cli/action@v3
100+
with:
101+
variant: 'linux-openssl-rhel'
102+
103+
- run: yarn install
104+
- run: yarn test
105+
```
106+
107+
The `variant` fragment corresponds to a portion of the installer filename, and can be found in the [Volta Releases](https://github.com/volta-cli/action/releases) page.
108+
94109
## License
95110

96111
The scripts and documentation in this project are released under the [MIT License](LICENSE)

action.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ inputs:
1414
yarn-version:
1515
description: 'Version Spec of the yarn version to use. Examples: 1.6.x, 10.15.1, >=10.15.0'
1616
default: ''
17-
openssl-version:
18-
description: 'Version Spec of the openssl version to use. Examples: 1.0, 1.1'
17+
variant:
18+
description: 'Specific variant to install. Example: providing the variant "linux-openssl-rhel", which will target installing the volta-${version}-linux-openssl-rhel.tar.gz tarball'
1919
default: ''
2020
registry-url:
2121
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'

src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ async function run(): Promise<void> {
88
try {
99
const authToken = core.getInput('token', { required: false });
1010
const voltaVersion = core.getInput('volta-version', { required: false });
11-
const openSSLVersion = core.getInput('openssl-version', { required: false });
11+
const variant = core.getInput('variant', { required: false });
1212

13-
await installer.getVolta(voltaVersion, authToken, openSSLVersion);
13+
await installer.getVolta({ versionSpec: voltaVersion, authToken, variant });
1414

1515
const hasPackageJSON = await findUp('package.json');
1616
const nodeVersion = core.getInput('node-version', { required: false });

src/installer.test.ts

Lines changed: 48 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { buildLayout, buildDownloadUrl, getVoltaVersion } from './installer';
1+
import { buildLayout, buildDownloadUrl, getVoltaVersion, getOpenSSLVersion } from './installer';
22
import { createTempDir } from 'broccoli-test-helper';
33
import nock from 'nock';
44

@@ -11,25 +11,21 @@ describe('buildDownloadUrl', () => {
1111

1212
test('linux', async function () {
1313
expect(
14-
await buildDownloadUrl('linux', '0.6.4', 'OpenSSL 1.0.1e-fips 11 Feb 2013')
14+
await buildDownloadUrl('linux', '0.6.4', '', 'OpenSSL 1.0.1e-fips 11 Feb 2013')
1515
).toMatchInlineSnapshot(
1616
`"https://github.com/volta-cli/volta/releases/download/v0.6.4/volta-0.6.4-linux-openssl-1.0.tar.gz"`
1717
);
1818

1919
expect(
20-
await buildDownloadUrl('linux', '0.6.4', 'OpenSSL 1.1.1e-fips 11 Sep 2018')
20+
await buildDownloadUrl('linux', '0.6.4', '', 'OpenSSL 1.1.1e-fips 11 Sep 2018')
2121
).toMatchInlineSnapshot(
2222
`"https://github.com/volta-cli/volta/releases/download/v0.6.4/volta-0.6.4-linux-openssl-1.1.tar.gz"`
2323
);
2424
});
2525

26-
test('linux with openssl-version input', async function () {
27-
expect(await buildDownloadUrl('linux', '0.6.4', '1.0')).toMatchInlineSnapshot(
28-
`"https://github.com/volta-cli/volta/releases/download/v0.6.4/volta-0.6.4-linux-openssl-1.0.tar.gz"`
29-
);
30-
31-
expect(await buildDownloadUrl('linux', '0.6.4', '1.1')).toMatchInlineSnapshot(
32-
`"https://github.com/volta-cli/volta/releases/download/v0.6.4/volta-0.6.4-linux-openssl-1.1.tar.gz"`
26+
test('linux with variant input', async function () {
27+
expect(await buildDownloadUrl('linux', '0.6.4', 'linux-openssl-rhel')).toMatchInlineSnapshot(
28+
`"https://github.com/volta-cli/volta/releases/download/v0.6.4/volta-0.6.4-linux-openssl-rhel.tar.gz"`
3329
);
3430
});
3531

@@ -46,6 +42,20 @@ describe('buildDownloadUrl', () => {
4642
});
4743
});
4844

45+
describe('getOpenSSLVersion', () => {
46+
test('1.0', async function () {
47+
expect(await getOpenSSLVersion('OpenSSL 1.0.1e-fips 11 Feb 2013')).toMatchInlineSnapshot(
48+
`"openssl-1.0"`
49+
);
50+
});
51+
52+
test('1.1', async function () {
53+
expect(await getOpenSSLVersion('OpenSSL 1.1.1e-fips 11 Sep 2018')).toMatchInlineSnapshot(
54+
`"openssl-1.1"`
55+
);
56+
});
57+
});
58+
4959
describe('buildLayout', () => {
5060
test('creates the rough folder structure', async () => {
5161
const tmpdir = await createTempDir();
@@ -59,34 +69,34 @@ describe('buildLayout', () => {
5969
await buildLayout(tmpdir.path());
6070

6171
expect(tmpdir.read()).toMatchInlineSnapshot(`
62-
Object {
63-
"bin": Object {
64-
"node": "shim-file-here",
65-
"npm": "shim-file-here",
66-
"npx": "shim-file-here",
67-
"shim": "shim-file-here",
68-
"yarn": "shim-file-here",
69-
},
70-
"cache": Object {
71-
"node": Object {},
72-
},
73-
"log": Object {},
74-
"tmp": Object {},
75-
"tools": Object {
76-
"image": Object {
77-
"node": Object {},
78-
"packages": Object {},
79-
"yarn": Object {},
80-
},
81-
"inventory": Object {
82-
"node": Object {},
83-
"packages": Object {},
84-
"yarn": Object {},
85-
},
86-
"user": Object {},
87-
},
88-
}
89-
`);
72+
Object {
73+
"bin": Object {
74+
"node": "shim-file-here",
75+
"npm": "shim-file-here",
76+
"npx": "shim-file-here",
77+
"shim": "shim-file-here",
78+
"yarn": "shim-file-here",
79+
},
80+
"cache": Object {
81+
"node": Object {},
82+
},
83+
"log": Object {},
84+
"tmp": Object {},
85+
"tools": Object {
86+
"image": Object {
87+
"node": Object {},
88+
"packages": Object {},
89+
"yarn": Object {},
90+
},
91+
"inventory": Object {
92+
"node": Object {},
93+
"packages": Object {},
94+
"yarn": Object {},
95+
},
96+
"user": Object {},
97+
},
98+
}
99+
`);
90100
});
91101
});
92102

src/installer.ts

Lines changed: 52 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ import * as semver from 'semver';
1010
import * as fs from 'fs';
1111
import { v4 as uuidV4 } from 'uuid';
1212

13+
type VoltaInstallOptions = {
14+
versionSpec: string;
15+
authToken: string;
16+
variant: string;
17+
};
18+
1319
async function getLatestVolta(authToken: string): Promise<string> {
1420
const url = 'https://api.github.com/repos/volta-cli/volta/releases/latest';
1521

@@ -40,53 +46,36 @@ function voltaVersionHasSetup(version: string): boolean {
4046
export async function buildDownloadUrl(
4147
platform: string,
4248
version: string,
43-
openSSLVersion = ''
49+
variant = '',
50+
openSSLVersionForTesting = ''
4451
): Promise<string> {
45-
let fileName: string;
46-
switch (platform) {
47-
case 'darwin':
48-
fileName = `volta-${version}-macos.tar.gz`;
49-
break;
50-
case 'linux': {
51-
openSSLVersion = await getOpenSSLVersion(openSSLVersion);
52-
53-
fileName = `volta-${version}-linux-${openSSLVersion}.tar.gz`;
54-
break;
52+
let fileName = '';
53+
54+
if (variant) {
55+
fileName = `volta-${version}-${variant}.tar.gz`;
56+
} else {
57+
switch (platform) {
58+
case 'darwin':
59+
fileName = `volta-${version}-macos.tar.gz`;
60+
break;
61+
case 'linux': {
62+
const openSSLVersion = await getOpenSSLVersion(openSSLVersionForTesting);
63+
64+
fileName = `volta-${version}-linux-${openSSLVersion}.tar.gz`;
65+
break;
66+
}
67+
case 'win32':
68+
fileName = `volta-${version}-windows-x86_64.msi`;
69+
break;
70+
default:
71+
throw new Error(`your platform ${platform} is not yet supported`);
5572
}
56-
case 'win32':
57-
fileName = `volta-${version}-windows-x86_64.msi`;
58-
break;
59-
default:
60-
throw new Error(`your platform ${platform} is not yet supported`);
6173
}
6274

6375
return `https://github.com/volta-cli/volta/releases/download/v${version}/${fileName}`;
6476
}
6577

66-
async function execOpenSSLVersion() {
67-
let output = '';
68-
const options: ExecOptions = {};
69-
options.listeners = {
70-
stdout: (data: Buffer) => {
71-
output += data.toString();
72-
},
73-
stderr: (data: Buffer) => {
74-
output += data.toString();
75-
},
76-
};
77-
78-
await exec('openssl version', [], options);
79-
80-
return output;
81-
}
82-
83-
async function getOpenSSLVersion(version = ''): Promise<string> {
84-
const specificVersionViaInput = /^\d{1,3}\.\d{1,3}$/.test(version);
85-
86-
if (specificVersionViaInput) {
87-
return `openssl-${version}`;
88-
}
89-
78+
export async function getOpenSSLVersion(version = ''): Promise<string> {
9079
if (version === '') {
9180
version = await execOpenSSLVersion();
9281
}
@@ -107,6 +96,23 @@ async function getOpenSSLVersion(version = ''): Promise<string> {
10796
return `openssl-${version}`;
10897
}
10998

99+
async function execOpenSSLVersion() {
100+
let output = '';
101+
const options: ExecOptions = {};
102+
options.listeners = {
103+
stdout: (data: Buffer) => {
104+
output += data.toString();
105+
},
106+
stderr: (data: Buffer) => {
107+
output += data.toString();
108+
},
109+
};
110+
111+
await exec('openssl version', [], options);
112+
113+
return output;
114+
}
115+
110116
/*
111117
* Used to setup a specific shim when running volta < 0.7
112118
*/
@@ -155,21 +161,17 @@ export async function buildLayout(voltaHome: string): Promise<void> {
155161
await setupShims(voltaHome);
156162
}
157163

158-
async function acquireVolta(
159-
version: string,
160-
authToken: string,
161-
openSSLVersion: string
162-
): Promise<string> {
164+
async function acquireVolta(version: string, options: VoltaInstallOptions): Promise<string> {
163165
//
164166
// Download - a tool installer intimately knows how to get the tool (and construct urls)
165167
//
166168

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

169-
const downloadUrl = await buildDownloadUrl(os.platform(), version, openSSLVersion);
171+
const downloadUrl = await buildDownloadUrl(os.platform(), version, options.variant);
170172

171173
core.debug(`downloading from \`${downloadUrl}\``);
172-
const downloadPath = await tc.downloadTool(downloadUrl, undefined, authToken);
174+
const downloadPath = await tc.downloadTool(downloadUrl, undefined, options.authToken);
173175

174176
const voltaHome = path.join(
175177
// `RUNNER_TEMP` is used by @actions/tool-cache
@@ -280,18 +282,14 @@ export async function getVoltaVersion(versionSpec: string, authToken: string): P
280282
return version;
281283
}
282284

283-
export async function getVolta(
284-
versionSpec: string,
285-
authToken: string,
286-
openSSLVersion: string
287-
): Promise<void> {
288-
const version = await getVoltaVersion(versionSpec, authToken);
285+
export async function getVolta(options: VoltaInstallOptions): Promise<void> {
286+
const version = await getVoltaVersion(options.versionSpec, options.authToken);
289287

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

292290
if (voltaHome === '') {
293291
// download, extract, cache
294-
const toolRoot = await acquireVolta(version, authToken, openSSLVersion);
292+
const toolRoot = await acquireVolta(version, options);
295293

296294
await setupVolta(version, toolRoot);
297295

0 commit comments

Comments
 (0)