Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 52 additions & 11 deletions __tests__/main.test.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,59 @@
import * as core from "@actions/core"
import * as fs from "fs"
import * as handlers from "typed-rest-client/Handlers"
import * as io from "@actions/io"
import * as thc from "typed-rest-client/HttpClient"

import {IReleaseDownloadSettings} from "../src/download-settings"
import {download} from "../src/download"
import {ReleaseDownloader} from "../src/release-downloader"

const nock = require("nock")

let downloader: ReleaseDownloader
let httpClent: thc.HttpClient
const outputFilePath = "./target"

beforeAll(() => {
const githubtoken = process.env.REPO_TOKEN || ""

const credentialHandler = new handlers.BearerCredentialHandler(
githubtoken,
false
)
httpClent = new thc.HttpClient("gh-api-client", [credentialHandler])
downloader = new ReleaseDownloader(httpClent)

nock("https://api.github.com")
.get("/repos/robinraju/probable-potato/releases/latest")
.reply(200, readFromFile("1-release-latest.json"))

nock("https://api.github.com", {
reqheaders: {accept: "application/octet-stream"}
})
.get("/repos/robinraju/probable-potato/releases/assets/66946546")
.replyWithFile(200, __dirname + "/resource/assets/test-1.txt")
})

afterAll(() => {
io.rmRF(outputFilePath)
})

function readFromFile(fileName: string): string {
return fs.readFileSync(`./__tests__/resource/${fileName}`, {
encoding: "utf-8"
})
}

test("run download", async () => {

const githubtoken = process.env.GITHUB_TOKEN ?? ""
test("Download from public repo", async () => {
const downloadSettings: IReleaseDownloadSettings = {
sourceRepoPath: "lihaoyi/Ammonite",
isLatest: false,
tag: "2.1.1",
fileName: "2.13-2.1.1-14-4f2a1b2-bootstrap",
sourceRepoPath: "robinraju/probable-potato",
isLatest: true,
tag: "",
fileName: "*",
tarBall: false,
zipBall: false,
outFilePath: "./target",
token: githubtoken
outFilePath: outputFilePath
}
await download(downloadSettings)
const result = await downloader.download(downloadSettings)
expect(result.length).toBe(1)
}, 10000)
36 changes: 36 additions & 0 deletions __tests__/resource/1-release-latest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"url": "https://api.github.com/repos/robinraju/probable-potato/releases/68092191",
"assets_url": "https://api.github.com/repos/robinraju/probable-potato/releases/68092191/assets",
"upload_url": "https://uploads.github.com/repos/robinraju/probable-potato/releases/68092191/assets{?name,label}",
"html_url": "https://github.com/robinraju/probable-potato/releases/tag/1.0.1",
"id": 68092191,
"author": {},
"node_id": "RE_kwDOHahpL84EDwEf",
"tag_name": "1.0.1",
"target_commitish": "main",
"name": "Probable potato - v1.0.1",
"draft": false,
"prerelease": false,
"created_at": "2022-05-29T12:03:47Z",
"published_at": "2022-05-29T12:04:42Z",
"assets": [
{
"url": "https://api.github.com/repos/robinraju/probable-potato/releases/assets/66946546",
"id": 66946546,
"node_id": "RA_kwDOHahpL84D_YXy",
"name": "test-1.txt",
"label": null,
"uploader": {},
"content_type": "image/jpeg",
"state": "uploaded",
"size": 7253,
"download_count": 56,
"created_at": "2022-05-29T12:08:23Z",
"updated_at": "2022-05-29T12:08:23Z",
"browser_download_url": "https://github.com/robinraju/probable-potato/releases/download/1.0.1/potato.jpeg"
}
],
"tarball_url": "https://api.github.com/repos/robinraju/probable-potato/tarball/1.0.1",
"zipball_url": "https://api.github.com/repos/robinraju/probable-potato/zipball/1.0.1",
"body": ""
}
1 change: 1 addition & 0 deletions __tests__/resource/assets/test-1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v1.0 robinraju/probable-potato/releases/latest
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ inputs:
required: false
fileName:
description: "Name of the file to download (use '*' to download all assets other than tarball or zipball)"
default: ""
default: "*"
required: false
tarBall:
description: "Download tarball from assets"
Expand Down
70 changes: 60 additions & 10 deletions package-lock.json

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

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
"typed-rest-client": "^1.8.5"
},
"devDependencies": {
"@types/node": "^17.0.36",
"@types/jest": "^27.4.1",
"@types/node": "^17.0.36",
"@typescript-eslint/parser": "^5.27.0",
"@vercel/ncc": "^0.33.4",
"eslint": "^8.16.0",
Expand All @@ -40,6 +40,7 @@
"jest": "^27.5.1",
"jest-circus": "^28.1.0",
"js-yaml": "^4.1.0",
"nock": "^13.2.6",
"prettier": "2.6.2",
"ts-jest": "^27.1.4",
"typescript": "^4.7.2"
Expand Down
5 changes: 0 additions & 5 deletions src/download-settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,4 @@ export interface IReleaseDownloadSettings {
* Target path to download the file
*/
outFilePath: string

/**
* Github access token to download from private repos (Optional)
*/
token: string
}
Loading