|
1 | | -# gha-create-signed-commit |
2 | | -gha-create-signed-commit eies og forvaltes av team-appark |
| 1 | +# Create Signed Commit Action |
| 2 | + |
| 3 | +Creates a signed commit using the GitHub API without pushing it, allowing batch commit operations. |
| 4 | + |
| 5 | +<!-- START doctoc generated TOC please keep comment here to allow auto update --> |
| 6 | +<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE --> |
| 7 | +## Table of Contents |
| 8 | + |
| 9 | +- [Quick Start](#quick-start) |
| 10 | +- [Inputs](#inputs) |
| 11 | +- [Outputs](#outputs) |
| 12 | +- [Multiple Commits Example](#multiple-commits-example) |
| 13 | +- [Notes](#notes) |
| 14 | + |
| 15 | +<!-- END doctoc generated TOC please keep comment here to allow auto update --> |
| 16 | + |
| 17 | +## Quick Start |
| 18 | + |
| 19 | +```yaml |
| 20 | +# Commit all changed files on current branch |
| 21 | +- uses: statens-pensjonskasse/github-actions-library/actions/versioning/create-signed-commit@COMMIT_SHA # vX.X.X |
| 22 | + with: |
| 23 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 24 | + message: 'Update files' |
| 25 | + |
| 26 | +# Commit specific paths (files, folders, wildcards) |
| 27 | +- uses: statens-pensjonskasse/github-actions-library/actions/versioning/create-signed-commit@COMMIT_SHA # vX.X.X |
| 28 | + with: |
| 29 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 30 | + message: 'Update config' |
| 31 | + paths: | |
| 32 | + config/ |
| 33 | + README.md |
| 34 | + actions/*/dist |
| 35 | +
|
| 36 | +# Commit and push immediately |
| 37 | +- uses: statens-pensjonskasse/github-actions-library/actions/versioning/create-signed-commit@COMMIT_SHA # vX.X.X |
| 38 | + with: |
| 39 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 40 | + message: 'Update and push' |
| 41 | + push: true |
| 42 | + |
| 43 | +# Create commit from specific parent |
| 44 | +- uses: statens-pensjonskasse/github-actions-library/actions/versioning/create-signed-commit@COMMIT_SHA # vX.X.X |
| 45 | + with: |
| 46 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 47 | + message: 'Cherry-pick changes' |
| 48 | + parent-commit: 'abc123def456' |
| 49 | +``` |
| 50 | +
|
| 51 | +## Inputs |
| 52 | +
|
| 53 | +| Name | Required | Default | Description | |
| 54 | +| ------ | ---------- | ------- | ------------- | |
| 55 | +| `token` | Yes | | GitHub token with write permissions | |
| 56 | +| `message` | Yes | | Commit message | |
| 57 | +| `branch` | No | Current branch | Branch to commit to | |
| 58 | +| `paths` | No | All changes | Paths to commit (files, folders, wildcards; newline-separated) | |
| 59 | +| `repository` | No | Current repo | Repository in `owner/repo` format | |
| 60 | +| `working-directory` | No | `.` | Working directory | |
| 61 | +| `fail-on-no-changes` | No | `true` | Fail if no changes detected | |
| 62 | +| `fetch-commit` | No | `true` | Fetch the created commit locally | |
| 63 | +| `push` | No | `false` | Push the commit to the remote branch after creation | |
| 64 | +| `parent-commit` | No | Current branch HEAD | SHA of the parent commit (must be a valid 40-character Git SHA-1 hash) | |
| 65 | + |
| 66 | +## Outputs |
| 67 | + |
| 68 | +- `commit-sha` - SHA of the created commit |
| 69 | +- `tree-sha` - SHA of the created tree |
| 70 | + |
| 71 | +## Multiple Commits Example |
| 72 | + |
| 73 | +Create multiple commits and push them together: |
| 74 | + |
| 75 | +```yaml |
| 76 | +- name: Create release commit |
| 77 | + id: release_commit |
| 78 | + uses: statens-pensjonskasse/github-actions-library/actions/versioning/create-signed-commit@COMMIT_SHA # vX.X.X |
| 79 | + with: |
| 80 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 81 | + branch: main |
| 82 | + message: 'chore: release version 1.0.0' |
| 83 | + paths: pom.xml |
| 84 | +
|
| 85 | +- name: Create snapshot commit |
| 86 | + id: snapshot_commit |
| 87 | + uses: statens-pensjonskasse/github-actions-library/actions/versioning/create-signed-commit@COMMIT_SHA # vX.X.X |
| 88 | + with: |
| 89 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 90 | + branch: main |
| 91 | + message: 'chore: update to snapshot version' |
| 92 | + paths: pom.xml |
| 93 | +
|
| 94 | +- name: Push both commits |
| 95 | + uses: actions/github-script@v7 # 60a0d83039c74a4aee543508d2ffcb1c3799cdea |
| 96 | + with: |
| 97 | + script: | |
| 98 | + // Pushing the last commit SHA pushes all commits in the chain |
| 99 | + await github.rest.git.updateRef({ |
| 100 | + owner: context.repo.owner, |
| 101 | + repo: context.repo.repo, |
| 102 | + ref: 'heads/main', |
| 103 | + sha: '${{ steps.snapshot_commit.outputs.commit-sha }}', |
| 104 | + force: false |
| 105 | + }); |
| 106 | +``` |
| 107 | + |
| 108 | +## Notes |
| 109 | + |
| 110 | +- Commits are automatically signed by GitHub |
| 111 | +- Commits are chained - pushing the last commit SHA pushes all parent commits |
| 112 | +- Use `force: false` to prevent accidental overwrites |
| 113 | +- Token needs `contents: write` permission |
| 114 | +- Branch protection rules apply |
0 commit comments