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 addToPath options #732

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@ specified files from both private and public repositories.
# Default: "https://api.github.com"
# Use http(s)://[hostname]/api/v3 to access the API for GitHub Enterprise Server
github-api-url: ''

# Add downloaded file path to the PATH environment variable
# Default: false
# Also strips any information after `-(v?)[0-9]` (which is commonly version and platform information), so that
# the binary is name matches its standard name.
# Also makes binaries executable via chmod
addToPath: false
```

### Output variables
Expand Down
88 changes: 73 additions & 15 deletions __tests__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { IReleaseDownloadSettings } from '../src/download-settings'
import { ReleaseDownloader } from '../src/release-downloader'
import nock from 'nock'
import { extract } from '../src/unarchive'
import { which } from '@actions/io'

let downloader: ReleaseDownloader
let httpClent: thc.HttpClient
Expand Down Expand Up @@ -123,6 +124,26 @@ beforeEach(() => {
200,
`${__dirname}/resource/assets/tar-zip-ball-only-repo.zip`
)

nock('https://api.github.com')
.get('/repos/sharkdp/hyperfine/releases/latest')
.replyWithFile(200, `${__dirname}/resource/7-add-assets-to-path.json`)

nock('https://api.github.com')
.get('/repos/sharkdp/hyperfine/releases/assets/129136486')
.replyWithFile(200, `${__dirname}/resource/assets/assets-path.json`)

nock('https://api.github.com', {
reqheaders: { accept: '*/*' }
})
.get('/repos/sharkdp/hyperfine/zipball/v1.18.0')
.replyWithFile(200, `${__dirname}/resource/assets/sharkdp-hyperfine.zip`)

nock('https://api.github.com', {
reqheaders: { accept: '*/*' }
})
.get('/repos/sharkdp/hyperfine/tarball/v1.18.0')
.replyWithFile(200, `${__dirname}/resource/assets/sharkdp-hyperfine.tar.gz`)
})

afterEach(async () => {
Expand Down Expand Up @@ -152,7 +173,8 @@ test('Download all files from public repo', async () => {
tarBall: false,
zipBall: false,
extractAssets: false,
outFilePath: outputFilePath
outFilePath: outputFilePath,
addToPathEnvironmentVariable: false
}
const result = await downloader.download(downloadSettings)
expect(result.length).toBe(7)
Expand All @@ -169,7 +191,8 @@ test('Download single file from public repo', async () => {
tarBall: false,
zipBall: false,
extractAssets: false,
outFilePath: outputFilePath
outFilePath: outputFilePath,
addToPathEnvironmentVariable: false
}
const result = await downloader.download(downloadSettings)
expect(result.length).toBe(1)
Expand All @@ -186,7 +209,8 @@ test('Fail loudly if given filename is not found in a release', async () => {
tarBall: false,
zipBall: false,
extractAssets: false,
outFilePath: outputFilePath
outFilePath: outputFilePath,
addToPathEnvironmentVariable: false
}
const result = downloader.download(downloadSettings)
await expect(result).rejects.toThrow(
Expand All @@ -205,7 +229,8 @@ test('Fail loudly if release is not identified', async () => {
tarBall: false,
zipBall: false,
extractAssets: false,
outFilePath: outputFilePath
outFilePath: outputFilePath,
addToPathEnvironmentVariable: false
}
const result = downloader.download(downloadSettings)
await expect(result).rejects.toThrow(
Expand All @@ -224,7 +249,8 @@ test('Download files with wildcard from public repo', async () => {
tarBall: false,
zipBall: false,
extractAssets: false,
outFilePath: outputFilePath
outFilePath: outputFilePath,
addToPathEnvironmentVariable: false
}
const result = await downloader.download(downloadSettings)
expect(result.length).toBe(2)
Expand All @@ -241,7 +267,8 @@ test('Download single file with wildcard from public repo', async () => {
tarBall: false,
zipBall: false,
extractAssets: false,
outFilePath: outputFilePath
outFilePath: outputFilePath,
addToPathEnvironmentVariable: false
}
const result = await downloader.download(downloadSettings)
expect(result.length).toBe(1)
Expand All @@ -258,7 +285,8 @@ test('Download multiple pdf files with wildcard filename', async () => {
tarBall: false,
zipBall: false,
extractAssets: false,
outFilePath: outputFilePath
outFilePath: outputFilePath,
addToPathEnvironmentVariable: false
}
const result = await downloader.download(downloadSettings)
expect(result.length).toBe(2)
Expand All @@ -275,7 +303,8 @@ test('Download a csv file with wildcard filename', async () => {
tarBall: false,
zipBall: false,
extractAssets: false,
outFilePath: outputFilePath
outFilePath: outputFilePath,
addToPathEnvironmentVariable: false
}
const result = await downloader.download(downloadSettings)
expect(result.length).toBe(1)
Expand All @@ -294,7 +323,8 @@ test('Download file from Github Enterprise server', async () => {
tarBall: false,
zipBall: false,
extractAssets: false,
outFilePath: outputFilePath
outFilePath: outputFilePath,
addToPathEnvironmentVariable: false
}
const result = await downloader.download(downloadSettings)
expect(result.length).toBe(1)
Expand All @@ -311,7 +341,8 @@ test('Download file from release identified by ID', async () => {
tarBall: false,
zipBall: false,
extractAssets: false,
outFilePath: outputFilePath
outFilePath: outputFilePath,
addToPathEnvironmentVariable: false
}
const result = await downloader.download(downloadSettings)
expect(result.length).toBe(1)
Expand All @@ -328,7 +359,8 @@ test('Download all archive files from public repo', async () => {
tarBall: false,
zipBall: false,
extractAssets: true,
outFilePath: outputFilePath
outFilePath: outputFilePath,
addToPathEnvironmentVariable: false
}
const result = await downloader.download(downloadSettings)
if (downloadSettings.extractAssets) {
Expand Down Expand Up @@ -367,7 +399,8 @@ test('Fail when a release with no assets are obtained', async () => {
tarBall: false,
zipBall: false,
extractAssets: false,
outFilePath: outputFilePath
outFilePath: outputFilePath,
addToPathEnvironmentVariable: false
}
const result = downloader.download(downloadSettings)
await expect(result).rejects.toThrow(
Expand All @@ -386,7 +419,8 @@ test('Download from latest prerelease', async () => {
tarBall: false,
zipBall: false,
extractAssets: false,
outFilePath: outputFilePath
outFilePath: outputFilePath,
addToPathEnvironmentVariable: false
}
const result = await downloader.download(downloadSettings)
expect(result.length).toBe(1)
Expand All @@ -403,7 +437,8 @@ test('Fail when a release with no prerelease is obtained', async () => {
tarBall: false,
zipBall: false,
extractAssets: false,
outFilePath: outputFilePath
outFilePath: outputFilePath,
addToPathEnvironmentVariable: false
}
const result = downloader.download(downloadSettings)
await expect(result).rejects.toThrow('No prereleases found!')
Expand All @@ -420,9 +455,32 @@ test('Download from a release containing only tarBall & zipBall', async () => {
tarBall: true,
zipBall: true,
extractAssets: false,
outFilePath: outputFilePath
outFilePath: outputFilePath,
addToPathEnvironmentVariable: false
}

const result = await downloader.download(downloadSettings)
expect(result.length).toBe(2)
})

test('Download from a release and add binary to PATH', async () => {
const downloadSettings: IReleaseDownloadSettings = {
sourceRepoPath: 'sharkdp/hyperfine',
isLatest: true,
preRelease: false,
tag: '',
id: '',
fileName: '*-x86_64-unknown-linux-gnu*',
tarBall: true,
zipBall: true,
extractAssets: true,
outFilePath: outputFilePath,
addToPathEnvironmentVariable: true
}

const result = await downloader.download(downloadSettings)
expect(result.length).toBeGreaterThan(0)

const binaryPath = await which('hyperfine', true)
expect(binaryPath)
})
Loading