Commit via GitHub API
ActionsTags
(2)A modular GitHub Action that commits changes via GitHub API, creating automatically signed commits that can bypass repository rulesets.
- Repository: vig-os/commit-action
- Organization: vigOS
- Automatically signed commits - Commits created via GitHub API are signed by GitHub
- Bypasses rulesets - Uses GitHub API instead of git push, allowing to bypass branch protection rules
- Modular design - Can be used as a standalone action or imported as a module
- Type-safe - Written in TypeScript with full type safety
- Well tested - Comprehensive unit test coverage
- name: Commit and push changes via API
uses: vig-os/commit-action@v0.1.3
env:
GITHUB_TOKEN: ${{ steps.sync.outputs.app-token || steps.sync.outputs.github-token }}
GITHUB_REPOSITORY: ${{ github.repository }}
TARGET_BRANCH: refs/heads/main # Preferred: avoids conflicts with built-in GITHUB_REF
# OR use GITHUB_REF: refs/heads/main (may be overridden by workflow context)
COMMIT_MESSAGE: "chore: sync issues and PRs"
FILE_PATHS: ${{ steps.sync.outputs.modified-files || 'docs' }}npm run commitEnvironment variables:
GITHUB_TOKENorGH_TOKEN- GitHub token (app token or regular token)GITHUB_REPOSITORY- Repository in format "owner/repo" (defaults to context)TARGET_BRANCH- Preferred: Branch reference (e.g., "refs/heads/main" or just "main", defaults to workflow context)GITHUB_REF- Alternative branch reference (may conflict with GitHub's built-in variable if workflow runs on different branch)COMMIT_MESSAGE- Commit message (defaults to "chore: update files")FILE_PATHS- Comma-separated list of file paths or directories (or auto-detects from git status)BASE_SHA- Optional base commit SHA (defaults to branch HEAD)
Note: Use TARGET_BRANCH instead of GITHUB_REF to avoid conflicts when your workflow runs on a different branch than the target commit branch. GitHub Actions sets GITHUB_REF automatically based on the workflow trigger, which can override your explicit setting.
import { commitViaAPI } from './src/commit';
const result = await commitViaAPI({
token: 'your-token',
owner: 'owner',
repo: 'repo',
branch: 'dev',
message: 'chore: update files',
filePaths: ['file1.txt', 'file2.txt'],
});
console.log(`Committed ${result.commitSha}`);Main function to commit changes via GitHub API.
Options:
token: string- GitHub tokenowner: string- Repository ownerrepo: string- Repository namebranch: string- Branch namemessage: string- Commit messagefilePaths: string[]- Array of file paths to commitbaseSha?: string- Optional base commit SHA
Returns:
commitSha: string- SHA of the created committreeSha: string- SHA of the created treefilesCommitted: number- Number of files committed
# Install dependencies
npm install
# Run tests
npm test
# Build
npm run build
# Bundle for Actions (outputs to dist/index.js)
npm run bundle
# Run commit script
npm run commitSee LICENSE.
Commit via GitHub API is not certified by GitHub. It is provided by a third-party and is governed by separate terms of service, privacy policy, and support documentation.