Skip to content

Commit

Permalink
Moved from curl to direct approach
Browse files Browse the repository at this point in the history
Installing the script and executing it
  • Loading branch information
AS1100K committed Oct 13, 2024
1 parent 612787e commit 27349f8
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 35 deletions.
50 changes: 37 additions & 13 deletions __tests__/toolchain_install.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,16 @@ describe('install_toolchain', () => {
'rustup-init.exe'
)

expect(mockedExec).toHaveBeenCalledWith(
'./rustup-init.exe -v --default-toolchain stable --profile minimal -y'
)

expect(mockedExec).toHaveBeenCalledWith('rm rustup-init.exe')
expect(mockedExec).toHaveBeenCalledWith('./rustup-init.exe', [
'-v',
'--default-toolchain',
'stable',
'--profile',
'minimal',
'-y'
])

expect(mockedExec).toHaveBeenCalledWith('rm ./rustup-init.exe')
})

test('should install Rust on Windows ia32', async () => {
Expand All @@ -65,19 +70,24 @@ describe('install_toolchain', () => {
'rustup-init.exe'
)

expect(mockedExec).toHaveBeenCalledWith(
'./rustup-init.exe -v --default-toolchain stable --profile minimal -y'
)
expect(mockedExec).toHaveBeenCalledWith('./rustup-init.exe', [
'-v',
'--default-toolchain',
'stable',
'--profile',
'minimal',
'-y'
])

expect(mockedExec).toHaveBeenCalledWith('rm rustup-init.exe')
expect(mockedExec).toHaveBeenCalledWith('rm ./rustup-init.exe')
})

test('should throw an error for unsupported architecture on Windows', async () => {
platform.isWindows = true
platform.arch = 'unsupported_arch'

await expect(install_toolchain(properties, platform)).rejects.toThrow(
"Unsupported Platform Architecture unsupported_arch. Supported Architecture are 'x64' and 'ia32' for windows OS."
"Unsupported Platform Architecture 'unsupported_arch'. Supported Architecture are 'x64' and 'ia32' for windows OS."
)

expect(mockedDownloadFile).not.toHaveBeenCalled()
Expand All @@ -89,10 +99,23 @@ describe('install_toolchain', () => {

await install_toolchain(properties, platform)

expect(mockedDownloadFile).not.toHaveBeenCalled()
expect(mockedExec).toHaveBeenCalledWith(
'curl --proto https --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -v --default-toolchain stable --profile minimal -y'
expect(mockedDownloadFile).toHaveBeenCalledWith(
new URL('https://sh.rustup.rs'),
'rustup.sh'
)

expect(mockedExec).toHaveBeenCalledWith('chmod a+x ./rustup.sh')

expect(mockedExec).toHaveBeenCalledWith('./rustup.sh', [
'-v',
'--default-toolchain',
'stable',
'--profile',
'minimal',
'-y'
])

expect(mockedExec).toHaveBeenCalledWith('rm ./rustup.sh')
})

test('should handle errors thrown by download_rust', async () => {
Expand All @@ -106,5 +129,6 @@ describe('install_toolchain', () => {
)

expect(mockedDownloadFile).toHaveBeenCalledTimes(1)
expect(mockedExec).not.toHaveBeenCalled()
})
})
2 changes: 1 addition & 1 deletion badges/coverage.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 16 additions & 7 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.

37 changes: 24 additions & 13 deletions src/toolchain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,23 +53,34 @@ async function download_rust(
)
} else {
throw new Error(
`Unsupported Platform Architecture ${platform.arch}. Supported Architecture are 'x64' and 'ia32' for windows OS.`
`Unsupported Platform Architecture '${platform.arch}'. Supported Architecture are 'x64' and 'ia32' for windows OS.`
)
}

// install rust via installer
await exec.exec(
`./rustup-init.exe -v --default-toolchain ${properties.rust_toolchain} --profile ${properties.profile} -y`
)

// uninstall the installer
await exec.exec('rm rustup-init.exe')
} else {
// Install installer via direct script and download rust
await exec.exec(
`curl --proto https --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -v --default-toolchain ${properties.rust_toolchain} --profile ${properties.profile} -y`
)
// Download rust installation script
await download_file(new URL('https://sh.rustup.rs'), 'rustup.sh')

// Give Execute Permission to script
await exec.exec('chmod a+x ./rustup.sh')
}

// Install rust
await exec.exec(
`${platform.isWindows ? './rustup-init.exe' : './rustup.sh'}`,
[
'-v',
'--default-toolchain',
properties.rust_toolchain,
'--profile',
properties.profile,
'-y'
]
)

// Uninstall script or installer
await exec.exec(
`rm ${platform.isWindows ? './rustup-init.exe' : './rustup.sh'}`
)
} catch (error) {
if (error instanceof Error) throw error
}
Expand Down

0 comments on commit 27349f8

Please sign in to comment.