diff --git a/README.md b/README.md index 40eb3c0..86cd493 100644 --- a/README.md +++ b/README.md @@ -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: diff --git a/action.yml b/action.yml index 2ed0d92..0726c6c 100644 --- a/action.yml +++ b/action.yml @@ -5,6 +5,10 @@ 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 @@ -12,7 +16,6 @@ inputs: 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 @@ -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 @@ -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" @@ -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 }} @@ -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: diff --git a/dist/index.js b/dist/index.js index e04b0a3..ddd72af 100644 --- a/dist/index.js +++ b/dist/index.js @@ -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 @@ -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(); @@ -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`); + } } } }; diff --git a/dist/index.js.map b/dist/index.js.map index 2e2062e..8ba26cc 100644 --- a/dist/index.js.map +++ b/dist/index.js.map @@ -1 +1 @@ -{"version":3,"sources":["../src/nix.ts","../src/index.ts"],"sourcesContent":["// Build the Nix args out of inputs from the Actions environment\nexport function makeNixCommandArgs(\n nixOptions: string[],\n flakeInputs: string[],\n commitMessage: string,\n): string[] {\n const flakeInputFlags = flakeInputs.flatMap((input) => [\n \"--update-input\",\n input,\n ]);\n\n // NOTE(cole-h): In Nix versions 2.23.0 and later, `commit-lockfile-summary` became an alias to\n // the setting `commit-lock-file-summary` (https://github.com/NixOS/nix/pull/10691), and Nix does\n // not treat aliases the same as their \"real\" setting by requiring setting aliases to be\n // configured via `--option