Skip to content

Commit 7922049

Browse files
committed
Fixes #529 Add zip and tarball urls to output
1 parent 0683ea3 commit 7922049

File tree

11 files changed

+934
-828
lines changed

11 files changed

+934
-828
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ This action will create a GitHub release and optionally upload an artifact to it
4949
| id | The identifier of the created release. |
5050
| html_url | The HTML URL of the release. |
5151
| upload_url | The URL for [uploading assets](https://docs.github.com/en/rest/releases/assets?apiVersion=2022-11-28#upload-a-release-asset) to the release. |
52+
| tarball_url | The URL for downloading the release as a tarball (.tar.gz). |
53+
| zipball_url | The URL for downloading the release as a zipball (.zip). |
5254

5355
## Example
5456
This example will create a release when a tag is pushed:

__tests__/Action.test.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ import type { Inputs } from "../src/Inputs"
77
import type { Outputs } from "../src/Outputs"
88
import type { Releases } from "../src/Releases"
99

10+
const TEST_URLS = {
11+
UPLOAD_URL: "http://api.example.com",
12+
HTML_URL: "https://github.com/owner/repo/releases/tag/v1.0.0",
13+
TARBALL_URL: "https://api.github.com/repos/owner/repo/tarball/v1.0.0",
14+
ZIPBALL_URL: "https://api.github.com/repos/owner/repo/zipball/v1.0.0",
15+
} as const
16+
1017
const applyReleaseDataMock = jest.fn()
1118
const artifactDestroyMock = jest.fn()
1219
const createMock = jest.fn()
@@ -38,7 +45,7 @@ const updateDraft = false
3845
const updateName = "updateName"
3946
const updatePrerelease = false
4047
const updateOnlyUnreleased = false
41-
const url = "http://api.example.com"
48+
const url = TEST_URLS.UPLOAD_URL
4249
const makeLatest = "legacy"
4350
const generatedReleaseBody = "test release notes"
4451

@@ -421,6 +428,9 @@ describe("Action", () => {
421428
expect(applyReleaseDataMock).toHaveBeenCalledWith({
422429
id: releaseId,
423430
upload_url: url,
431+
html_url: TEST_URLS.HTML_URL,
432+
tarball_url: TEST_URLS.TARBALL_URL,
433+
zipball_url: TEST_URLS.ZIPBALL_URL,
424434
})
425435
}
426436

@@ -456,6 +466,9 @@ describe("Action", () => {
456466
data: {
457467
id: releaseId,
458468
upload_url: url,
469+
html_url: TEST_URLS.HTML_URL,
470+
tarball_url: TEST_URLS.TARBALL_URL,
471+
zipball_url: TEST_URLS.ZIPBALL_URL,
459472
},
460473
})
461474

@@ -477,6 +490,9 @@ describe("Action", () => {
477490
data: {
478491
id: releaseId,
479492
upload_url: url,
493+
html_url: TEST_URLS.HTML_URL,
494+
tarball_url: TEST_URLS.TARBALL_URL,
495+
zipball_url: TEST_URLS.ZIPBALL_URL,
480496
},
481497
})
482498
uploadMock.mockResolvedValue({})

__tests__/ArtifactGlobber.test.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ describe("ArtifactGlobber", () => {
3939
const expectedArtifacts = globResults.map((path) => new Artifact(path, contentType))
4040

4141
expect(globber.globArtifactString("~/path", "raw", false)).toEqual(expectedArtifacts)
42-
expect(globMock).toBeCalledWith(untildify("~/path"))
43-
expect(warnMock).not.toBeCalled()
42+
expect(globMock).toHaveBeenCalledWith(untildify("~/path"))
43+
expect(warnMock).not.toHaveBeenCalled()
4444
})
4545

4646
it("globs simple path", () => {
@@ -49,8 +49,8 @@ describe("ArtifactGlobber", () => {
4949
const expectedArtifacts = globResults.map((path) => new Artifact(path, contentType))
5050

5151
expect(globber.globArtifactString("path", "raw", false)).toEqual(expectedArtifacts)
52-
expect(globMock).toBeCalledWith("path")
53-
expect(warnMock).not.toBeCalled()
52+
expect(globMock).toHaveBeenCalledWith("path")
53+
expect(warnMock).not.toHaveBeenCalled()
5454
})
5555

5656
it("splits multiple paths with comma separator", () => {
@@ -59,9 +59,9 @@ describe("ArtifactGlobber", () => {
5959
const expectedArtifacts = globResults.concat(globResults).map((path) => new Artifact(path, contentType))
6060

6161
expect(globber.globArtifactString("path1,path2", "raw", false)).toEqual(expectedArtifacts)
62-
expect(globMock).toBeCalledWith("path1")
63-
expect(globMock).toBeCalledWith("path2")
64-
expect(warnMock).not.toBeCalled()
62+
expect(globMock).toHaveBeenCalledWith("path1")
63+
expect(globMock).toHaveBeenCalledWith("path2")
64+
expect(warnMock).not.toHaveBeenCalled()
6565
})
6666

6767
it("splits multiple paths with new line separator and trims start", () => {
@@ -70,16 +70,16 @@ describe("ArtifactGlobber", () => {
7070
const expectedArtifacts = globResults.concat(globResults).map((path) => new Artifact(path, contentType))
7171

7272
expect(globber.globArtifactString("path1\n path2", "raw", false)).toEqual(expectedArtifacts)
73-
expect(globMock).toBeCalledWith("path1")
74-
expect(globMock).toBeCalledWith("path2")
75-
expect(warnMock).not.toBeCalled()
73+
expect(globMock).toHaveBeenCalledWith("path1")
74+
expect(globMock).toHaveBeenCalledWith("path2")
75+
expect(warnMock).not.toHaveBeenCalled()
7676
})
7777

7878
it("warns when no glob results are produced and empty results shouldn't throw", () => {
7979
const globber = createArtifactGlobber([])
8080

8181
expect(globber.globArtifactString("path", "raw", false)).toEqual([])
82-
expect(warnMock).toBeCalled()
82+
expect(warnMock).toHaveBeenCalled()
8383
})
8484

8585
it("throws when no glob results are produced and empty results shouild throw", () => {

__tests__/ArtifactPathValidator.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@ describe("ArtifactPathValidator", () => {
3030
const validator = new ArtifactPathValidator(false, paths, pattern)
3131

3232
const result = validator.validate()
33-
expect(warnMock).toBeCalled()
33+
expect(warnMock).toHaveBeenCalled()
3434
expect(result).toEqual(["path2"])
3535
})
3636

3737
it("warns when no glob results are produced and empty results shouldn't throw", () => {
3838
const validator = new ArtifactPathValidator(false, [], pattern)
3939
const result = validator.validate()
40-
expect(warnMock).toBeCalled()
40+
expect(warnMock).toHaveBeenCalled()
4141
})
4242

4343
it("throws when no glob results are produced and empty results shouild throw", () => {

__tests__/Inputs.test.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -83,31 +83,31 @@ describe("Inputs", () => {
8383
mockGetInput.mockReturnValueOnce("art1").mockReturnValueOnce("contentType").mockReturnValueOnce("true")
8484

8585
expect(inputs.artifacts).toEqual(artifacts)
86-
expect(mockGlob).toBeCalledTimes(1)
87-
expect(mockGlob).toBeCalledWith("art1", "contentType", true)
86+
expect(mockGlob).toHaveBeenCalledTimes(1)
87+
expect(mockGlob).toHaveBeenCalledWith("art1", "contentType", true)
8888
})
8989

9090
it("returns empty artifacts", () => {
9191
mockGetInput.mockReturnValueOnce("").mockReturnValueOnce("")
9292

9393
expect(inputs.artifacts).toEqual([])
94-
expect(mockGlob).toBeCalledTimes(0)
94+
expect(mockGlob).toHaveBeenCalledTimes(0)
9595
})
9696

9797
it("returns input.artifacts", () => {
9898
mockGetInput.mockReturnValueOnce("art1").mockReturnValueOnce("contentType").mockReturnValueOnce("false")
9999

100100
expect(inputs.artifacts).toEqual(artifacts)
101-
expect(mockGlob).toBeCalledTimes(1)
102-
expect(mockGlob).toBeCalledWith("art1", "contentType", false)
101+
expect(mockGlob).toHaveBeenCalledTimes(1)
102+
expect(mockGlob).toHaveBeenCalledWith("art1", "contentType", false)
103103
})
104104

105105
it("returns input.artifacts with default contentType", () => {
106106
mockGetInput.mockReturnValueOnce("art1").mockReturnValueOnce("").mockReturnValueOnce("false")
107107

108108
expect(inputs.artifacts).toEqual(artifacts)
109-
expect(mockGlob).toBeCalledTimes(1)
110-
expect(mockGlob).toBeCalledWith("art1", "raw", false)
109+
expect(mockGlob).toHaveBeenCalledTimes(1)
110+
expect(mockGlob).toHaveBeenCalledWith("art1", "raw", false)
111111
})
112112

113113
it("returns input.artifact", () => {
@@ -118,8 +118,8 @@ describe("Inputs", () => {
118118
.mockReturnValueOnce("false")
119119

120120
expect(inputs.artifacts).toEqual(artifacts)
121-
expect(mockGlob).toBeCalledTimes(1)
122-
expect(mockGlob).toBeCalledWith("art2", "contentType", false)
121+
expect(mockGlob).toHaveBeenCalledTimes(1)
122+
expect(mockGlob).toHaveBeenCalledWith("art2", "contentType", false)
123123
})
124124
})
125125

__tests__/Outputs.test.ts

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ jest.mock("@actions/core", () => {
77
return { setOutput: mockSetOutput }
88
})
99

10+
const TEST_URLS = {
11+
HTML_URL: "https://api.example.com/assets",
12+
UPLOAD_URL: "https://api.example.com",
13+
TARBALL_URL: "https://api.example.com/tarball",
14+
ZIPBALL_URL: "https://api.example.com/zipball",
15+
} as const
16+
1017
describe("Outputs", () => {
1118
let outputs: Outputs
1219
let releaseData: ReleaseData
@@ -15,15 +22,30 @@ describe("Outputs", () => {
1522
outputs = new CoreOutputs()
1623
releaseData = {
1724
id: 1,
18-
html_url: "https://api.example.com/assets",
19-
upload_url: "https://api.example.com",
25+
html_url: TEST_URLS.HTML_URL,
26+
upload_url: TEST_URLS.UPLOAD_URL,
27+
tarball_url: TEST_URLS.TARBALL_URL,
28+
zipball_url: TEST_URLS.ZIPBALL_URL,
2029
}
2130
})
2231

2332
it("Applies the release data to the action output", () => {
2433
outputs.applyReleaseData(releaseData)
25-
expect(mockSetOutput).toBeCalledWith("id", releaseData.id)
26-
expect(mockSetOutput).toBeCalledWith("html_url", releaseData.html_url)
27-
expect(mockSetOutput).toBeCalledWith("upload_url", releaseData.upload_url)
34+
expect(mockSetOutput).toHaveBeenCalledWith("id", releaseData.id)
35+
expect(mockSetOutput).toHaveBeenCalledWith("html_url", releaseData.html_url)
36+
expect(mockSetOutput).toHaveBeenCalledWith("upload_url", releaseData.upload_url)
37+
expect(mockSetOutput).toHaveBeenCalledWith("tarball_url", releaseData.tarball_url)
38+
expect(mockSetOutput).toHaveBeenCalledWith("zipball_url", releaseData.zipball_url)
39+
})
40+
41+
it("Handles null tarball_url and zipball_url", () => {
42+
const releaseDataWithNulls = {
43+
...releaseData,
44+
tarball_url: null,
45+
zipball_url: null,
46+
}
47+
outputs.applyReleaseData(releaseDataWithNulls)
48+
expect(mockSetOutput).toHaveBeenCalledWith("tarball_url", "")
49+
expect(mockSetOutput).toHaveBeenCalledWith("zipball_url", "")
2850
})
2951
})

0 commit comments

Comments
 (0)