Skip to content

Commit 853065c

Browse files
committed
feat: support signoff
Signed-off-by: andrea11 <10788630+andrea11@users.noreply.github.com>
1 parent de9ebbf commit 853065c

File tree

7 files changed

+69
-52
lines changed

7 files changed

+69
-52
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,12 @@ jobs:
208208
token: ${{ secrets.GH_TOKEN_FOR_UPDATES }}
209209
```
210210

211+
## Sign-off commit
212+
213+
The bot can produce commits with a sign-off. This is useful for projects that require a sign-off to be present in the commit message.
214+
To enable this, set the `signoff` input to `true`.
215+
216+
211217
## With GPG commit signing
212218

213219
It's possible for the bot to produce GPG-signed commits.

action.yml

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,14 @@ inputs:
3434
Automated changes by the [update-flake-lock](https://github.com/DeterminateSystems/update-flake-lock) GitHub Action.
3535
3636
```
37-
{{ env.GIT_COMMIT_MESSAGE }}
37+
{{ env.FLAKE_UPDATE_OUTPUT }}
3838
```
3939
4040
### Running GitHub Actions on this PR
4141
4242
GitHub Actions will not run workflows on pull requests which are opened by a GitHub Action.
4343
4444
**To run GitHub Actions workflows on this PR, close and re-open this pull request.**
45-
4645
pr-labels:
4746
description: "A comma or newline separated list of labels to set on the Pull Request to be created"
4847
required: false
@@ -75,6 +74,10 @@ inputs:
7574
description: "Set to true if the action should sign the commit with GPG"
7675
required: false
7776
default: "false"
77+
signoff:
78+
description: "Set to true if the action should add a Signed-off-by line to the commit message"
79+
required: false
80+
default: "false"
7881
gpg-private-key:
7982
description: "GPG Private Key with which to sign the commits in the PR to be created"
8083
required: false
@@ -175,15 +178,6 @@ runs:
175178
path: pr_body.template
176179
contents: ${{ inputs.pr-body }}
177180
env: {}
178-
- name: Set additional env variables (GIT_COMMIT_MESSAGE)
179-
shell: bash
180-
run: |
181-
DELIMITER=$(dd if=/dev/urandom bs=15 count=1 status=none | base64)
182-
COMMIT_MESSAGE="$(git log --format=%b -n 1)"
183-
echo "GIT_COMMIT_MESSAGE<<$DELIMITER" >> $GITHUB_ENV
184-
echo "$COMMIT_MESSAGE" >> $GITHUB_ENV
185-
echo "$DELIMITER" >> $GITHUB_ENV
186-
echo "GIT_COMMIT_MESSAGE is: ${COMMIT_MESSAGE}"
187181
- name: Interpolate PR Body
188182
uses: pedrolamas/handlebars-action@2995d7eadacbc8f2f6ab8431a01d84a5fa3b8bb4 # v2.4.0
189183
with:
@@ -207,6 +201,10 @@ runs:
207201
base: ${{ inputs.base }}
208202
branch: ${{ inputs.branch }}
209203
delete-branch: true
204+
commit-message: |
205+
${{ inputs.commit-msg }}
206+
207+
${{ env.FLAKE_UPDATE_OUTPUT }}
210208
committer: ${{ env.GIT_COMMITTER_NAME }} ${{ env.GIT_COMMITTER_EMAIL }}
211209
author: ${{ env.GIT_AUTHOR_NAME }} ${{ env.GIT_AUTHOR_EMAIL }}
212210
title: ${{ inputs.pr-title }}
@@ -215,3 +213,4 @@ runs:
215213
labels: ${{ inputs.pr-labels }}
216214
reviewers: ${{ inputs.pr-reviewers }}
217215
body: ${{ steps.pr_body.outputs.content }}
216+
signoff: ${{ inputs.signoff }}

dist/index.js

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -95249,35 +95249,33 @@ function makeOptionsConfident(actionOptions) {
9524995249
* Copyright (c) 2018-2020 [Samuel Carreira]
9525095250
*/
9525195251
//# sourceMappingURL=index.js.map
95252+
// EXTERNAL MODULE: external "stream"
95253+
var external_stream_ = __nccwpck_require__(2203);
9525295254
;// CONCATENATED MODULE: ./dist/index.js
9525395255
// src/nix.ts
95254-
function makeNixCommandArgs(nixOptions, flakeInputs, commitMessage) {
95256+
function makeNixCommandArgs(nixOptions, flakeInputs) {
9525595257
const flakeInputFlags = flakeInputs.flatMap((input) => [
9525695258
"--update-input",
9525795259
input
9525895260
]);
95259-
const lockfileSummaryFlags = [
95260-
"--option",
95261-
"commit-lockfile-summary",
95262-
commitMessage
95263-
];
9526495261
const updateLockMechanism = flakeInputFlags.length === 0 ? "update" : "lock";
95265-
return nixOptions.concat(["flake", updateLockMechanism]).concat(flakeInputFlags).concat(["--commit-lock-file"]).concat(lockfileSummaryFlags);
95262+
return nixOptions.concat(["flake", updateLockMechanism]).concat(flakeInputFlags);
9526695263
}
9526795264

9526895265
// src/index.ts
9526995266

9527095267

9527195268

95269+
9527295270
var EVENT_EXECUTION_FAILURE = "execution_failure";
95271+
var COMMIT_MESSAGE_MAX_LENGTH = 65536;
9527395272
var UpdateFlakeLockAction = class extends DetSysAction {
9527495273
constructor() {
9527595274
super({
9527695275
name: "update-flake-lock",
9527795276
fetchStyle: "universal",
9527895277
requireNix: "fail"
9527995278
});
95280-
this.commitMessage = inputs_exports.getString("commit-msg");
9528195279
this.flakeInputs = inputs_exports.getArrayOfStrings("inputs", "space");
9528295280
this.nixOptions = inputs_exports.getArrayOfStrings("nix-options", "space");
9528395281
this.pathToFlakeDir = inputs_exports.getStringOrNull("path-to-flake-dir");
@@ -95291,20 +95289,25 @@ var UpdateFlakeLockAction = class extends DetSysAction {
9529195289
async update() {
9529295290
const nixCommandArgs = makeNixCommandArgs(
9529395291
this.nixOptions,
95294-
this.flakeInputs,
95295-
this.commitMessage
95292+
this.flakeInputs
9529695293
);
9529795294
core.debug(
9529895295
JSON.stringify({
9529995296
options: this.nixOptions,
9530095297
inputs: this.flakeInputs,
95301-
message: this.commitMessage,
9530295298
args: nixCommandArgs
9530395299
})
9530495300
);
95301+
let output = "";
9530595302
const execOptions = {
9530695303
cwd: this.pathToFlakeDir !== null ? this.pathToFlakeDir : void 0,
95307-
ignoreReturnCode: true
95304+
ignoreReturnCode: true,
95305+
outStream: new external_stream_.Writable({
95306+
write: (chunk, _, callback) => {
95307+
output += chunk.toString();
95308+
callback();
95309+
}
95310+
})
9530895311
};
9530995312
const exitCode = await exec.exec("nix", nixCommandArgs, execOptions);
9531095313
if (exitCode !== 0) {
@@ -95314,6 +95317,15 @@ var UpdateFlakeLockAction = class extends DetSysAction {
9531495317
core.setFailed(`non-zero exit code of ${exitCode} detected`);
9531595318
} else {
9531695319
core.info(`flake.lock file was successfully updated`);
95320+
if (output.length > COMMIT_MESSAGE_MAX_LENGTH) {
95321+
core.warning(
95322+
`commit message is too long, truncating to ${COMMIT_MESSAGE_MAX_LENGTH} characters`
95323+
);
95324+
}
95325+
core.exportVariable(
95326+
"FLAKE_UPDATE_OUTPUT",
95327+
output.trim().slice(0, COMMIT_MESSAGE_MAX_LENGTH)
95328+
);
9531795329
}
9531895330
}
9531995331
};

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.lock

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/index.ts

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@ import { makeNixCommandArgs } from "./nix.js";
22
import * as actionsCore from "@actions/core";
33
import * as actionsExec from "@actions/exec";
44
import { DetSysAction, inputs } from "detsys-ts";
5+
import { Writable } from "stream";
56

67
const EVENT_EXECUTION_FAILURE = "execution_failure";
8+
const COMMIT_MESSAGE_MAX_LENGTH = 65536;
79

810
class UpdateFlakeLockAction extends DetSysAction {
9-
private commitMessage: string;
1011
private nixOptions: string[];
1112
private flakeInputs: string[];
1213
private pathToFlakeDir: string | null;
@@ -18,7 +19,6 @@ class UpdateFlakeLockAction extends DetSysAction {
1819
requireNix: "fail",
1920
});
2021

21-
this.commitMessage = inputs.getString("commit-msg");
2222
this.flakeInputs = inputs.getArrayOfStrings("inputs", "space");
2323
this.nixOptions = inputs.getArrayOfStrings("nix-options", "space");
2424
this.pathToFlakeDir = inputs.getStringOrNull("path-to-flake-dir");
@@ -33,28 +33,34 @@ class UpdateFlakeLockAction extends DetSysAction {
3333

3434
async update(): Promise<void> {
3535
// Nix command of this form:
36-
// nix ${maybe nix options} flake ${"update" or "lock"} ${maybe --update-input flags} --commit-lock-file --commit-lockfile-summary ${commit message}
36+
// nix ${maybe nix options} flake ${"update" or "lock"} ${maybe --update-input flags}
3737
// Example commands:
38-
// nix --extra-substituters https://example.com flake lock --update-input nixpkgs --commit-lock-file --commit-lockfile-summary "updated flake.lock"
39-
// nix flake update --commit-lock-file --commit-lockfile-summary "updated flake.lock"
38+
// nix --extra-substituters https://example.com flake lock --update-input nixpkgs
39+
// nix flake update
4040
const nixCommandArgs: string[] = makeNixCommandArgs(
4141
this.nixOptions,
4242
this.flakeInputs,
43-
this.commitMessage,
4443
);
4544

4645
actionsCore.debug(
4746
JSON.stringify({
4847
options: this.nixOptions,
4948
inputs: this.flakeInputs,
50-
message: this.commitMessage,
5149
args: nixCommandArgs,
5250
}),
5351
);
5452

53+
let output = "";
54+
5555
const execOptions: actionsExec.ExecOptions = {
5656
cwd: this.pathToFlakeDir !== null ? this.pathToFlakeDir : undefined,
5757
ignoreReturnCode: true,
58+
outStream: new Writable({
59+
write: (chunk, _, callback) => {
60+
output += chunk.toString();
61+
callback();
62+
},
63+
}),
5864
};
5965

6066
const exitCode = await actionsExec.exec("nix", nixCommandArgs, execOptions);
@@ -66,6 +72,15 @@ class UpdateFlakeLockAction extends DetSysAction {
6672
actionsCore.setFailed(`non-zero exit code of ${exitCode} detected`);
6773
} else {
6874
actionsCore.info(`flake.lock file was successfully updated`);
75+
if (output.length > COMMIT_MESSAGE_MAX_LENGTH) {
76+
actionsCore.warning(
77+
`commit message is too long, truncating to ${COMMIT_MESSAGE_MAX_LENGTH} characters`,
78+
);
79+
}
80+
actionsCore.exportVariable(
81+
"FLAKE_UPDATE_OUTPUT",
82+
output.trim().slice(0, COMMIT_MESSAGE_MAX_LENGTH),
83+
);
6984
}
7085
}
7186
}

0 commit comments

Comments
 (0)