Skip to content

Commit c633a68

Browse files
authored
feat: create signed commit action (#1)
1 parent 0e2f087 commit c633a68

43 files changed

Lines changed: 3944 additions & 2 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.editorconfig

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
root = true
2+
3+
[*]
4+
indent_style = space
5+
indent_size = 4
6+
charset = utf-8
7+
trim_trailing_whitespace = true
8+
insert_final_newline = true
9+
10+
[{*.yml,*.yaml}]
11+
indent_size = 2

.github/renovate.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
3+
"extends": ["github>statens-pensjonskasse/renovate-presets:weekly-grouped-non-major"]
4+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: Build & Release
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
workflow_dispatch:
9+
10+
jobs:
11+
build-and-publish:
12+
uses: statens-pensjonskasse/public-actions-library/.github/workflows/build-action-node.yaml@558b9ead422abd24faaa3d54b1735b3f14a67fc5 #v0.2.5
13+
permissions:
14+
contents: write
15+
packages: write
16+
secrets: inherit
17+
with:
18+
node-version: '24'

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
node_modules/
2+
lib/
3+
.idea
4+

LICENSE

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
MIT License
2+
3+
Copyright (c) 2025 Statens Pensjonskasse (SPK)
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.
22+

README.md

Lines changed: 114 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,114 @@
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

action.yml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: 'Create Signed Commit'
2+
description: 'Create a signed commit using the GitHub API without pushing it'
3+
4+
inputs:
5+
working-directory:
6+
description: 'Working directory for git operations'
7+
required: false
8+
default: '.'
9+
token:
10+
description: 'GitHub token with permissions to access the repository'
11+
required: true
12+
message:
13+
description: 'The commit message'
14+
required: true
15+
repository:
16+
description: 'The repository in format owner/repo'
17+
required: false
18+
default: ${{ github.repository }}
19+
branch:
20+
description: 'The branch to create the commit on'
21+
required: false
22+
default: ${{ github.ref_name }}
23+
fail-on-no-changes:
24+
description: 'Fail if there are no changes to commit'
25+
required: false
26+
default: 'true'
27+
paths:
28+
description: 'Newline-separated list of file and/or folder paths to commit. If not specified, commits all changed files.'
29+
required: false
30+
fetch-commit:
31+
description: 'Fetch the created commit locally after creation'
32+
required: false
33+
default: 'true'
34+
push:
35+
description: 'Push the commit to the remote branch after creation'
36+
required: false
37+
default: 'false'
38+
parent-commit:
39+
description: 'SHA of the parent commit. If not specified, uses the current HEAD of the branch'
40+
required: false
41+
42+
outputs:
43+
commit-sha:
44+
description: 'The SHA of the created commit'
45+
tree-sha:
46+
description: 'The SHA of the created tree'
47+
48+
runs:
49+
using: 'node24'
50+
main: 'dist/index.js'

biome.json

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"$schema": "https://biomejs.dev/schemas/2.3.10/schema.json",
3+
"extends": ["@statens-pensjonskasse/biome/config"],
4+
"linter": {
5+
"enabled": true,
6+
"rules": {
7+
"recommended": true
8+
}
9+
},
10+
"formatter": {
11+
"enabled": true,
12+
"useEditorconfig": true,
13+
"formatWithErrors": false,
14+
"indentStyle": "space",
15+
"indentWidth": 4,
16+
"lineEnding": "lf",
17+
"lineWidth": 120,
18+
"attributePosition": "auto",
19+
"bracketSpacing": true
20+
},
21+
"javascript": {
22+
"formatter": {
23+
"jsxQuoteStyle": "double",
24+
"quoteProperties": "asNeeded",
25+
"trailingCommas": "all",
26+
"semicolons": "always",
27+
"arrowParentheses": "always",
28+
"bracketSameLine": false,
29+
"quoteStyle": "single",
30+
"attributePosition": "auto",
31+
"bracketSpacing": true
32+
}
33+
}
34+
}

dist/blob-creator.d.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import type * as github from '@actions/github';
2+
import type { FileChange } from './types';
3+
type Octokit = ReturnType<typeof github.getOctokit>;
4+
/**
5+
* Tree item for GitHub API
6+
*/
7+
interface TreeItem {
8+
path: string;
9+
mode: '100644' | '100755';
10+
type: 'blob';
11+
sha: string;
12+
}
13+
/**
14+
* Create blobs in batches to avoid overwhelming the API
15+
* @param files Array of file changes to create blobs for
16+
* @param octokit GitHub API client
17+
* @param owner Repository owner
18+
* @param repo Repository name
19+
* @param batchSize Number of blobs to create concurrently (default: 10)
20+
* @returns Array of tree items
21+
*/
22+
export declare function createBlobsInBatches(files: FileChange[], octokit: Octokit, owner: string, repo: string, batchSize?: number): Promise<TreeItem[]>;
23+
export {};

dist/commit-creator.d.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import type { ActionInputs, CommitResult } from './types';
2+
/**
3+
* Create a signed commit using the GitHub API
4+
* @param inputs The action inputs
5+
* @returns The commit and tree SHA
6+
*/
7+
export declare function createSignedCommit(inputs: ActionInputs): Promise<CommitResult>;

0 commit comments

Comments
 (0)