diff --git a/.prettierignore b/.prettierignore index 21869472..1f05c4ce 100644 --- a/.prettierignore +++ b/.prettierignore @@ -1,3 +1,4 @@ dist/ lib/ -node_modules/ \ No newline at end of file +node_modules/ +*.json \ No newline at end of file diff --git a/__tests__/main.test.ts b/__tests__/main.test.ts index ad000ff2..073f26a7 100644 --- a/__tests__/main.test.ts +++ b/__tests__/main.test.ts @@ -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 () => { @@ -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: "*", @@ -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", @@ -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", @@ -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", @@ -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", @@ -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", @@ -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", @@ -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", @@ -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", @@ -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", @@ -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", @@ -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", @@ -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) diff --git a/__tests__/resource/4-with-prerelease.json b/__tests__/resource/4-with-prerelease.json new file mode 100644 index 00000000..85f7d178 --- /dev/null +++ b/__tests__/resource/4-with-prerelease.json @@ -0,0 +1,524 @@ +[ + { + "url": "https://api.github.com/repos/robinraju/slick-pg/releases/134459592", + "assets_url": "https://api.github.com/repos/robinraju/slick-pg/releases/134459592/assets", + "upload_url": "https://uploads.github.com/repos/robinraju/slick-pg/releases/134459592/assets{?name,label}", + "html_url": "https://github.com/robinraju/slick-pg/releases/tag/0.22.0-M5", + "id": 134459592, + "author": null, + "node_id": "RE_kwDOAJgE5M4IA7DI", + "tag_name": "0.22.0-M5", + "target_commitish": "master", + "name": "0.22.0-M5", + "draft": false, + "prerelease": true, + "created_at": "2023-12-17T11:18:44Z", + "published_at": "2023-12-19T12:04:36Z", + "assets": [ + { + "url": "https://api.github.com/repos/robinraju/slick-pg/releases/assets/66946546", + "id": 66946546, + "node_id": "RA_kwDOHahpL84D_YXy", + "name": "pre-release.txt", + "label": null, + "uploader": {}, + "content_type": "text/plain", + "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/slick-pg/releases/download/0.22.0-M5/test-1.txt" + } + ], + "tarball_url": "https://api.github.com/repos/robinraju/slick-pg/tarball/0.22.0-M5", + "zipball_url": "https://api.github.com/repos/robinraju/slick-pg/zipball/0.22.0-M5", + "body": "1) Scala 3 support #677", + "reactions": { + "url": "https://api.github.com/repos/robinraju/slick-pg/releases/134459592/reactions", + "total_count": 3, + "+1": 0, + "-1": 0, + "laugh": 0, + "hooray": 3, + "confused": 0, + "heart": 0, + "rocket": 0, + "eyes": 0 + } + }, + { + "url": "https://api.github.com/repos/robinraju/slick-pg/releases/115265873", + "assets_url": "https://api.github.com/repos/robinraju/slick-pg/releases/115265873/assets", + "upload_url": "https://uploads.github.com/repos/robinraju/slick-pg/releases/115265873/assets{?name,label}", + "html_url": "https://github.com/robinraju/slick-pg/releases/tag/v0.22.0-M4", + "id": 115265873, + "author": null, + "node_id": "RE_kwDOAJgE5M4G3tFR", + "tag_name": "v0.22.0-M4", + "target_commitish": "master", + "name": "v0.22.0-M4", + "draft": false, + "prerelease": true, + "created_at": "2023-08-05T08:33:34Z", + "published_at": "2023-08-05T08:38:36Z", + "assets": [ + + ], + "tarball_url": "https://api.github.com/repos/robinraju/slick-pg/tarball/v0.22.0-M4", + "zipball_url": "https://api.github.com/repos/robinraju/slick-pg/zipball/v0.22.0-M4", + "body": "1) Upgrade to slick v3.5.0-M4\r\n2) Add support for date_bin (#648)\r\n3) Remove split dependencies for scala < 2.13 (#640)\r\n4) Scala 3 explicit implicits (#641)" + }, + { + "url": "https://api.github.com/repos/robinraju/slick-pg/releases/101810981", + "assets_url": "https://api.github.com/repos/robinraju/slick-pg/releases/101810981/assets", + "upload_url": "https://uploads.github.com/repos/robinraju/slick-pg/releases/101810981/assets{?name,label}", + "html_url": "https://github.com/robinraju/slick-pg/releases/tag/v0.22.0-M3", + "id": 101810981, + "author": null, + "node_id": "RE_kwDOAJgE5M4GEYMl", + "tag_name": "v0.22.0-M3", + "target_commitish": "master", + "name": "v0.22.0-M3", + "draft": false, + "prerelease": true, + "created_at": "2023-05-04T03:40:40Z", + "published_at": "2023-05-04T03:48:15Z", + "assets": [ + + ], + "tarball_url": "https://api.github.com/repos/robinraju/slick-pg/tarball/v0.22.0-M3", + "zipball_url": "https://api.github.com/repos/robinraju/slick-pg/zipball/v0.22.0-M3", + "body": "1) upgrade to slick v3.5.0-M3" + }, + { + "url": "https://api.github.com/repos/robinraju/slick-pg/releases/95639750", + "assets_url": "https://api.github.com/repos/robinraju/slick-pg/releases/95639750/assets", + "upload_url": "https://uploads.github.com/repos/robinraju/slick-pg/releases/95639750/assets{?name,label}", + "html_url": "https://github.com/robinraju/slick-pg/releases/tag/v0.22.0-M2", + "id": 95639750, + "author": null, + "node_id": "RE_kwDOAJgE5M4Fs1jG", + "tag_name": "v0.22.0-M2", + "target_commitish": "master", + "name": "v0.22.0-M2", + "draft": false, + "prerelease": true, + "created_at": "2023-03-15T02:00:28Z", + "published_at": "2023-03-15T02:04:15Z", + "assets": [ + + ], + "tarball_url": "https://api.github.com/repos/robinraju/slick-pg/tarball/v0.22.0-M2", + "zipball_url": "https://api.github.com/repos/robinraju/slick-pg/zipball/v0.22.0-M2", + "body": "1) upgrade to slick v3.5.0-M2 \r\n\r\n__p.s. dropped support for scala 2.11/2.12 (following slick)__", + "reactions": { + "url": "https://api.github.com/repos/robinraju/slick-pg/releases/95639750/reactions", + "total_count": 1, + "+1": 1, + "-1": 0, + "laugh": 0, + "hooray": 0, + "confused": 0, + "heart": 0, + "rocket": 0, + "eyes": 0 + } + }, + { + "url": "https://api.github.com/repos/robinraju/slick-pg/releases/85496533", + "assets_url": "https://api.github.com/repos/robinraju/slick-pg/releases/85496533/assets", + "upload_url": "https://uploads.github.com/repos/robinraju/slick-pg/releases/85496533/assets{?name,label}", + "html_url": "https://github.com/robinraju/slick-pg/releases/tag/v0.21.1", + "id": 85496533, + "author": null, + "node_id": "RE_kwDOAJgE5M4FGJLV", + "tag_name": "v0.21.1", + "target_commitish": "master", + "name": "v0.21.1", + "draft": false, + "prerelease": false, + "created_at": "2022-12-06T12:29:58Z", + "published_at": "2022-12-08T23:15:05Z", + "assets": [ + + ], + "tarball_url": "https://api.github.com/repos/robinraju/slick-pg/tarball/v0.21.1", + "zipball_url": "https://api.github.com/repos/robinraju/slick-pg/zipball/v0.21.1", + "body": "1) Rollback scala-parser-combinators to 1.1.2 #587 \r\n2) Add support an auto incrementing by explicitly creating a sequence #606 \r\n3) Add support for strict_word_similarity functions #588 \r\n4) upgrade slick to `v3.4.1`" + }, + { + "url": "https://api.github.com/repos/robinraju/slick-pg/releases/75978975", + "assets_url": "https://api.github.com/repos/robinraju/slick-pg/releases/75978975/assets", + "upload_url": "https://uploads.github.com/repos/robinraju/slick-pg/releases/75978975/assets{?name,label}", + "html_url": "https://github.com/robinraju/slick-pg/releases/tag/v0.21.0", + "id": 75978975, + "author": null, + "node_id": "RE_kwDOAJgE5M4Eh1jf", + "tag_name": "v0.21.0", + "target_commitish": "master", + "name": "v0.21.0", + "draft": false, + "prerelease": false, + "created_at": "2022-09-01T03:15:30Z", + "published_at": "2022-09-01T03:28:17Z", + "assets": [ + + ], + "tarball_url": "https://api.github.com/repos/robinraju/slick-pg/tarball/v0.21.0", + "zipball_url": "https://api.github.com/repos/robinraju/slick-pg/zipball/v0.21.0", + "body": "1) upgrade `slick` to `v3.4.0` and other dependencies\r\n2) fix #580 - SimpleArrayUtils.mkString/fromString have inconsistent behavior" + }, + { + "url": "https://api.github.com/repos/robinraju/slick-pg/releases/75106731", + "assets_url": "https://api.github.com/repos/robinraju/slick-pg/releases/75106731/assets", + "upload_url": "https://uploads.github.com/repos/robinraju/slick-pg/releases/75106731/assets{?name,label}", + "html_url": "https://github.com/robinraju/slick-pg/releases/tag/v0.20.4", + "id": 75106731, + "author": null, + "node_id": "RE_kwDOAJgE5M4Eegmr", + "tag_name": "v0.20.4", + "target_commitish": "slick33", + "name": "v0.20.4", + "draft": false, + "prerelease": false, + "created_at": "2022-08-22T02:14:00Z", + "published_at": "2022-08-23T14:59:49Z", + "assets": [ + + ], + "tarball_url": "https://api.github.com/repos/robinraju/slick-pg/tarball/v0.20.4", + "zipball_url": "https://api.github.com/repos/robinraju/slick-pg/zipball/v0.20.4", + "body": "1) Update vulnerable Postgres JDBC Driver #577" + }, + { + "url": "https://api.github.com/repos/robinraju/slick-pg/releases/64603237", + "assets_url": "https://api.github.com/repos/robinraju/slick-pg/releases/64603237/assets", + "upload_url": "https://uploads.github.com/repos/robinraju/slick-pg/releases/64603237/assets{?name,label}", + "html_url": "https://github.com/robinraju/slick-pg/releases/tag/v0.20.3", + "id": 64603237, + "author": null, + "node_id": "RE_kwDOAJgE5M4D2cRl", + "tag_name": "v0.20.3", + "target_commitish": "slick33", + "name": "v0.20.3", + "draft": false, + "prerelease": false, + "created_at": "2022-04-17T12:23:47Z", + "published_at": "2022-04-17T12:31:25Z", + "assets": [ + + ], + "tarball_url": "https://api.github.com/repos/robinraju/slick-pg/tarball/v0.20.3", + "zipball_url": "https://api.github.com/repos/robinraju/slick-pg/zipball/v0.20.3", + "body": "1. Add tsQuery <-> tsQuery -> tsQuery #551" + }, + { + "url": "https://api.github.com/repos/robinraju/slick-pg/releases/63032454", + "assets_url": "https://api.github.com/repos/robinraju/slick-pg/releases/63032454/assets", + "upload_url": "https://uploads.github.com/repos/robinraju/slick-pg/releases/63032454/assets{?name,label}", + "html_url": "https://github.com/robinraju/slick-pg/releases/tag/v0.21.0-M1", + "id": 63032454, + "author": null, + "node_id": "RE_kwDOAJgE5M4DwcyG", + "tag_name": "v0.21.0-M1", + "target_commitish": "master", + "name": "v0.21.0-M1", + "draft": false, + "prerelease": true, + "created_at": "2022-03-29T12:17:43Z", + "published_at": "2022-03-29T12:40:25Z", + "assets": [ + + ], + "tarball_url": "https://api.github.com/repos/robinraju/slick-pg/tarball/v0.21.0-M1", + "zipball_url": "https://api.github.com/repos/robinraju/slick-pg/zipball/v0.21.0-M1", + "body": "1) upgrade to slick 3.4.0-M1." + }, + { + "url": "https://api.github.com/repos/robinraju/slick-pg/releases/55795139", + "assets_url": "https://api.github.com/repos/robinraju/slick-pg/releases/55795139/assets", + "upload_url": "https://uploads.github.com/repos/robinraju/slick-pg/releases/55795139/assets{?name,label}", + "html_url": "https://github.com/robinraju/slick-pg/releases/tag/v0.20.2", + "id": 55795139, + "author": null, + "node_id": "RE_kwDOAJgE5M4DU13D", + "tag_name": "v0.20.2", + "target_commitish": "master", + "name": "v0.20.2", + "draft": false, + "prerelease": false, + "created_at": "2021-12-22T03:14:01Z", + "published_at": "2021-12-22T03:18:09Z", + "assets": [ + + ], + "tarball_url": "https://api.github.com/repos/robinraju/slick-pg/tarball/v0.20.2", + "zipball_url": "https://api.github.com/repos/robinraju/slick-pg/zipball/v0.20.2", + "body": "1) Fix composite parsing bug (#511 #512)\r\n2) upgrade to json4s 4.0.3 (#509)" + }, + { + "url": "https://api.github.com/repos/robinraju/slick-pg/releases/46442396", + "assets_url": "https://api.github.com/repos/robinraju/slick-pg/releases/46442396/assets", + "upload_url": "https://uploads.github.com/repos/robinraju/slick-pg/releases/46442396/assets{?name,label}", + "html_url": "https://github.com/robinraju/slick-pg/releases/tag/v0.19.7", + "id": 46442396, + "author": null, + "node_id": "MDc6UmVsZWFzZTQ2NDQyMzk2", + "tag_name": "v0.19.7", + "target_commitish": "master", + "name": "v0.19.7", + "draft": false, + "prerelease": false, + "created_at": "2021-07-19T23:15:16Z", + "published_at": "2021-07-19T23:16:58Z", + "assets": [ + + ], + "tarball_url": "https://api.github.com/repos/robinraju/slick-pg/tarball/v0.19.7", + "zipball_url": "https://api.github.com/repos/robinraju/slick-pg/zipball/v0.19.7", + "body": "1) Add phrase_to_tsquery, websearch_to_tsquery functions (#507)" + }, + { + "url": "https://api.github.com/repos/robinraju/slick-pg/releases/41815731", + "assets_url": "https://api.github.com/repos/robinraju/slick-pg/releases/41815731/assets", + "upload_url": "https://uploads.github.com/repos/robinraju/slick-pg/releases/41815731/assets{?name,label}", + "html_url": "https://github.com/robinraju/slick-pg/releases/tag/v0.19.6", + "id": 41815731, + "author": null, + "node_id": "MDc6UmVsZWFzZTQxODE1NzMx", + "tag_name": "v0.19.6", + "target_commitish": "master", + "name": "v0.19.6", + "draft": false, + "prerelease": false, + "created_at": "2021-04-21T15:34:15Z", + "published_at": "2021-04-22T04:13:30Z", + "assets": [ + + ], + "tarball_url": "https://api.github.com/repos/robinraju/slick-pg/tarball/v0.19.6", + "zipball_url": "https://api.github.com/repos/robinraju/slick-pg/zipball/v0.19.6", + "body": "1. fix generating sql for arrays with custom types #503\r\n2. use testcontainers for tests, update addon/scala versions #505" + }, + { + "url": "https://api.github.com/repos/robinraju/slick-pg/releases/38228470", + "assets_url": "https://api.github.com/repos/robinraju/slick-pg/releases/38228470/assets", + "upload_url": "https://uploads.github.com/repos/robinraju/slick-pg/releases/38228470/assets{?name,label}", + "html_url": "https://github.com/robinraju/slick-pg/releases/tag/v0.19.5", + "id": 38228470, + "author": null, + "node_id": "MDc6UmVsZWFzZTM4MjI4NDcw", + "tag_name": "v0.19.5", + "target_commitish": "master", + "name": "v0.19.5", + "draft": false, + "prerelease": false, + "created_at": "2021-02-18T11:13:23Z", + "published_at": "2021-02-18T13:24:10Z", + "assets": [ + + ], + "tarball_url": "https://api.github.com/repos/robinraju/slick-pg/tarball/v0.19.5", + "zipball_url": "https://api.github.com/repos/robinraju/slick-pg/zipball/v0.19.5", + "body": "1. Add support for POSIX regular expression matching on strings #497 \r\n2. Fix - Non-uniform isEmpty behaviour #498 \r\n3. Fix - Remove all \\u0000 characters from JSON strings in simple json support #500 " + }, + { + "url": "https://api.github.com/repos/robinraju/slick-pg/releases/33894266", + "assets_url": "https://api.github.com/repos/robinraju/slick-pg/releases/33894266/assets", + "upload_url": "https://uploads.github.com/repos/robinraju/slick-pg/releases/33894266/assets{?name,label}", + "html_url": "https://github.com/robinraju/slick-pg/releases/tag/v0.19.4", + "id": 33894266, + "author": null, + "node_id": "MDc6UmVsZWFzZTMzODk0MjY2", + "tag_name": "v0.19.4", + "target_commitish": "master", + "name": "v0.19.4", + "draft": false, + "prerelease": false, + "created_at": "2020-11-13T04:22:55Z", + "published_at": "2020-11-13T04:27:54Z", + "assets": [ + + ], + "tarball_url": "https://api.github.com/repos/robinraju/slick-pg/tarball/v0.19.4", + "zipball_url": "https://api.github.com/repos/robinraju/slick-pg/zipball/v0.19.4", + "body": "1) upgrade `slick` to `v3.3.3`\r\n2) Fix escaping quotes in string arrays #492\r\n3) hstore's +> should return Option[String] instead of String #494" + }, + { + "url": "https://api.github.com/repos/robinraju/slick-pg/releases/31020503", + "assets_url": "https://api.github.com/repos/robinraju/slick-pg/releases/31020503/assets", + "upload_url": "https://uploads.github.com/repos/robinraju/slick-pg/releases/31020503/assets{?name,label}", + "html_url": "https://github.com/robinraju/slick-pg/releases/tag/v0.19.3", + "id": 31020503, + "author": null, + "node_id": "MDc6UmVsZWFzZTMxMDIwNTAz", + "tag_name": "v0.19.3", + "target_commitish": "master", + "name": "v0.19.3", + "draft": false, + "prerelease": false, + "created_at": "2020-09-10T02:56:00Z", + "published_at": "2020-09-10T02:59:03Z", + "assets": [ + + ], + "tarball_url": "https://api.github.com/repos/robinraju/slick-pg/tarball/v0.19.3", + "zipball_url": "https://api.github.com/repos/robinraju/slick-pg/zipball/v0.19.3", + "body": "1. Fixed - Null in array serialized wrongly #488\r\n\r\nRebuilt with java 8 for v0.19.1" + }, + { + "url": "https://api.github.com/repos/robinraju/slick-pg/releases/28970775", + "assets_url": "https://api.github.com/repos/robinraju/slick-pg/releases/28970775/assets", + "upload_url": "https://uploads.github.com/repos/robinraju/slick-pg/releases/28970775/assets{?name,label}", + "html_url": "https://github.com/robinraju/slick-pg/releases/tag/v0.19.1", + "id": 28970775, + "author": null, + "node_id": "MDc6UmVsZWFzZTI4OTcwNzc1", + "tag_name": "v0.19.1", + "target_commitish": "master", + "name": "v0.19.1", + "draft": false, + "prerelease": true, + "created_at": "2020-07-27T03:06:22Z", + "published_at": "2020-07-27T03:18:24Z", + "assets": [ + + ], + "tarball_url": "https://api.github.com/repos/robinraju/slick-pg/tarball/v0.19.1", + "zipball_url": "https://api.github.com/repos/robinraju/slick-pg/zipball/v0.19.1", + "body": "1) Support postgis ST_EndPoint, ST_PointN and ST_StartPoint (#482)\r\n2) upgrade scala, jdbc driver to latest version\r\n\r\n**p.s. this is built with java 11 in cautiously. For java 8 build, pls turn to `v0.19.3`.**" + }, + { + "url": "https://api.github.com/repos/robinraju/slick-pg/releases/24758023", + "assets_url": "https://api.github.com/repos/robinraju/slick-pg/releases/24758023/assets", + "upload_url": "https://uploads.github.com/repos/robinraju/slick-pg/releases/24758023/assets{?name,label}", + "html_url": "https://github.com/robinraju/slick-pg/releases/tag/v0.19.0", + "id": 24758023, + "author": null, + "node_id": "MDc6UmVsZWFzZTI0NzU4MDIz", + "tag_name": "v0.19.0", + "target_commitish": "master", + "name": "v0.19.0", + "draft": false, + "prerelease": false, + "created_at": "2020-03-23T03:01:51Z", + "published_at": "2020-03-23T03:10:23Z", + "assets": [ + + ], + "tarball_url": "https://api.github.com/repos/robinraju/slick-pg/tarball/v0.19.0", + "zipball_url": "https://api.github.com/repos/robinraju/slick-pg/zipball/v0.19.0", + "body": "1) add geography support\r\n2) fix #473\r\n3) fix #475 " + }, + { + "url": "https://api.github.com/repos/robinraju/slick-pg/releases/21826353", + "assets_url": "https://api.github.com/repos/robinraju/slick-pg/releases/21826353/assets", + "upload_url": "https://uploads.github.com/repos/robinraju/slick-pg/releases/21826353/assets{?name,label}", + "html_url": "https://github.com/robinraju/slick-pg/releases/tag/v0.18.1", + "id": 21826353, + "author": null, + "node_id": "MDc6UmVsZWFzZTIxODI2MzUz", + "tag_name": "v0.18.1", + "target_commitish": "master", + "name": "v0.18.1", + "draft": false, + "prerelease": false, + "created_at": "2019-11-28T09:56:03Z", + "published_at": "2019-11-28T10:28:10Z", + "assets": [ + + ], + "tarball_url": "https://api.github.com/repos/robinraju/slick-pg/tarball/v0.18.1", + "zipball_url": "https://api.github.com/repos/robinraju/slick-pg/zipball/v0.18.1", + "body": "1) upgrade circe to v0.12.3 **(p.s. but for version of scala 2.11, roll back to v0.11.2 instead, since circe dropped support for scala 2.11)**" + }, + { + "url": "https://api.github.com/repos/robinraju/slick-pg/releases/18253493", + "assets_url": "https://api.github.com/repos/robinraju/slick-pg/releases/18253493/assets", + "upload_url": "https://uploads.github.com/repos/robinraju/slick-pg/releases/18253493/assets{?name,label}", + "html_url": "https://github.com/robinraju/slick-pg/releases/tag/v0.18.0", + "id": 18253493, + "author": null, + "node_id": "MDc6UmVsZWFzZTE4MjUzNDkz", + "tag_name": "v0.18.0", + "target_commitish": "master", + "name": "v0.18.0", + "draft": false, + "prerelease": false, + "created_at": "2019-06-27T01:16:48Z", + "published_at": "2019-06-27T01:18:44Z", + "assets": [ + + ], + "tarball_url": "https://api.github.com/repos/robinraju/slick-pg/tarball/v0.18.0", + "zipball_url": "https://api.github.com/repos/robinraju/slick-pg/zipball/v0.18.0", + "body": "1) support scala 2.13, with related dependencies upgraded and some refactorings." + }, + { + "url": "https://api.github.com/repos/robinraju/slick-pg/releases/17452628", + "assets_url": "https://api.github.com/repos/robinraju/slick-pg/releases/17452628/assets", + "upload_url": "https://uploads.github.com/repos/robinraju/slick-pg/releases/17452628/assets{?name,label}", + "html_url": "https://github.com/robinraju/slick-pg/releases/tag/v0.17.3", + "id": 17452628, + "author": null, + "node_id": "MDc6UmVsZWFzZTE3NDUyNjI4", + "tag_name": "v0.17.3", + "target_commitish": "master", + "name": "v0.17.3", + "draft": false, + "prerelease": false, + "created_at": "2019-05-20T03:54:21Z", + "published_at": "2019-05-20T03:57:13Z", + "assets": [ + + ], + "tarball_url": "https://api.github.com/repos/robinraju/slick-pg/tarball/v0.17.3", + "zipball_url": "https://api.github.com/repos/robinraju/slick-pg/zipball/v0.17.3", + "body": "1) fix #449" + }, + { + "url": "https://api.github.com/repos/robinraju/slick-pg/releases/15424160", + "assets_url": "https://api.github.com/repos/robinraju/slick-pg/releases/15424160/assets", + "upload_url": "https://uploads.github.com/repos/robinraju/slick-pg/releases/15424160/assets{?name,label}", + "html_url": "https://github.com/robinraju/slick-pg/releases/tag/v0.17.2", + "id": 15424160, + "author": null, + "node_id": "MDc6UmVsZWFzZTE1NDI0MTYw", + "tag_name": "v0.17.2", + "target_commitish": "master", + "name": "v0.17.2", + "draft": false, + "prerelease": false, + "created_at": "2019-02-07T14:17:52Z", + "published_at": "2019-02-07T14:21:56Z", + "assets": [ + + ], + "tarball_url": "https://api.github.com/repos/robinraju/slick-pg/tarball/v0.17.2", + "zipball_url": "https://api.github.com/repos/robinraju/slick-pg/zipball/v0.17.2", + "body": "1) update to slick 3.3.0\r\n2) update to play-json 2.7" + }, + { + "url": "https://api.github.com/repos/robinraju/slick-pg/releases/15231483", + "assets_url": "https://api.github.com/repos/robinraju/slick-pg/releases/15231483/assets", + "upload_url": "https://uploads.github.com/repos/robinraju/slick-pg/releases/15231483/assets{?name,label}", + "html_url": "https://github.com/robinraju/slick-pg/releases/tag/v0.17.1", + "id": 15231483, + "author": null, + "node_id": "MDc6UmVsZWFzZTE1MjMxNDgz", + "tag_name": "v0.17.1", + "target_commitish": "master", + "name": "v0.17.1", + "draft": false, + "prerelease": false, + "created_at": "2019-01-29T04:08:45Z", + "published_at": "2019-01-29T05:24:04Z", + "assets": [ + + ], + "tarball_url": "https://api.github.com/repos/robinraju/slick-pg/tarball/v0.17.1", + "zipball_url": "https://api.github.com/repos/robinraju/slick-pg/zipball/v0.17.1", + "body": "1. Add support for locationtech's JTS library #442\r\n2. Provide a custom way for #441\r\n3. Upgrade some third party dependencies" + } +] \ No newline at end of file diff --git a/__tests__/resource/5-without-prerelease.json b/__tests__/resource/5-without-prerelease.json new file mode 100644 index 00000000..a83d53d0 --- /dev/null +++ b/__tests__/resource/5-without-prerelease.json @@ -0,0 +1,134 @@ +[ + { + "url": "https://api.github.com/repos/foo/slick-pg/releases/24758023", + "assets_url": "https://api.github.com/repos/foo/slick-pg/releases/24758023/assets", + "upload_url": "https://uploads.github.com/repos/foo/slick-pg/releases/24758023/assets{?name,label}", + "html_url": "https://github.com/foo/slick-pg/releases/tag/v0.19.0", + "id": 24758023, + "author": null, + "node_id": "MDc6UmVsZWFzZTI0NzU4MDIz", + "tag_name": "v0.19.0", + "target_commitish": "master", + "name": "v0.19.0", + "draft": false, + "prerelease": false, + "created_at": "2020-03-23T03:01:51Z", + "published_at": "2020-03-23T03:10:23Z", + "assets": [ + + ], + "tarball_url": "https://api.github.com/repos/foo/slick-pg/tarball/v0.19.0", + "zipball_url": "https://api.github.com/repos/foo/slick-pg/zipball/v0.19.0", + "body": "1) add geography support\r\n2) fix #473\r\n3) fix #475 " + }, + { + "url": "https://api.github.com/repos/foo/slick-pg/releases/21826353", + "assets_url": "https://api.github.com/repos/foo/slick-pg/releases/21826353/assets", + "upload_url": "https://uploads.github.com/repos/foo/slick-pg/releases/21826353/assets{?name,label}", + "html_url": "https://github.com/foo/slick-pg/releases/tag/v0.18.1", + "id": 21826353, + "author": null, + "node_id": "MDc6UmVsZWFzZTIxODI2MzUz", + "tag_name": "v0.18.1", + "target_commitish": "master", + "name": "v0.18.1", + "draft": false, + "prerelease": false, + "created_at": "2019-11-28T09:56:03Z", + "published_at": "2019-11-28T10:28:10Z", + "assets": [ + + ], + "tarball_url": "https://api.github.com/repos/foo/slick-pg/tarball/v0.18.1", + "zipball_url": "https://api.github.com/repos/foo/slick-pg/zipball/v0.18.1", + "body": "1) upgrade circe to v0.12.3 **(p.s. but for version of scala 2.11, roll back to v0.11.2 instead, since circe dropped support for scala 2.11)**" + }, + { + "url": "https://api.github.com/repos/foo/slick-pg/releases/18253493", + "assets_url": "https://api.github.com/repos/foo/slick-pg/releases/18253493/assets", + "upload_url": "https://uploads.github.com/repos/foo/slick-pg/releases/18253493/assets{?name,label}", + "html_url": "https://github.com/foo/slick-pg/releases/tag/v0.18.0", + "id": 18253493, + "author": null, + "node_id": "MDc6UmVsZWFzZTE4MjUzNDkz", + "tag_name": "v0.18.0", + "target_commitish": "master", + "name": "v0.18.0", + "draft": false, + "prerelease": false, + "created_at": "2019-06-27T01:16:48Z", + "published_at": "2019-06-27T01:18:44Z", + "assets": [ + + ], + "tarball_url": "https://api.github.com/repos/foo/slick-pg/tarball/v0.18.0", + "zipball_url": "https://api.github.com/repos/foo/slick-pg/zipball/v0.18.0", + "body": "1) support scala 2.13, with related dependencies upgraded and some refactorings." + }, + { + "url": "https://api.github.com/repos/foo/slick-pg/releases/17452628", + "assets_url": "https://api.github.com/repos/foo/slick-pg/releases/17452628/assets", + "upload_url": "https://uploads.github.com/repos/foo/slick-pg/releases/17452628/assets{?name,label}", + "html_url": "https://github.com/foo/slick-pg/releases/tag/v0.17.3", + "id": 17452628, + "author": null, + "node_id": "MDc6UmVsZWFzZTE3NDUyNjI4", + "tag_name": "v0.17.3", + "target_commitish": "master", + "name": "v0.17.3", + "draft": false, + "prerelease": false, + "created_at": "2019-05-20T03:54:21Z", + "published_at": "2019-05-20T03:57:13Z", + "assets": [ + + ], + "tarball_url": "https://api.github.com/repos/foo/slick-pg/tarball/v0.17.3", + "zipball_url": "https://api.github.com/repos/foo/slick-pg/zipball/v0.17.3", + "body": "1) fix #449" + }, + { + "url": "https://api.github.com/repos/foo/slick-pg/releases/15424160", + "assets_url": "https://api.github.com/repos/foo/slick-pg/releases/15424160/assets", + "upload_url": "https://uploads.github.com/repos/foo/slick-pg/releases/15424160/assets{?name,label}", + "html_url": "https://github.com/foo/slick-pg/releases/tag/v0.17.2", + "id": 15424160, + "author": null, + "node_id": "MDc6UmVsZWFzZTE1NDI0MTYw", + "tag_name": "v0.17.2", + "target_commitish": "master", + "name": "v0.17.2", + "draft": false, + "prerelease": false, + "created_at": "2019-02-07T14:17:52Z", + "published_at": "2019-02-07T14:21:56Z", + "assets": [ + + ], + "tarball_url": "https://api.github.com/repos/foo/slick-pg/tarball/v0.17.2", + "zipball_url": "https://api.github.com/repos/foo/slick-pg/zipball/v0.17.2", + "body": "1) update to slick 3.3.0\r\n2) update to play-json 2.7" + }, + { + "url": "https://api.github.com/repos/foo/slick-pg/releases/15231483", + "assets_url": "https://api.github.com/repos/foo/slick-pg/releases/15231483/assets", + "upload_url": "https://uploads.github.com/repos/foo/slick-pg/releases/15231483/assets{?name,label}", + "html_url": "https://github.com/foo/slick-pg/releases/tag/v0.17.1", + "id": 15231483, + "author": null, + "node_id": "MDc6UmVsZWFzZTE1MjMxNDgz", + "tag_name": "v0.17.1", + "target_commitish": "master", + "name": "v0.17.1", + "draft": false, + "prerelease": false, + "created_at": "2019-01-29T04:08:45Z", + "published_at": "2019-01-29T05:24:04Z", + "assets": [ + + ], + "tarball_url": "https://api.github.com/repos/foo/slick-pg/tarball/v0.17.1", + "zipball_url": "https://api.github.com/repos/foo/slick-pg/zipball/v0.17.1", + "body": "1. Add support for locationtech's JTS library #442\r\n2. Provide a custom way for #441\r\n3. Upgrade some third party dependencies" + } + ] \ No newline at end of file diff --git a/__tests__/resource/assets/pre-release.txt b/__tests__/resource/assets/pre-release.txt new file mode 100644 index 00000000..844ff53e --- /dev/null +++ b/__tests__/resource/assets/pre-release.txt @@ -0,0 +1 @@ +Pre-release \ No newline at end of file diff --git a/action.yml b/action.yml index 502705dd..a4a0ac85 100644 --- a/action.yml +++ b/action.yml @@ -10,6 +10,10 @@ inputs: description: "A flag to choose between latest release and remaining releases" default: "false" required: false + preRelease: + description: "A flag to download from prerelease. It should be combined with latest flag" + default: "false" + required: false tag: description: "The github tag to download the release from" default: "" diff --git a/dist/index.js b/dist/index.js index b7973ea2..c23e6997 100644 --- a/dist/index.js +++ b/dist/index.js @@ -33,36 +33,42 @@ Object.defineProperty(exports, "__esModule", ({ value: true })); exports.getInputs = void 0; const core = __importStar(__nccwpck_require__(2186)); const path = __importStar(__nccwpck_require__(1017)); +function validateRepositoryPath(repositoryPath) { + const repoParts = repositoryPath.split("/"); + if (repoParts.length !== 2 || !repoParts[0] || !repoParts[1]) { + throw new Error(`Invalid repository '${repositoryPath}'. Expected format {owner}/{repo}.`); + } +} +function validateReleaseVersion(latestFlag, ghTag, releaseId) { + if ((latestFlag && ghTag && releaseId) || (ghTag && releaseId)) { + throw new Error(`Invalid inputs. latest=${latestFlag}, tag=${ghTag}, and releaseId=${releaseId} can't coexist`); + } +} function getInputs() { - const downloadSettings = {}; let githubWorkspacePath = process.env["GITHUB_WORKSPACE"]; if (!githubWorkspacePath) { throw new Error("$GITHUB_WORKSPACE not defined"); } githubWorkspacePath = path.resolve(githubWorkspacePath); const repositoryPath = core.getInput("repository"); - const repo = repositoryPath.split("/"); - if (repo.length !== 2 || !repo[0] || !repo[1]) { - throw new Error(`Invalid repository '${repositoryPath}'. Expected format {owner}/{repo}.`); - } - downloadSettings.sourceRepoPath = repositoryPath; + validateRepositoryPath(repositoryPath); const latestFlag = core.getBooleanInput("latest"); + const preReleaseFlag = core.getBooleanInput("preRelease"); const ghTag = core.getInput("tag"); const releaseId = core.getInput("releaseId"); - if ((latestFlag && ghTag.length > 0 && releaseId.length > 0) || - (ghTag.length > 0 && releaseId.length > 0)) { - throw new Error(`Invalid inputs. latest=${latestFlag}, tag=${ghTag} and releaseId=${releaseId} can't coexist`); - } - downloadSettings.isLatest = latestFlag; - downloadSettings.tag = ghTag; - downloadSettings.id = releaseId; - downloadSettings.fileName = core.getInput("fileName"); - downloadSettings.tarBall = core.getBooleanInput("tarBall"); - downloadSettings.zipBall = core.getBooleanInput("zipBall"); - downloadSettings.extractAssets = core.getBooleanInput("extract"); - const outFilePath = core.getInput("out-file-path") || "."; - downloadSettings.outFilePath = path.resolve(githubWorkspacePath, outFilePath); - return downloadSettings; + validateReleaseVersion(latestFlag, ghTag, releaseId); + return { + sourceRepoPath: repositoryPath, + isLatest: latestFlag, + preRelease: preReleaseFlag, + tag: ghTag, + id: releaseId, + fileName: core.getInput("fileName"), + tarBall: core.getBooleanInput("tarBall"), + zipBall: core.getBooleanInput("zipBall"), + extractAssets: core.getBooleanInput("extract"), + outFilePath: path.resolve(githubWorkspacePath, core.getInput("out-file-path") || ".") + }; } exports.getInputs = getInputs; @@ -196,7 +202,7 @@ class ReleaseDownloader { return __awaiter(this, void 0, void 0, function* () { let ghRelease; if (downloadSettings.isLatest) { - ghRelease = yield this.getlatestRelease(downloadSettings.sourceRepoPath); + ghRelease = yield this.getlatestRelease(downloadSettings.sourceRepoPath, downloadSettings.preRelease); } else if (downloadSettings.tag !== "") { ghRelease = yield this.getReleaseByTag(downloadSettings.sourceRepoPath, downloadSettings.tag); @@ -220,18 +226,37 @@ class ReleaseDownloader { * Gets the latest release metadata from github api * @param repoPath The source repository path. {owner}/{repo} */ - getlatestRelease(repoPath) { + getlatestRelease(repoPath, preRelease) { return __awaiter(this, void 0, void 0, function* () { core.info(`Fetching latest release for repo ${repoPath}`); const headers = { Accept: "application/vnd.github.v3+json" }; - const response = yield this.httpClient.get(`${this.apiRoot}/repos/${repoPath}/releases/latest`, headers); + let response; + if (!preRelease) { + response = yield this.httpClient.get(`${this.apiRoot}/repos/${repoPath}/releases/latest`, headers); + } + else { + response = yield this.httpClient.get(`${this.apiRoot}/repos/${repoPath}/releases`, headers); + } if (response.message.statusCode !== 200) { const err = new Error(`[getlatestRelease] Unexpected response: ${response.message.statusCode}`); throw err; } const responseBody = yield response.readBody(); - const release = JSON.parse(responseBody.toString()); - core.info(`Found latest release version: ${release.tag_name}`); + let release; + if (!preRelease) { + release = JSON.parse(responseBody.toString()); + core.info(`Found latest release version: ${release.tag_name}`); + } + else { + const allReleases = JSON.parse(responseBody.toString()); + const latestPreRelease = allReleases.find(r => r.prerelease === true); + if (latestPreRelease) { + release = latestPreRelease; + } + else { + throw new Error("No prereleases found!"); + } + } return release; }); } diff --git a/src/download-settings.ts b/src/download-settings.ts index ef9b84cc..88f5b6c0 100644 --- a/src/download-settings.ts +++ b/src/download-settings.ts @@ -9,6 +9,11 @@ export interface IReleaseDownloadSettings { */ isLatest: boolean + /** + * A flag to enable downloading from prerelease + */ + preRelease: boolean + /** * The release tag */ diff --git a/src/gh-api.ts b/src/gh-api.ts index 394fb825..2813eeff 100644 --- a/src/gh-api.ts +++ b/src/gh-api.ts @@ -7,6 +7,7 @@ export interface GithubRelease { name: string id: number tag_name: String + prerelease: boolean assets: GhAsset[] tarball_url: string zipball_url: string diff --git a/src/input-helper.ts b/src/input-helper.ts index 15645747..c62ae70b 100644 --- a/src/input-helper.ts +++ b/src/input-helper.ts @@ -1,11 +1,29 @@ import * as core from "@actions/core" import * as path from "path" - import {IReleaseDownloadSettings} from "./download-settings" -export function getInputs(): IReleaseDownloadSettings { - const downloadSettings = {} as unknown as IReleaseDownloadSettings +function validateRepositoryPath(repositoryPath: string): void { + const repoParts = repositoryPath.split("/") + if (repoParts.length !== 2 || !repoParts[0] || !repoParts[1]) { + throw new Error( + `Invalid repository '${repositoryPath}'. Expected format {owner}/{repo}.` + ) + } +} +function validateReleaseVersion( + latestFlag: boolean, + ghTag: string, + releaseId: string +): void { + if ((latestFlag && ghTag && releaseId) || (ghTag && releaseId)) { + throw new Error( + `Invalid inputs. latest=${latestFlag}, tag=${ghTag}, and releaseId=${releaseId} can't coexist` + ) + } +} + +export function getInputs(): IReleaseDownloadSettings { let githubWorkspacePath = process.env["GITHUB_WORKSPACE"] if (!githubWorkspacePath) { throw new Error("$GITHUB_WORKSPACE not defined") @@ -13,43 +31,28 @@ export function getInputs(): IReleaseDownloadSettings { githubWorkspacePath = path.resolve(githubWorkspacePath) const repositoryPath = core.getInput("repository") - const repo = repositoryPath.split("/") - if (repo.length !== 2 || !repo[0] || !repo[1]) { - throw new Error( - `Invalid repository '${repositoryPath}'. Expected format {owner}/{repo}.` - ) - } - downloadSettings.sourceRepoPath = repositoryPath + validateRepositoryPath(repositoryPath) const latestFlag = core.getBooleanInput("latest") + const preReleaseFlag = core.getBooleanInput("preRelease") const ghTag = core.getInput("tag") const releaseId = core.getInput("releaseId") - if ( - (latestFlag && ghTag.length > 0 && releaseId.length > 0) || - (ghTag.length > 0 && releaseId.length > 0) - ) { - throw new Error( - `Invalid inputs. latest=${latestFlag}, tag=${ghTag} and releaseId=${releaseId} can't coexist` + validateReleaseVersion(latestFlag, ghTag, releaseId) + + return { + sourceRepoPath: repositoryPath, + isLatest: latestFlag, + preRelease: preReleaseFlag, + tag: ghTag, + id: releaseId, + fileName: core.getInput("fileName"), + tarBall: core.getBooleanInput("tarBall"), + zipBall: core.getBooleanInput("zipBall"), + extractAssets: core.getBooleanInput("extract"), + outFilePath: path.resolve( + githubWorkspacePath, + core.getInput("out-file-path") || "." ) } - - downloadSettings.isLatest = latestFlag - - downloadSettings.tag = ghTag - - downloadSettings.id = releaseId - - downloadSettings.fileName = core.getInput("fileName") - - downloadSettings.tarBall = core.getBooleanInput("tarBall") - - downloadSettings.zipBall = core.getBooleanInput("zipBall") - - downloadSettings.extractAssets = core.getBooleanInput("extract") - - const outFilePath = core.getInput("out-file-path") || "." - downloadSettings.outFilePath = path.resolve(githubWorkspacePath, outFilePath) - - return downloadSettings } diff --git a/src/release-downloader.ts b/src/release-downloader.ts index 7378c64b..937db5bf 100644 --- a/src/release-downloader.ts +++ b/src/release-downloader.ts @@ -25,7 +25,10 @@ export class ReleaseDownloader { let ghRelease: GithubRelease if (downloadSettings.isLatest) { - ghRelease = await this.getlatestRelease(downloadSettings.sourceRepoPath) + ghRelease = await this.getlatestRelease( + downloadSettings.sourceRepoPath, + downloadSettings.preRelease + ) } else if (downloadSettings.tag !== "") { ghRelease = await this.getReleaseByTag( downloadSettings.sourceRepoPath, @@ -64,15 +67,26 @@ export class ReleaseDownloader { * Gets the latest release metadata from github api * @param repoPath The source repository path. {owner}/{repo} */ - private async getlatestRelease(repoPath: string): Promise { + private async getlatestRelease( + repoPath: string, + preRelease: boolean + ): Promise { core.info(`Fetching latest release for repo ${repoPath}`) const headers: IHeaders = {Accept: "application/vnd.github.v3+json"} + let response: IHttpClientResponse - const response = await this.httpClient.get( - `${this.apiRoot}/repos/${repoPath}/releases/latest`, - headers - ) + if (!preRelease) { + response = await this.httpClient.get( + `${this.apiRoot}/repos/${repoPath}/releases/latest`, + headers + ) + } else { + response = await this.httpClient.get( + `${this.apiRoot}/repos/${repoPath}/releases`, + headers + ) + } if (response.message.statusCode !== 200) { const err: Error = new Error( @@ -82,9 +96,24 @@ export class ReleaseDownloader { } const responseBody = await response.readBody() - const release: GithubRelease = JSON.parse(responseBody.toString()) - core.info(`Found latest release version: ${release.tag_name}`) + let release: GithubRelease + if (!preRelease) { + release = JSON.parse(responseBody.toString()) + core.info(`Found latest release version: ${release.tag_name}`) + } else { + const allReleases: GithubRelease[] = JSON.parse(responseBody.toString()) + const latestPreRelease: GithubRelease | undefined = allReleases.find( + r => r.prerelease === true + ) + + if (latestPreRelease) { + release = latestPreRelease + } else { + throw new Error("No prereleases found!") + } + } + return release }