Skip to content

Commit

Permalink
Don't prepend cuda- prefix to ubuntu package names
Browse files Browse the repository at this point in the history
- When writing this tool I noticed the ubuntu packages had the "cuda-"
  prefix.
- This is not the case for all packages, so let's add a new argument called
  "non-cuda-sub-packages", which behaves the same as "sub-packages",
  except that it only works for ubuntu network installs, and that it
  doesn't prefix the packages with "cuda-".
- Fixes #249.
  • Loading branch information
Jimver committed Jul 6, 2023
1 parent 6974ecc commit 3800432
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 17 deletions.
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
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
}

0 comments on commit 3800432

Please sign in to comment.