Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,31 @@ jobs:
inputs: input1 input2 input3
```

## Example updating specific flake(s)
```yaml
name: update-flake-lock

on:
workflow_dispatch: # allows manual triggering
schedule:
- cron: '0 0 * * 0' # runs weekly on Sunday at 00:00

jobs:
lockfile:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install Determinate Nix
uses: DeterminateSystems/determinate-nix-action@v3
- name: Update flake.lock
uses: DeterminateSystems/update-flake-lock@main
with:
flakes: |
flake-1/
flake-2/
```

## Example adding options to nix command

It's also possible to use specific options to the `nix` command in a space-separated list:
Expand Down
22 changes: 17 additions & 5 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,17 @@ inputs:
description: "A space-separated list of inputs to update. Leave empty to update all inputs."
required: false
default: ""
flakes:
description: "Flakes to update, one per line. If not provided, the action will look for a `flake.nix` file in the root of the repository."
required: false
default: ""
token:
description: "GITHUB_TOKEN or a `repo` scoped Personal Access Token (PAT)"
required: false
default: ${{ github.token }}
commit-msg:
description: "The message provided with the commit"
required: false
default: "flake.lock: Update"
base:
description: "Sets the pull request base branch. Defaults to the branch checked out in the workflow."
required: false
Expand All @@ -33,9 +36,7 @@ inputs:
default: |
Automated changes by the [update-flake-lock](https://github.com/DeterminateSystems/update-flake-lock) GitHub Action.

```
{{ env.GIT_COMMIT_MESSAGE }}
```

### Running GitHub Actions on this PR

Expand Down Expand Up @@ -140,6 +141,10 @@ runs:
echo "GIT_AUTHOR_EMAIL=<${{ inputs.git-author-email }}>" >> $GITHUB_ENV
echo "GIT_COMMITTER_NAME=${{ inputs.git-committer-name }}" >> $GITHUB_ENV
echo "GIT_COMMITTER_EMAIL=<${{ inputs.git-committer-email }}>" >> $GITHUB_ENV
- name: Get pre-update commit hash
id: pre-update
shell: bash
run: echo "value=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
- name: Run update-flake-lock
shell: bash
run: node "$GITHUB_ACTION_PATH/dist/index.js"
Expand All @@ -149,6 +154,7 @@ runs:
INPUT_BASE: ${{ inputs.base }}
INPUT_BRANCH: ${{ inputs.branch }}
INPUT_COMMIT-MSG: ${{ inputs.commit-msg }}
INPUT_FLAKES: ${{ inputs.flakes }}
INPUT_GIT-AUTHOR-EMAIL: ${{ inputs.git-author-email }}
INPUT_GIT-AUTHOR-NAME: ${{ inputs.git-author-name }}
INPUT_GIT-COMMITTER-EMAIL: ${{ inputs.git-committer-email }}
Expand Down Expand Up @@ -179,11 +185,17 @@ runs:
shell: bash
run: |
DELIMITER=$(dd if=/dev/urandom bs=15 count=1 status=none | base64)
COMMIT_MESSAGE="$(git log --format=%b -n 1)"
COMMIT_MESSAGE=$(git log --pretty=format:"\`\`\`\

%B\
\`\`\`\

" ${{ steps.pre-update.outputs.value }}..HEAD)
echo "GIT_COMMIT_MESSAGE<<$DELIMITER" >> $GITHUB_ENV
echo "$COMMIT_MESSAGE" >> $GITHUB_ENV
echo "$DELIMITER" >> $GITHUB_ENV
echo "GIT_COMMIT_MESSAGE is: ${COMMIT_MESSAGE}"
echo "GIT_COMMIT_MESSAGE is:"
echo "${COMMIT_MESSAGE}"
- name: Interpolate PR Body
uses: pedrolamas/handlebars-action@2995d7eadacbc8f2f6ab8431a01d84a5fa3b8bb4 # v2.4.0
with:
Expand Down
76 changes: 37 additions & 39 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -95251,18 +95251,9 @@ function makeOptionsConfident(actionOptions) {
//# sourceMappingURL=index.js.map
;// CONCATENATED MODULE: ./dist/index.js
// src/nix.ts
function makeNixCommandArgs(nixOptions, flakeInputs, commitMessage) {
const flakeInputFlags = flakeInputs.flatMap((input) => [
"--update-input",
input
]);
const lockfileSummaryFlags = [
"--option",
"commit-lockfile-summary",
commitMessage
];
const updateLockMechanism = flakeInputFlags.length === 0 ? "update" : "lock";
return nixOptions.concat(["flake", updateLockMechanism]).concat(flakeInputFlags).concat(["--commit-lock-file"]).concat(lockfileSummaryFlags);
function makeNixCommandArgs(nixOptions, flake, flakeInputs, commitMessage) {
const lockfileSummaryFlags = commitMessage ? ["--option", "commit-lockfile-summary", commitMessage] : [];
return nixOptions.concat(["flake", "update"]).concat(flake ? ["--flake", flake] : []).concat(flakeInputs).concat(["--commit-lock-file"]).concat(lockfileSummaryFlags);
}

// src/index.ts
Expand All @@ -95277,10 +95268,10 @@ var UpdateFlakeLockAction = class extends DetSysAction {
fetchStyle: "universal",
requireNix: "fail"
});
this.commitMessage = inputs_exports.getString("commit-msg");
this.commitMessage = inputs_exports.getStringOrNull("commit-msg");
this.flakeInputs = inputs_exports.getArrayOfStrings("inputs", "space");
this.nixOptions = inputs_exports.getArrayOfStrings("nix-options", "space");
this.pathToFlakeDir = inputs_exports.getStringOrNull("path-to-flake-dir");
this.flakes = core.getMultilineInput("flakes").concat(inputs_exports.getStringOrNull("path-to-flake-dir") ?? []);
}
async main() {
await this.update();
Expand All @@ -95289,31 +95280,38 @@ var UpdateFlakeLockAction = class extends DetSysAction {
async post() {
}
async update() {
const nixCommandArgs = makeNixCommandArgs(
this.nixOptions,
this.flakeInputs,
this.commitMessage
);
core.debug(
JSON.stringify({
options: this.nixOptions,
inputs: this.flakeInputs,
message: this.commitMessage,
args: nixCommandArgs
})
);
const execOptions = {
cwd: this.pathToFlakeDir !== null ? this.pathToFlakeDir : void 0,
ignoreReturnCode: true
};
const exitCode = await exec.exec("nix", nixCommandArgs, execOptions);
if (exitCode !== 0) {
this.recordEvent(EVENT_EXECUTION_FAILURE, {
exitCode
});
core.setFailed(`non-zero exit code of ${exitCode} detected`);
} else {
core.info(`flake.lock file was successfully updated`);
for (const flake of this.flakes.length > 0 ? this.flakes : [null]) {
const nixCommandArgs = makeNixCommandArgs(
this.nixOptions,
flake,
this.flakeInputs,
this.commitMessage
);
core.debug(
JSON.stringify({
options: this.nixOptions,
flake,
inputs: this.flakeInputs,
message: this.commitMessage,
args: nixCommandArgs
})
);
const execOptions = {
ignoreReturnCode: true
};
const exitCode = await exec.exec(
"nix",
nixCommandArgs,
execOptions
);
if (exitCode !== 0) {
this.recordEvent(EVENT_EXECUTION_FAILURE, {
exitCode
});
core.setFailed(`non-zero exit code of ${exitCode} detected`);
} else {
core.info(`flake.lock file was successfully updated`);
}
}
}
};
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading