Skip to content

Commit

Permalink
Fix: Action (#5)
Browse files Browse the repository at this point in the history
* Added `sync` CLI command

* Added delay of 1 second before running the installer

* Output `rustup --help` command
  • Loading branch information
AS1100K authored Oct 13, 2024
1 parent a118094 commit 1b2d7f6
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,4 @@ jobs:

- name: Print Output
id: output
run: echo "${{ steps.test-action.outputs.installation }}"
run: rustup --help
4 changes: 3 additions & 1 deletion __tests__/toolchain_install.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,9 @@ describe('install_toolchain', () => {
'rustup.sh'
)

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

expect(mockedExec).toHaveBeenCalledWith('sync')

expect(mockedExec).toHaveBeenCalledWith('./rustup.sh', [
'-v',
Expand Down
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.
18 changes: 17 additions & 1 deletion 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.

10 changes: 8 additions & 2 deletions src/toolchain.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as exec from '@actions/exec'
import { Platform, Properties } from './types'
import { download_file } from './utils'
import { delay, download_file } from './utils'

/**
* Installs specified Rust Toolchain
Expand Down Expand Up @@ -61,9 +61,15 @@ async function download_rust(
await download_file(new URL('https://sh.rustup.rs'), 'rustup.sh')

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

// Ensure the file system is synced
await exec.exec('sync')
}

// Sleep for 1 second i.e. 1000ms
await delay(1000)

// Install rust
await exec.exec(
`${platform.isWindows ? './rustup-init.exe' : './rustup.sh'}`,
Expand Down
12 changes: 12 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,15 @@ export async function download_file(
throw err
})
}

/**
* Sleeps for the said amount of time (in ms)
*
* @export
* @async
* @param {number} ms Time in milliseconds for the delay
* @returns {void}
*/
export async function delay(ms: number): Promise<void> {
return new Promise(resolve => setTimeout(resolve, ms))
}

0 comments on commit 1b2d7f6

Please sign in to comment.