|
1 | 1 | import * as fs from 'node:fs'; |
2 | 2 | import * as path from 'node:path'; |
3 | 3 | import * as process from 'node:process'; |
| 4 | +import { inspect } from 'node:util'; |
4 | 5 |
|
5 | 6 | import * as core from '@actions/core'; |
6 | 7 | import * as github from '@actions/github'; |
@@ -69,13 +70,25 @@ export async function run(): Promise<void> { |
69 | 70 | const token = core.getInput('token', { required: true }); |
70 | 71 |
|
71 | 72 | // Optional inputs |
| 73 | + const authorEmail = core.getInput('author-email'); |
| 74 | + const authorName = core.getInput('author-name'); |
72 | 75 | const ref = core.getInput('ref') || (await getHeadRef()); |
73 | 76 | const failOnNoChanges = core.getBooleanInput('fail-on-no-changes'); |
74 | 77 | const force = core.getBooleanInput('force'); |
75 | 78 | const owner = core.getInput('owner') || github.context.repo.owner; |
76 | 79 | const repo = core.getInput('repository') || github.context.repo.repo; |
77 | 80 | const workingDirectory = core.getInput('working-directory'); |
78 | 81 |
|
| 82 | + if (authorEmail && !authorName) { |
| 83 | + core.setFailed('Input required and not supplied: author-name'); |
| 84 | + return; |
| 85 | + } |
| 86 | + |
| 87 | + if (!authorEmail && authorName) { |
| 88 | + core.setFailed('Input required and not supplied: author-email'); |
| 89 | + return; |
| 90 | + } |
| 91 | + |
79 | 92 | if (workingDirectory) { |
80 | 93 | process.chdir(workingDirectory); |
81 | 94 | } |
@@ -117,13 +130,28 @@ export async function run(): Promise<void> { |
117 | 130 | }); |
118 | 131 | core.debug(`New tree SHA: ${newTree.data.sha}`); |
119 | 132 |
|
120 | | - const newCommit = await octokit.rest.git.createCommit({ |
| 133 | + core.debug(`Creating commit with committer: ${process.env.GIT_COMMITTER_NAME} <${process.env.GIT_COMMITTER_EMAIL}>`); |
| 134 | + |
| 135 | + const createCommitParams: Endpoints['POST /repos/{owner}/{repo}/git/commits']['parameters'] = { |
121 | 136 | owner, |
122 | 137 | repo, |
| 138 | + // committer: { |
| 139 | + // name: process.env.GIT_COMMITTER_NAME, |
| 140 | + // email: process.env.GIT_COMMITTER_EMAIL |
| 141 | + // }, |
123 | 142 | parents: [await getHeadSha()], |
124 | 143 | message, |
125 | 144 | tree: newTree.data.sha |
126 | | - }); |
| 145 | + }; |
| 146 | + if (authorEmail && authorName) { |
| 147 | + core.debug(`Creating commit with author: ${authorName} <${authorEmail}>`); |
| 148 | + createCommitParams.author = { |
| 149 | + name: authorName, |
| 150 | + email: authorEmail |
| 151 | + }; |
| 152 | + } |
| 153 | + const newCommit = await octokit.rest.git.createCommit(createCommitParams); |
| 154 | + core.debug(`New commit author: ${newCommit.data.author?.email}`); |
127 | 155 | core.debug(`New commit SHA: ${newCommit.data.sha}`); |
128 | 156 |
|
129 | 157 | try { |
@@ -160,6 +188,7 @@ export async function run(): Promise<void> { |
160 | 188 | core.setOutput('sha', newCommit.data.sha); |
161 | 189 | } catch (error) { |
162 | 190 | // Fail the workflow run if an error occurs |
| 191 | + core.debug(inspect(error)); |
163 | 192 | if (error instanceof Error && error.stack) core.debug(error.stack); |
164 | 193 | core.setFailed( |
165 | 194 | error instanceof Error ? error.message : JSON.stringify(error) |
|
0 commit comments