Skip to content

Commit 368754b

Browse files
authored
Download latest prerelease (#679)
* Download latest prerelease * Update README * Add test to workflow
1 parent 52c0768 commit 368754b

13 files changed

+887
-69
lines changed

.github/workflows/ci.yml

+15
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,21 @@ jobs:
5151
shell: bash
5252
run: ls -lrth test-downloads
5353

54+
- name: Test download latest pre-release
55+
uses: ./
56+
with:
57+
repository: "robinraju/probable-potato"
58+
latest: true
59+
preRelease: true
60+
fileName: "prerelease.txt"
61+
tarBall: true
62+
zipBall: true
63+
out-file-path: "./prerelease-downloads"
64+
65+
- name: List downloaded files
66+
shell: bash
67+
run: ls -lrth prerelease-downloads
68+
5469
- name: Test download from a private repo
5570
uses: ./
5671
id: download-private

.prettierignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
dist/
22
lib/
3-
node_modules/
3+
node_modules/
4+
*.json

README.md

+15
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ A Github Action to download assets from github release. It can download specifie
1818
# A flag to set the download target as latest release
1919
# The default value is 'false'
2020
latest: true
21+
22+
# A flag to download from prerelease. It should be combined with latest flag.
23+
# The default value is 'false'
24+
preRelease: true
2125

2226
# The github tag. e.g: v1.0.1
2327
# Download assets from a specific tag/version
@@ -165,3 +169,14 @@ A Github Action to download assets from github release. It can download specifie
165169
latest: true
166170
extract: true
167171
```
172+
173+
### Download latest prerelease
174+
175+
```yaml
176+
- uses: robinraju/[email protected]
177+
with:
178+
repository: "owner/repo"
179+
fileName: "foo.zip"
180+
latest: true
181+
preRelease: true
182+
```

__tests__/main.test.ts

+60
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,20 @@ beforeEach(() => {
8888
})
8989
.get("/repos/my-enterprise/test-repo/releases/assets/66946546")
9090
.replyWithFile(200, __dirname + "/resource/assets/test-1.txt")
91+
92+
nock("https://api.github.com/")
93+
.get("/repos/robinraju/slick-pg/releases")
94+
.reply(200, readFromFile("4-with-prerelease.json"))
95+
96+
nock("https://api.github.com", {
97+
reqheaders: {accept: "application/octet-stream"}
98+
})
99+
.get("/repos/robinraju/slick-pg/releases/assets/66946546")
100+
.replyWithFile(200, __dirname + "/resource/assets/pre-release.txt")
101+
102+
nock("https://api.github.com/")
103+
.get("/repos/foo/slick-pg/releases")
104+
.reply(200, readFromFile("5-without-prerelease.json"))
91105
})
92106

93107
afterEach(async () => {
@@ -104,6 +118,7 @@ test("Download all files from public repo", async () => {
104118
const downloadSettings: IReleaseDownloadSettings = {
105119
sourceRepoPath: "robinraju/probable-potato",
106120
isLatest: true,
121+
preRelease: false,
107122
tag: "",
108123
id: "",
109124
fileName: "*",
@@ -120,6 +135,7 @@ test("Download single file from public repo", async () => {
120135
const downloadSettings: IReleaseDownloadSettings = {
121136
sourceRepoPath: "robinraju/probable-potato",
122137
isLatest: true,
138+
preRelease: false,
123139
tag: "",
124140
id: "",
125141
fileName: "test-1.txt",
@@ -136,6 +152,7 @@ test("Fail loudly if given filename is not found in a release", async () => {
136152
const downloadSettings: IReleaseDownloadSettings = {
137153
sourceRepoPath: "robinraju/probable-potato",
138154
isLatest: true,
155+
preRelease: false,
139156
tag: "",
140157
id: "",
141158
fileName: "missing-file.txt",
@@ -154,6 +171,7 @@ test("Fail loudly if release is not identified", async () => {
154171
const downloadSettings: IReleaseDownloadSettings = {
155172
sourceRepoPath: "robinraju/probable-potato",
156173
isLatest: false,
174+
preRelease: false,
157175
tag: "",
158176
id: "",
159177
fileName: "missing-file.txt",
@@ -172,6 +190,7 @@ test("Download files with wildcard from public repo", async () => {
172190
const downloadSettings: IReleaseDownloadSettings = {
173191
sourceRepoPath: "robinraju/probable-potato",
174192
isLatest: true,
193+
preRelease: false,
175194
tag: "",
176195
id: "",
177196
fileName: "test-*.txt",
@@ -188,6 +207,7 @@ test("Download single file with wildcard from public repo", async () => {
188207
const downloadSettings: IReleaseDownloadSettings = {
189208
sourceRepoPath: "robinraju/probable-potato",
190209
isLatest: true,
210+
preRelease: false,
191211
tag: "",
192212
id: "",
193213
fileName: "3-*.txt",
@@ -204,6 +224,7 @@ test("Download multiple pdf files with wildcard filename", async () => {
204224
const downloadSettings: IReleaseDownloadSettings = {
205225
sourceRepoPath: "robinraju/probable-potato",
206226
isLatest: true,
227+
preRelease: false,
207228
tag: "",
208229
id: "",
209230
fileName: "*.pdf",
@@ -220,6 +241,7 @@ test("Download a csv file with wildcard filename", async () => {
220241
const downloadSettings: IReleaseDownloadSettings = {
221242
sourceRepoPath: "robinraju/probable-potato",
222243
isLatest: true,
244+
preRelease: false,
223245
tag: "",
224246
id: "",
225247
fileName: "*.csv",
@@ -238,6 +260,7 @@ test("Download file from Github Enterprise server", async () => {
238260
const downloadSettings: IReleaseDownloadSettings = {
239261
sourceRepoPath: "my-enterprise/test-repo",
240262
isLatest: true,
263+
preRelease: false,
241264
tag: "",
242265
id: "",
243266
fileName: "test-1.txt",
@@ -254,6 +277,7 @@ test("Download file from release identified by ID", async () => {
254277
const downloadSettings: IReleaseDownloadSettings = {
255278
sourceRepoPath: "robinraju/probable-potato",
256279
isLatest: false,
280+
preRelease: false,
257281
tag: "",
258282
id: "68092191",
259283
fileName: "test-2.txt",
@@ -270,6 +294,7 @@ test("Download all archive files from public repo", async () => {
270294
const downloadSettings: IReleaseDownloadSettings = {
271295
sourceRepoPath: "robinraju/probable-potato",
272296
isLatest: true,
297+
preRelease: false,
273298
tag: "",
274299
id: "",
275300
fileName: "*.zip",
@@ -295,6 +320,7 @@ test("Fail when a release with no assets are obtained", async () => {
295320
const downloadSettings: IReleaseDownloadSettings = {
296321
sourceRepoPath: "robinraju/foo-app",
297322
isLatest: false,
323+
preRelease: false,
298324
tag: "1.0.0",
299325
id: "",
300326
fileName: "installer.zip",
@@ -308,3 +334,37 @@ test("Fail when a release with no assets are obtained", async () => {
308334
"No assets found in release Foo app - v1.0.0"
309335
)
310336
}, 10000)
337+
338+
test("Download from latest prerelease", async () => {
339+
const downloadSettings: IReleaseDownloadSettings = {
340+
sourceRepoPath: "robinraju/slick-pg",
341+
isLatest: true,
342+
preRelease: true,
343+
tag: "",
344+
id: "",
345+
fileName: "pre-release.txt",
346+
tarBall: false,
347+
zipBall: false,
348+
extractAssets: false,
349+
outFilePath: outputFilePath
350+
}
351+
const result = await downloader.download(downloadSettings)
352+
expect(result.length).toBe(1)
353+
}, 10000)
354+
355+
test("Fail when a release with no prerelease is obtained", async () => {
356+
const downloadSettings: IReleaseDownloadSettings = {
357+
sourceRepoPath: "foo/slick-pg",
358+
isLatest: true,
359+
preRelease: true,
360+
tag: "",
361+
id: "",
362+
fileName: "installer.zip",
363+
tarBall: false,
364+
zipBall: false,
365+
extractAssets: false,
366+
outFilePath: outputFilePath
367+
}
368+
const result = downloader.download(downloadSettings)
369+
await expect(result).rejects.toThrow("No prereleases found!")
370+
}, 10000)

0 commit comments

Comments
 (0)