Skip to content

Commit

Permalink
Download latest prerelease (#679)
Browse files Browse the repository at this point in the history
* Download latest prerelease

* Update README

* Add test to workflow
  • Loading branch information
robinraju authored Jan 27, 2024
1 parent 52c0768 commit 368754b
Show file tree
Hide file tree
Showing 13 changed files with 887 additions and 69 deletions.
15 changes: 15 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,21 @@ jobs:
shell: bash
run: ls -lrth test-downloads

- name: Test download latest pre-release
uses: ./
with:
repository: "robinraju/probable-potato"
latest: true
preRelease: true
fileName: "prerelease.txt"
tarBall: true
zipBall: true
out-file-path: "./prerelease-downloads"

- name: List downloaded files
shell: bash
run: ls -lrth prerelease-downloads

- name: Test download from a private repo
uses: ./
id: download-private
Expand Down
3 changes: 2 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
dist/
lib/
node_modules/
node_modules/
*.json
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ A Github Action to download assets from github release. It can download specifie
# A flag to set the download target as latest release
# The default value is 'false'
latest: true

# A flag to download from prerelease. It should be combined with latest flag.
# The default value is 'false'
preRelease: true

# The github tag. e.g: v1.0.1
# Download assets from a specific tag/version
Expand Down Expand Up @@ -165,3 +169,14 @@ A Github Action to download assets from github release. It can download specifie
latest: true
extract: true
```

### Download latest prerelease

```yaml
- uses: robinraju/release-downloader@v1.8
with:
repository: "owner/repo"
fileName: "foo.zip"
latest: true
preRelease: true
```
60 changes: 60 additions & 0 deletions __tests__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,20 @@ beforeEach(() => {
})
.get("/repos/my-enterprise/test-repo/releases/assets/66946546")
.replyWithFile(200, __dirname + "/resource/assets/test-1.txt")

nock("https://api.github.com/")
.get("/repos/robinraju/slick-pg/releases")
.reply(200, readFromFile("4-with-prerelease.json"))

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

nock("https://api.github.com/")
.get("/repos/foo/slick-pg/releases")
.reply(200, readFromFile("5-without-prerelease.json"))
})

afterEach(async () => {
Expand All @@ -104,6 +118,7 @@ test("Download all files from public repo", async () => {
const downloadSettings: IReleaseDownloadSettings = {
sourceRepoPath: "robinraju/probable-potato",
isLatest: true,
preRelease: false,
tag: "",
id: "",
fileName: "*",
Expand All @@ -120,6 +135,7 @@ test("Download single file from public repo", async () => {
const downloadSettings: IReleaseDownloadSettings = {
sourceRepoPath: "robinraju/probable-potato",
isLatest: true,
preRelease: false,
tag: "",
id: "",
fileName: "test-1.txt",
Expand All @@ -136,6 +152,7 @@ test("Fail loudly if given filename is not found in a release", async () => {
const downloadSettings: IReleaseDownloadSettings = {
sourceRepoPath: "robinraju/probable-potato",
isLatest: true,
preRelease: false,
tag: "",
id: "",
fileName: "missing-file.txt",
Expand All @@ -154,6 +171,7 @@ test("Fail loudly if release is not identified", async () => {
const downloadSettings: IReleaseDownloadSettings = {
sourceRepoPath: "robinraju/probable-potato",
isLatest: false,
preRelease: false,
tag: "",
id: "",
fileName: "missing-file.txt",
Expand All @@ -172,6 +190,7 @@ test("Download files with wildcard from public repo", async () => {
const downloadSettings: IReleaseDownloadSettings = {
sourceRepoPath: "robinraju/probable-potato",
isLatest: true,
preRelease: false,
tag: "",
id: "",
fileName: "test-*.txt",
Expand All @@ -188,6 +207,7 @@ test("Download single file with wildcard from public repo", async () => {
const downloadSettings: IReleaseDownloadSettings = {
sourceRepoPath: "robinraju/probable-potato",
isLatest: true,
preRelease: false,
tag: "",
id: "",
fileName: "3-*.txt",
Expand All @@ -204,6 +224,7 @@ test("Download multiple pdf files with wildcard filename", async () => {
const downloadSettings: IReleaseDownloadSettings = {
sourceRepoPath: "robinraju/probable-potato",
isLatest: true,
preRelease: false,
tag: "",
id: "",
fileName: "*.pdf",
Expand All @@ -220,6 +241,7 @@ test("Download a csv file with wildcard filename", async () => {
const downloadSettings: IReleaseDownloadSettings = {
sourceRepoPath: "robinraju/probable-potato",
isLatest: true,
preRelease: false,
tag: "",
id: "",
fileName: "*.csv",
Expand All @@ -238,6 +260,7 @@ test("Download file from Github Enterprise server", async () => {
const downloadSettings: IReleaseDownloadSettings = {
sourceRepoPath: "my-enterprise/test-repo",
isLatest: true,
preRelease: false,
tag: "",
id: "",
fileName: "test-1.txt",
Expand All @@ -254,6 +277,7 @@ test("Download file from release identified by ID", async () => {
const downloadSettings: IReleaseDownloadSettings = {
sourceRepoPath: "robinraju/probable-potato",
isLatest: false,
preRelease: false,
tag: "",
id: "68092191",
fileName: "test-2.txt",
Expand All @@ -270,6 +294,7 @@ test("Download all archive files from public repo", async () => {
const downloadSettings: IReleaseDownloadSettings = {
sourceRepoPath: "robinraju/probable-potato",
isLatest: true,
preRelease: false,
tag: "",
id: "",
fileName: "*.zip",
Expand All @@ -295,6 +320,7 @@ test("Fail when a release with no assets are obtained", async () => {
const downloadSettings: IReleaseDownloadSettings = {
sourceRepoPath: "robinraju/foo-app",
isLatest: false,
preRelease: false,
tag: "1.0.0",
id: "",
fileName: "installer.zip",
Expand All @@ -308,3 +334,37 @@ test("Fail when a release with no assets are obtained", async () => {
"No assets found in release Foo app - v1.0.0"
)
}, 10000)

test("Download from latest prerelease", async () => {
const downloadSettings: IReleaseDownloadSettings = {
sourceRepoPath: "robinraju/slick-pg",
isLatest: true,
preRelease: true,
tag: "",
id: "",
fileName: "pre-release.txt",
tarBall: false,
zipBall: false,
extractAssets: false,
outFilePath: outputFilePath
}
const result = await downloader.download(downloadSettings)
expect(result.length).toBe(1)
}, 10000)

test("Fail when a release with no prerelease is obtained", async () => {
const downloadSettings: IReleaseDownloadSettings = {
sourceRepoPath: "foo/slick-pg",
isLatest: true,
preRelease: true,
tag: "",
id: "",
fileName: "installer.zip",
tarBall: false,
zipBall: false,
extractAssets: false,
outFilePath: outputFilePath
}
const result = downloader.download(downloadSettings)
await expect(result).rejects.toThrow("No prereleases found!")
}, 10000)
Loading

0 comments on commit 368754b

Please sign in to comment.