Skip to content

Commit b793b7c

Browse files
authored
fix: handle binary content properly (#9)
Signed-off-by: Xavier Krantz <xavier.krantz@datadome.co>
1 parent 2dee538 commit b793b7c

File tree

9 files changed

+1854
-1405
lines changed

9 files changed

+1854
-1405
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,15 @@ Note: The `GH_TOKEN` environment variable is **required** for GitHub API request
7676
| `commit-sha` | Full SHA of the signed commit. |
7777
| `tag` | Tag of the signed commit. |
7878

79+
## Release
80+
81+
This project follows [Conventional Commits](https://www.conventionalcommits.org/) and uses a manual release workflow.
82+
83+
1. Ensure `dist/` is up-to-date by running `npm run bundle`
84+
2. Trigger the **Release** workflow via `workflow_dispatch` with the desired [semver](https://semver.org/) version
85+
- The workflow bumps `package.json`, creates a signed commit, and tags `v{version}`
86+
3. The **Changelog** workflow automatically regenerates `CHANGELOG.md` from conventional commits using [git-cliff](https://git-cliff.org/)
87+
7988
[ci_badge]: https://github.com/ryancyq/github-signed-commit/actions/workflows/ci.yml/badge.svg
8089
[ci_workflows]: https://github.com/ryancyq/github-signed-commit/actions/workflows/ci.yml
8190
[coverage_badge]: https://codecov.io/gh/ryancyq/github-signed-commit/graph/badge.svg?token=KZTD2F2MN2

__tests__/blob.test.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,23 @@ describe('Blob', () => {
8686
})
8787
})
8888

89+
it('binary file successfully', async () => {
90+
const binaryContent = Buffer.from([
91+
0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0xff, 0xfe, 0x00, 0x80,
92+
0xc0, 0xc1, 0xf5, 0xf6,
93+
])
94+
const binaryPath = join(__dirname, 'fixtures', 'blob.bin')
95+
fs.writeFileSync(binaryPath, binaryContent)
96+
97+
try {
98+
const blob = getBlob('fixtures/blob.bin')
99+
const fileAddition = await blob.load()
100+
expect(fileAddition.contents).toEqual(binaryContent.toString('base64'))
101+
} finally {
102+
fs.unlinkSync(binaryPath)
103+
}
104+
})
105+
89106
it('stream with error', async () => {
90107
const blob = getBlob('fixtures/error.txt')
91108
const mockStream = new PassThrough()

__tests__/main.test.ts

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -205,42 +205,6 @@ describe('action', () => {
205205
})
206206
})
207207

208-
describe('input repository is given', () => {
209-
describe('valid format', () => {
210-
beforeEach(() => {
211-
jest.spyOn(core, 'getInput').mockImplementation((name, _option) => {
212-
if (name == 'repository') return 'the-user/the-repo'
213-
return ''
214-
})
215-
})
216-
217-
it('succeed', async () => {
218-
const setFailedMock = jest.spyOn(core, 'setFailed').mockReturnValue()
219-
await main.run()
220-
expect(setFailedMock).toHaveBeenCalledWith(
221-
'Neither files nor tag input has been configured'
222-
)
223-
})
224-
})
225-
226-
describe('invalid format', () => {
227-
beforeEach(() => {
228-
jest.spyOn(core, 'getInput').mockImplementation((name, _option) => {
229-
if (name == 'repository') return 'the-user-the-repo'
230-
return ''
231-
})
232-
})
233-
234-
it('fails', async () => {
235-
const setFailedMock = jest.spyOn(core, 'setFailed').mockReturnValue()
236-
await main.run()
237-
expect(setFailedMock).toHaveBeenCalledWith(
238-
'Input <repository> "the-user-the-repo" is invalid'
239-
)
240-
})
241-
})
242-
})
243-
244208
describe('input branch is given', () => {
245209
beforeEach(() => {
246210
jest.spyOn(core, 'getMultilineInput').mockReturnValue(['/test.txt'])

__tests__/stream/base64-encoder.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,18 @@ describe('Base64 Encoder', () => {
1515
const streamedContent = Buffer.concat(chunks).toString('utf8')
1616
expect(streamedContent).toEqual(Buffer.from(content).toString('base64'))
1717
})
18+
19+
it('binary buffer stream', async () => {
20+
const binaryContent = Buffer.from([
21+
0x89, 0x50, 0x4e, 0x47, 0xff, 0xfe, 0x00, 0x80, 0xc0, 0xc1,
22+
])
23+
const stream = Readable.from(binaryContent).pipe(new Base64Encoder())
24+
25+
const chunks: Buffer[] = []
26+
for await (const chunk of stream) {
27+
chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk))
28+
}
29+
const streamedContent = Buffer.concat(chunks).toString('utf8')
30+
expect(streamedContent).toEqual(binaryContent.toString('base64'))
31+
})
1832
})

0 commit comments

Comments
 (0)