Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,19 @@ All notable changes to this project will be documented in this file. See [conven
---
## [Unreleased](https://github.com/ryancyq/github-signed-commit/tree/HEAD)

### Bug Fixes

- handle binary content properly ([#9](https://github.com/ryancyq/github-signed-commit/issues/9)) - ([b793b7c](https://github.com/ryancyq/github-signed-commit/commit/b793b7cec39f3659d9a29f030223994686cbb01f)) - Xavier Krantz

### Documentation

- add support to repository input - ([f3899e6](https://github.com/ryancyq/github-signed-commit/commit/f3899e6baca1f1580ac3516468dd170a47a84d6f)) - Ryan Chang

### Features

- allow customized repository with owner - ([8f42b12](https://github.com/ryancyq/github-signed-commit/commit/8f42b1246b6287f96b2c628ed756d1debc681b3e)) - Ryan Chang
- Add support for remote GitHub repository + working directory ([#2](https://github.com/ryancyq/github-signed-commit/issues/2)) - ([9f01b63](https://github.com/ryancyq/github-signed-commit/commit/9f01b63120591cae14729ff96261d66a7fd7e4eb)) - Xavier Krantz
- Add support for Tags push events ([#3](https://github.com/ryancyq/github-signed-commit/issues/3)) - ([5d85f5f](https://github.com/ryancyq/github-signed-commit/commit/5d85f5f027d01342eff841614fe2a17e7e06925c)) - Xavier Krantz

### Tests

Expand Down
16 changes: 13 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,9 @@ Note: The `GH_TOKEN` environment variable is **required** for GitHub API request
| `files` | **YES** | Multi-line string of file paths to be committed, relative to the current workspace.|
| `workspace` | **NO** | Directory containing files to be committed. **DEFAULT:** GitHub workspace directory (root of the repository). |
| `commit-message` | **YES** | Commit message for the file changes. |
| `repository` | **NO** | Repository name including owner (e.g. owner/repo). **DEFAULT:** Workflow triggered repository |
| `branch-name` | **NO** | Branch to commit, it must already exist in the remote. **DEFAULT:** Workflow triggered branch |
| `owner` | **NO** | GitHub repository owner (user or organization), defaults to the repo invoking the action. |
| `repo` | **NO** | GitHub repository name, defaults to the repo invoking the action. |
| `branch-name` | **NO*** | Branch to commit, it must already exist in the remote. **DEFAULT:** Workflow triggered branch. **REQUIRED:** If triggered through `on tags`.|
| `branch-push-force` | **NO** | `--force` flag when running `git push <branch-name>`. |
| `tag` | **NO** | Push tag for the new/current commit. |
| `tag-only-if-file-changes` | **NO** | Push tag for new commit only when file changes present. **DEFAULT:** true |
Expand All @@ -75,9 +76,18 @@ Note: The `GH_TOKEN` environment variable is **required** for GitHub API request
| `commit-sha` | Full SHA of the signed commit. |
| `tag` | Tag of the signed commit. |

## Release

This project follows [Conventional Commits](https://www.conventionalcommits.org/) and uses a manual release workflow.

1. Ensure `dist/` is up-to-date by running `npm run bundle`
2. Trigger the **Release** workflow via `workflow_dispatch` with the desired [semver](https://semver.org/) version
- The workflow bumps `package.json`, creates a signed commit, and tags `v{version}`
3. The **Changelog** workflow automatically regenerates `CHANGELOG.md` from conventional commits using [git-cliff](https://git-cliff.org/)

[ci_badge]: https://github.com/ryancyq/github-signed-commit/actions/workflows/ci.yml/badge.svg
[ci_workflows]: https://github.com/ryancyq/github-signed-commit/actions/workflows/ci.yml
[coverage_badge]: https://codecov.io/gh/ryancyq/github-signed-commit/graph/badge.svg?token=KZTD2F2MN2
[coverage]: https://codecov.io/gh/ryancyq/github-signed-commit
[maintainability_badge]: https://api.codeclimate.com/v1/badges/0de9dbec270ca85719c6/maintainability
[maintainability]: https://codeclimate.com/github/ryancyq/github-signed-commit/maintainability
[maintainability]: https://codeclimate.com/github/ryancyq/github-signed-commit/maintainability
17 changes: 17 additions & 0 deletions __tests__/blob.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,23 @@ describe('Blob', () => {
})
})

it('binary file successfully', async () => {
const binaryContent = Buffer.from([
0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0xff, 0xfe, 0x00, 0x80,
0xc0, 0xc1, 0xf5, 0xf6,
])
const binaryPath = join(__dirname, 'fixtures', 'blob.bin')
fs.writeFileSync(binaryPath, binaryContent)

try {
const blob = getBlob('fixtures/blob.bin')
const fileAddition = await blob.load()
expect(fileAddition.contents).toEqual(binaryContent.toString('base64'))
} finally {
fs.unlinkSync(binaryPath)
}
})

it('stream with error', async () => {
const blob = getBlob('fixtures/error.txt')
const mockStream = new PassThrough()
Expand Down
4 changes: 2 additions & 2 deletions __tests__/git.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ describe('Git CLI', () => {

describe('git add', () => {
beforeEach(() => {
jest.spyOn(cwd, 'getWorkspace').mockReturnValue('/test-workspace')
jest.spyOn(cwd, 'getWorkspace').mockReturnValue('test-workspace/')
})

it('should ensure file paths are within curent working directory', async () => {
Expand All @@ -191,7 +191,7 @@ describe('Git CLI', () => {
await addFileChanges(['*.ts', '~/.bashrc'])
expect(execMock).toHaveBeenCalledWith(
'git',
['add', '--', '/test-workspace/*.ts', '/test-workspace/~/.bashrc'],
['add', '--', 'test-workspace/*.ts', 'test-workspace/~/.bashrc'],
expect.objectContaining({
listeners: { stdline: expect.anything(), errline: expect.anything() },
})
Expand Down
36 changes: 0 additions & 36 deletions __tests__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,42 +205,6 @@ describe('action', () => {
})
})

describe('input repository is given', () => {
describe('valid format', () => {
beforeEach(() => {
jest.spyOn(core, 'getInput').mockImplementation((name, _option) => {
if (name == 'repository') return 'the-user/the-repo'
return ''
})
})

it('succeed', async () => {
const setFailedMock = jest.spyOn(core, 'setFailed').mockReturnValue()
await main.run()
expect(setFailedMock).toHaveBeenCalledWith(
'Neither files nor tag input has been configured'
)
})
})

describe('invalid format', () => {
beforeEach(() => {
jest.spyOn(core, 'getInput').mockImplementation((name, _option) => {
if (name == 'repository') return 'the-user-the-repo'
return ''
})
})

it('fails', async () => {
const setFailedMock = jest.spyOn(core, 'setFailed').mockReturnValue()
await main.run()
expect(setFailedMock).toHaveBeenCalledWith(
'Input <repository> "the-user-the-repo" is invalid'
)
})
})
})

describe('input branch is given', () => {
beforeEach(() => {
jest.spyOn(core, 'getMultilineInput').mockReturnValue(['/test.txt'])
Expand Down
14 changes: 14 additions & 0 deletions __tests__/stream/base64-encoder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,18 @@ describe('Base64 Encoder', () => {
const streamedContent = Buffer.concat(chunks).toString('utf8')
expect(streamedContent).toEqual(Buffer.from(content).toString('base64'))
})

it('binary buffer stream', async () => {
const binaryContent = Buffer.from([
0x89, 0x50, 0x4e, 0x47, 0xff, 0xfe, 0x00, 0x80, 0xc0, 0xc1,
])
const stream = Readable.from(binaryContent).pipe(new Base64Encoder())

const chunks: Buffer[] = []
for await (const chunk of stream) {
chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk))
}
const streamedContent = Buffer.concat(chunks).toString('utf8')
expect(streamedContent).toEqual(binaryContent.toString('base64'))
})
})
14 changes: 11 additions & 3 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,23 @@ inputs:
Directory containing files to be committed. Default: GitHub workspace directory (root of repository).
required: false
default: ''
workdir:
description: |
Directory where the action should run. Default: GitHub workspace directory (root of repository from where the GH Workflow is triggered).
required: false
default: ''
commit-message:
description: |
Commit message for the file changes.
required: false
repository:
owner:
description: |
Repository name including owner (e.g. owner/repo). Default: Workflow triggered repository.
GitHub repository owner (user or organization), defaults to the repo invoking the action.
required: false
repo:
description: |
GitHub repository name, defaults to the repo invoking the action.
required: false
default: ''
branch-name:
description: |
Branch to commit to. Default: Workflow triggered branch.
Expand Down
Loading