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

Add non-cuda-sub-pckages action argument #250

Merged
merged 2 commits into from Jul 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions .github/workflows/CI.yml
Expand Up @@ -20,7 +20,8 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [windows-2022, windows-2019, ubuntu-22.04, ubuntu-20.04, ubuntu-18.04]
os:
[windows-2022, windows-2019, ubuntu-22.04, ubuntu-20.04, ubuntu-18.04]
method: [local, network]
runs-on: ${{ matrix.os }}

Expand Down Expand Up @@ -66,12 +67,13 @@ jobs:
with:
method: ${{matrix.method}}

- name: Run the action on this runner with nvcc subpackage only (Linux)
- name: Run the action on this runner with nvcc and libcublas subpackages (Linux)
if: runner.os == 'Linux' && matrix.method == 'network'
uses: ./
with:
method: ${{matrix.method}}
sub-packages: '["nvcc"]'
non-cuda-sub-packages: '["libcublas"]'

- name: Run the action on this runner with nvcc subpackage only (Windows)
if: runner.os == 'Windows'
Expand Down
4 changes: 4 additions & 0 deletions action.yml
Expand Up @@ -10,6 +10,10 @@ inputs:
description: 'Only installs specified subpackages, must be in the form of a JSON array. For example, if you only want to install nvcc and visual studio integration: ["nvcc", "visual_studio_integration"] double quotes required! Note that if you want to use this on Linux, ''network'' method MUST be used.'
required: false
default: '[]'
non-cuda-sub-packages:
description: 'Only installs specified subpackages that do not have the cuda prefix, must be in the form of a JSON array. For example, if you only want to install libcublas and libcufft: ["libcublas", "libcufft"] double quotes required! Note that this only works with ''network'' method on only on Linux.'
required: false
default: '[]'
method:
description: "Installation method, can be either 'local' or 'network'. 'local' downloads the entire installer with all packages and runs that (you can still only install certain packages with sub-packages on Windows). 'network' downloads a smaller executable which only downloads necessary packages which you can define in subPackages"
required: false
Expand Down
90 changes: 75 additions & 15 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

13 changes: 10 additions & 3 deletions src/apt-installer.ts
Expand Up @@ -46,7 +46,8 @@ export async function aptSetup(version: SemVer): Promise<void> {

export async function aptInstall(
version: SemVer,
subPackages: string[]
subPackages: string[],
nonCudaSubPackages: string[]
): Promise<number> {
const osType = await getOs()
if (osType !== OSType.linux) {
Expand All @@ -61,9 +62,15 @@ export async function aptInstall(
return await exec(`sudo apt-get -y install`, [packageName])
} else {
// Only install specified packages
const versionedSubPackages = subPackages.map(
subPackage => `cuda-${subPackage}-${version.major}-${version.minor}`
const prefixedSubPackages = subPackages.map(
subPackage => `cuda-${subPackage}`
)
const versionedSubPackages = prefixedSubPackages
.concat(nonCudaSubPackages)
.map(
nonCudaSubPackage =>
`${nonCudaSubPackage}-${version.major}-${version.minor}`
)
core.debug(`Only install subpackages: ${versionedSubPackages}`)
return await exec(`sudo apt-get -y install`, versionedSubPackages)
}
Expand Down
34 changes: 22 additions & 12 deletions src/main.ts
Expand Up @@ -6,13 +6,18 @@ import {download} from './downloader'
import {getVersion} from './version'
import {install} from './installer'
import {updatePath} from './update-path'
import {parsePackages} from './parser'

async function run(): Promise<void> {
try {
const cuda: string = core.getInput('cuda')
core.debug(`Desired cuda version: ${cuda}`)
const subPackages: string = core.getInput('sub-packages')
core.debug(`Desired subPackes: ${subPackages}`)
const subPackagesArgName = 'sub-packages'
const subPackages: string = core.getInput(subPackagesArgName)
core.debug(`Desired subPackages: ${subPackages}`)
const nonCudaSubPackagesArgName = 'non-cuda-sub-packages'
const nonCudaSubPackages: string = core.getInput(nonCudaSubPackagesArgName)
core.debug(`Desired nonCudasubPackages: ${nonCudaSubPackages}`)
const methodString: string = core.getInput('method')
core.debug(`Desired method: ${methodString}`)
const linuxLocalArgs: string = core.getInput('linux-local-args')
Expand All @@ -21,15 +26,16 @@ async function run(): Promise<void> {
core.debug(`Desired GitHub cache usage: ${useGitHubCache}`)

// Parse subPackages array
let subPackagesArray: string[] = []
try {
subPackagesArray = JSON.parse(subPackages)
// TODO verify that elements are valid package names (nvcc, etc.)
} catch (error) {
const errString = `Error parsing input 'sub-packages' to a JSON string array: ${subPackages}`
core.debug(errString)
throw new Error(errString)
}
const subPackagesArray: string[] = await parsePackages(
subPackages,
subPackagesArgName
)

// Parse nonCudaSubPackages array
const nonCudaSubPackagesArray: string[] = await parsePackages(
nonCudaSubPackages,
nonCudaSubPackagesArgName
)

// Parse method
const methodParsed: Method = parseMethod(methodString)
Expand Down Expand Up @@ -66,7 +72,11 @@ async function run(): Promise<void> {
// Setup aptitude repos
await aptSetup(version)
// Install packages
const installResult = await aptInstall(version, subPackagesArray)
const installResult = await aptInstall(
version,
subPackagesArray,
nonCudaSubPackagesArray
)
core.debug(`Install result: ${installResult}`)
} else {
// Download
Expand Down
16 changes: 16 additions & 0 deletions src/parser.ts
@@ -0,0 +1,16 @@
import * as core from '@actions/core'

export async function parsePackages(
subPackages: string,
parameterName: string
): Promise<string[]> {
let subPackagesArray: string[] = []
try {
subPackagesArray = JSON.parse(subPackages)
} catch (error) {
const errString = `Error parsing input '${parameterName}' to a JSON string array: ${subPackages}`
core.debug(errString)
throw new Error(errString)
}
return subPackagesArray
}