From 86ce5ab1b40fd92b92ea4092bd3d48fc3184a1ca Mon Sep 17 00:00:00 2001 From: Vitor Mattos <1079143+vitormattos@users.noreply.github.com> Date: Tue, 17 Nov 2026 12:43:35 +0000 Subject: [PATCH 1/8] ci(deps): update LibreSign submodule from merged 3rdparty PR Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com> --- .github/workflows/command-update-3rdparty.yml | 99 +++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 .github/workflows/command-update-3rdparty.yml diff --git a/.github/workflows/command-update-3rdparty.yml b/.github/workflows/command-update-3rdparty.yml new file mode 100644 index 0000000000..1f7ba389d3 --- /dev/null +++ b/.github/workflows/command-update-3rdparty.yml @@ -0,0 +1,99 @@ +# SPDX-FileCopyrightText: 2026 LibreCode coop and contributors +# SPDX-License-Identifier: AGPL-3.0-or-later +name: Update 3rdparty PR reference + +on: + issue_comment: + types: [created] + +permissions: + contents: read + pull-requests: read + +jobs: + authorize: + if: github.event.issue.pull_request != '' && github.event.comment.body == '/update-3rdparty' + runs-on: ubuntu-latest + outputs: + head_ref: ${{ steps.pr.outputs.head_ref } + target_sha: ${{ steps.pr.outputs.target_sha } + source_pr: ${{ steps.pr.outputs.source_pr } + steps: + - name: Check actor permission + uses: skjnldsv/check-actor-permission@69e92a3c4711150929bca9fcf34448c5bf5526e7 # v3.0 + with: + require: write + - name: Resolve merged 3rdparty PR + id: pr + uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 + with: + github-token: ${{ github.token } + script: | + const { data: pr } = await github.rest.pulls.get({ + owner: context.repo.owner, + repo: context.repo.repo, + pull_number: context.issue.number, + }); + if (pr.head.repo?.full_name !== `${context.repo.owner}/${context.repo.repo}`) { + core.setFailed('Cannot update PRs from forks'); + return; + } + if (!/^(main|stable\d+)$/.test(pr.base.ref)) { + core.setFailed(`Unsupported base branch: ${{pr.base.ref}`); + return; + } + const match = (pr.body || '').match(/^\s*-\s*\[[ xX]\]\s*3rdparty:\s*https:\/\/github\.com\/LibreSign\/3rdparty\/pull\/(\d+)\s*$/m); + if (!match) { + core.setFailed('PR body must reference the 3rdparty PR created by /libresign-pr'); + return; + } + const { data: source } = await github.rest.pulls.get({ + owner: 'LibreSign', repo: '3rdparty', pull_number: Number(match[1]), + }); + if (!source.merged_at || !source.merge_commit_sha) { + core.setFailed('The linked 3rdparty PR must be merged first'); + return; + } + if (source.base.ref !== pr.base.ref) { + core.setFailed('The 3rdparty PR target does not match the LibreSign PR target'); + return; + } + core.setOutput('head_ref', pr.head.ref); + core.setOutput('target_sha', source.merge_commit_sha); + core.setOutput('source_pr', match[1]); + + update: + runs-on: ubuntu-latest + needs: authorize + env: + HEAD_REF: ${{ needs.authorize.outputs.head_ref } + TARGET_SHA: ${{ needs.authorize.outputs.target_sha } + SOURCE_PR: ${{ needs.authorize.outputs.source_pr } + PARENT_PR: ${{ github.event.issue.number } + GH_TOKEN: ${{ secrets.COMMAND_BOT_PAT } + steps: + - name: Check credentials + run: test -n "$GH_TOKEN" + - name: Checkout LibreSign PR branch + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + ref: ${{ needs.authorize.outputs.head_ref } + token: ${{ secrets.COMMAND_BOT_PAT } + persist-credentials: true + - name: Update submodule to merged commit + shell: bash + run: | + set -euo pipefail + git config --local user.email 'libresign-command@users.noreply.github.com' + git config --local user.name 'libresign-command' + git update-index --cacheinfo "160000,$TARGET_SHA,3rdparty" + if git diff --cached --quiet; then + echo 'Submodule already points to the merged commit' + else + git commit --signoff -m "chore(deps): align 3rdparty with merged PR #$SOURCE_PR" + git push origin "HEAD:$HEAD_REF" + fi + - name: Report submodule update + run: | + gh pr comment "$PARENT_PR" --repo LibreSign/libresign \ + --body "3rdparty updated to LibreSign/3rdparty#$SOURCE_PR ($TARGET_SHA)." From c2939dc29cac3d908027cf50091d9938db79966b Mon Sep 17 00:00:00 2001 From: Vitor Mattos <1079143+vitormattos@users.noreply.github.com> Date: Tue, 17 Nov 2026 12:44:00 +0000 Subject: [PATCH 2/8] fix(ci): correct expressions in submodule update workflow Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com> --- .github/workflows/command-update-3rdparty.yml | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/.github/workflows/command-update-3rdparty.yml b/.github/workflows/command-update-3rdparty.yml index 1f7ba389d3..adad1a2cb0 100644 --- a/.github/workflows/command-update-3rdparty.yml +++ b/.github/workflows/command-update-3rdparty.yml @@ -15,9 +15,9 @@ jobs: if: github.event.issue.pull_request != '' && github.event.comment.body == '/update-3rdparty' runs-on: ubuntu-latest outputs: - head_ref: ${{ steps.pr.outputs.head_ref } - target_sha: ${{ steps.pr.outputs.target_sha } - source_pr: ${{ steps.pr.outputs.source_pr } + head_ref: ${{ steps.pr.outputs.head_ref }} + target_sha: ${{ steps.pr.outputs.target_sha }} + source_pr: ${{ steps.pr.outputs.source_pr }} steps: - name: Check actor permission uses: skjnldsv/check-actor-permission@69e92a3c4711150929bca9fcf34448c5bf5526e7 # v3.0 @@ -27,7 +27,7 @@ jobs: id: pr uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 with: - github-token: ${{ github.token } + github-token: ${{ github.token }} script: | const { data: pr } = await github.rest.pulls.get({ owner: context.repo.owner, @@ -39,7 +39,7 @@ jobs: return; } if (!/^(main|stable\d+)$/.test(pr.base.ref)) { - core.setFailed(`Unsupported base branch: ${{pr.base.ref}`); + core.setFailed('Unsupported base branch: ' + pr.base.ref); return; } const match = (pr.body || '').match(/^\s*-\s*\[[ xX]\]\s*3rdparty:\s*https:\/\/github\.com\/LibreSign\/3rdparty\/pull\/(\d+)\s*$/m); @@ -66,19 +66,19 @@ jobs: runs-on: ubuntu-latest needs: authorize env: - HEAD_REF: ${{ needs.authorize.outputs.head_ref } - TARGET_SHA: ${{ needs.authorize.outputs.target_sha } - SOURCE_PR: ${{ needs.authorize.outputs.source_pr } - PARENT_PR: ${{ github.event.issue.number } - GH_TOKEN: ${{ secrets.COMMAND_BOT_PAT } + HEAD_REF: ${{ needs.authorize.outputs.head_ref }} + TARGET_SHA: ${{ needs.authorize.outputs.target_sha }} + SOURCE_PR: ${{ needs.authorize.outputs.source_pr }} + PARENT_PR: ${{ github.event.issue.number }} + GH_TOKEN: ${{ secrets.COMMAND_BOT_PAT }} steps: - name: Check credentials run: test -n "$GH_TOKEN" - name: Checkout LibreSign PR branch uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: - ref: ${{ needs.authorize.outputs.head_ref } - token: ${{ secrets.COMMAND_BOT_PAT } + ref: ${{ needs.authorize.outputs.head_ref }} + token: ${{ secrets.COMMAND_BOT_PAT }} persist-credentials: true - name: Update submodule to merged commit shell: bash From 4183a7ec6e116f003be3eefd85969d96c4ce45be Mon Sep 17 00:00:00 2001 From: Vitor Mattos <1079143+vitormattos@users.noreply.github.com> Date: Wed, 18 Nov 2026 01:04:52 +0000 Subject: [PATCH 3/8] fix(ci): avoid privileged checkout when updating 3rdparty gitlink Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com> --- .github/workflows/command-update-3rdparty.yml | 133 +++++++++--------- 1 file changed, 66 insertions(+), 67 deletions(-) diff --git a/.github/workflows/command-update-3rdparty.yml b/.github/workflows/command-update-3rdparty.yml index adad1a2cb0..43ede513ca 100644 --- a/.github/workflows/command-update-3rdparty.yml +++ b/.github/workflows/command-update-3rdparty.yml @@ -11,89 +11,88 @@ permissions: pull-requests: read jobs: - authorize: + update-submodule: if: github.event.issue.pull_request != '' && github.event.comment.body == '/update-3rdparty' runs-on: ubuntu-latest - outputs: - head_ref: ${{ steps.pr.outputs.head_ref }} - target_sha: ${{ steps.pr.outputs.target_sha }} - source_pr: ${{ steps.pr.outputs.source_pr }} steps: - name: Check actor permission uses: skjnldsv/check-actor-permission@69e92a3c4711150929bca9fcf34448c5bf5526e7 # v3.0 with: require: write - - name: Resolve merged 3rdparty PR - id: pr + + # No PR checkout: a comment-triggered workflow has privileged credentials. + - name: Update submodule through GitHub API uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 with: - github-token: ${{ github.token }} + github-token: ${{ secrets.COMMAND_BOT_PAT }} script: | - const { data: pr } = await github.rest.pulls.get({ - owner: context.repo.owner, - repo: context.repo.repo, - pull_number: context.issue.number, - }); - if (pr.head.repo?.full_name !== `${context.repo.owner}/${context.repo.repo}`) { - core.setFailed('Cannot update PRs from forks'); - return; - } - if (!/^(main|stable\d+)$/.test(pr.base.ref)) { - core.setFailed('Unsupported base branch: ' + pr.base.ref); - return; + const owner = context.repo.owner; + const repo = context.repo.repo; + const pull_number = context.issue.number; + const { data: pr } = await github.rest.pulls.get({ owner, repo, pull_number }); + + if (pr.state !== 'open' || + pr.head.repo?.full_name !== owner + '/' + repo || + !/^(main|stable\d+)$/.test(pr.base.ref)) { + throw new Error('Only open PRs from this repository targeting main/stable are supported'); } - const match = (pr.body || '').match(/^\s*-\s*\[[ xX]\]\s*3rdparty:\s*https:\/\/github\.com\/LibreSign\/3rdparty\/pull\/(\d+)\s*$/m); + + const match = (pr.body || '').match( + /^\s*-\s*\[[ xX]\]\s*3rdparty:\s*https:\/\/github\.com\/LibreSign\/3rdparty\/pull\/(\d+)\s*$/m + ); if (!match) { - core.setFailed('PR body must reference the 3rdparty PR created by /libresign-pr'); - return; + throw new Error('PR body must link the originating LibreSign/3rdparty PR'); } + const sourcePrNumber = Number(match[1]); const { data: source } = await github.rest.pulls.get({ - owner: 'LibreSign', repo: '3rdparty', pull_number: Number(match[1]), + owner: 'LibreSign', repo: '3rdparty', pull_number: sourcePrNumber, }); - if (!source.merged_at || !source.merge_commit_sha) { - core.setFailed('The linked 3rdparty PR must be merged first'); - return; + if (!source.merged_at || !source.merge_commit_sha || + source.base.ref !== pr.base.ref) { + throw new Error('The linked 3rdparty PR must be merged into the same target branch'); + } + + const { data: head } = await github.rest.git.getCommit({ + owner, repo, commit_sha: pr.head.sha, + }); + const { data: currentTree } = await github.rest.git.getTree({ + owner, repo, tree_sha: head.tree.sha, + }); + const gitlink = currentTree.tree.find((entry) => + entry.path === '3rdparty' && entry.mode === '160000'); + if (!gitlink) { + throw new Error('The LibreSign PR does not contain the 3rdparty submodule'); } - if (source.base.ref !== pr.base.ref) { - core.setFailed('The 3rdparty PR target does not match the LibreSign PR target'); + if (gitlink.sha === source.merge_commit_sha) { + core.notice('The 3rdparty submodule already points to the merged commit'); return; } - core.setOutput('head_ref', pr.head.ref); - core.setOutput('target_sha', source.merge_commit_sha); - core.setOutput('source_pr', match[1]); - update: - runs-on: ubuntu-latest - needs: authorize - env: - HEAD_REF: ${{ needs.authorize.outputs.head_ref }} - TARGET_SHA: ${{ needs.authorize.outputs.target_sha }} - SOURCE_PR: ${{ needs.authorize.outputs.source_pr }} - PARENT_PR: ${{ github.event.issue.number }} - GH_TOKEN: ${{ secrets.COMMAND_BOT_PAT }} - steps: - - name: Check credentials - run: test -n "$GH_TOKEN" - - name: Checkout LibreSign PR branch - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - with: - ref: ${{ needs.authorize.outputs.head_ref }} - token: ${{ secrets.COMMAND_BOT_PAT }} - persist-credentials: true - - name: Update submodule to merged commit - shell: bash - run: | - set -euo pipefail - git config --local user.email 'libresign-command@users.noreply.github.com' - git config --local user.name 'libresign-command' - git update-index --cacheinfo "160000,$TARGET_SHA,3rdparty" - if git diff --cached --quiet; then - echo 'Submodule already points to the merged commit' - else - git commit --signoff -m "chore(deps): align 3rdparty with merged PR #$SOURCE_PR" - git push origin "HEAD:$HEAD_REF" - fi - - name: Report submodule update - run: | - gh pr comment "$PARENT_PR" --repo LibreSign/libresign \ - --body "3rdparty updated to LibreSign/3rdparty#$SOURCE_PR ($TARGET_SHA)." + const { data: tree } = await github.rest.git.createTree({ + owner, repo, base_tree: head.tree.sha, + tree: [{ + path: '3rdparty', mode: '160000', type: 'commit', + sha: source.merge_commit_sha, + }], + }); + const author = { + name: 'libresign-command', + email: 'libresign-command@users.noreply.github.com', + }; + const message = 'chore(deps): update 3rdparty from merged PR #' + + sourcePrNumber + '\n\nSigned-off-by: ' + + author.name + ' <' + author.email + '>'; + const { data: commit } = await github.rest.git.createCommit({ + owner, repo, message, tree: tree.sha, parents: [pr.head.sha], + author, committer: author, + }); + // Never overwrite a PR branch that moved during this workflow. + await github.rest.git.updateRef({ + owner, repo, ref: 'heads/' + pr.head.ref, + sha: commit.sha, force: false, + }); + await github.rest.issues.createComment({ + owner, repo, issue_number: pull_number, + body: 'Updated 3rdparty to LibreSign/3rdparty#' + + sourcePrNumber + ' (' + source.merge_commit_sha + ').', + }); From 6589e8a9890325fd9cd2cd28139b90259e39063b Mon Sep 17 00:00:00 2001 From: Vitor Mattos <1079143+vitormattos@users.noreply.github.com> Date: Wed, 18 Nov 2026 01:25:37 +0000 Subject: [PATCH 4/8] fix(ci): use shared upstream-derived safe submodule update workflow Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com> --- .github/workflows/command-update-3rdparty.yml | 98 -------------- .../workflows/command-update-submodule.yml | 126 ++++++++++++++++++ .../command-update-submodule.yml.patch | 17 +++ 3 files changed, 143 insertions(+), 98 deletions(-) delete mode 100644 .github/workflows/command-update-3rdparty.yml create mode 100644 .github/workflows/command-update-submodule.yml create mode 100644 .github/workflows/command-update-submodule.yml.patch diff --git a/.github/workflows/command-update-3rdparty.yml b/.github/workflows/command-update-3rdparty.yml deleted file mode 100644 index 43ede513ca..0000000000 --- a/.github/workflows/command-update-3rdparty.yml +++ /dev/null @@ -1,98 +0,0 @@ -# SPDX-FileCopyrightText: 2026 LibreCode coop and contributors -# SPDX-License-Identifier: AGPL-3.0-or-later -name: Update 3rdparty PR reference - -on: - issue_comment: - types: [created] - -permissions: - contents: read - pull-requests: read - -jobs: - update-submodule: - if: github.event.issue.pull_request != '' && github.event.comment.body == '/update-3rdparty' - runs-on: ubuntu-latest - steps: - - name: Check actor permission - uses: skjnldsv/check-actor-permission@69e92a3c4711150929bca9fcf34448c5bf5526e7 # v3.0 - with: - require: write - - # No PR checkout: a comment-triggered workflow has privileged credentials. - - name: Update submodule through GitHub API - uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 - with: - github-token: ${{ secrets.COMMAND_BOT_PAT }} - script: | - const owner = context.repo.owner; - const repo = context.repo.repo; - const pull_number = context.issue.number; - const { data: pr } = await github.rest.pulls.get({ owner, repo, pull_number }); - - if (pr.state !== 'open' || - pr.head.repo?.full_name !== owner + '/' + repo || - !/^(main|stable\d+)$/.test(pr.base.ref)) { - throw new Error('Only open PRs from this repository targeting main/stable are supported'); - } - - const match = (pr.body || '').match( - /^\s*-\s*\[[ xX]\]\s*3rdparty:\s*https:\/\/github\.com\/LibreSign\/3rdparty\/pull\/(\d+)\s*$/m - ); - if (!match) { - throw new Error('PR body must link the originating LibreSign/3rdparty PR'); - } - const sourcePrNumber = Number(match[1]); - const { data: source } = await github.rest.pulls.get({ - owner: 'LibreSign', repo: '3rdparty', pull_number: sourcePrNumber, - }); - if (!source.merged_at || !source.merge_commit_sha || - source.base.ref !== pr.base.ref) { - throw new Error('The linked 3rdparty PR must be merged into the same target branch'); - } - - const { data: head } = await github.rest.git.getCommit({ - owner, repo, commit_sha: pr.head.sha, - }); - const { data: currentTree } = await github.rest.git.getTree({ - owner, repo, tree_sha: head.tree.sha, - }); - const gitlink = currentTree.tree.find((entry) => - entry.path === '3rdparty' && entry.mode === '160000'); - if (!gitlink) { - throw new Error('The LibreSign PR does not contain the 3rdparty submodule'); - } - if (gitlink.sha === source.merge_commit_sha) { - core.notice('The 3rdparty submodule already points to the merged commit'); - return; - } - - const { data: tree } = await github.rest.git.createTree({ - owner, repo, base_tree: head.tree.sha, - tree: [{ - path: '3rdparty', mode: '160000', type: 'commit', - sha: source.merge_commit_sha, - }], - }); - const author = { - name: 'libresign-command', - email: 'libresign-command@users.noreply.github.com', - }; - const message = 'chore(deps): update 3rdparty from merged PR #' + - sourcePrNumber + '\n\nSigned-off-by: ' + - author.name + ' <' + author.email + '>'; - const { data: commit } = await github.rest.git.createCommit({ - owner, repo, message, tree: tree.sha, parents: [pr.head.sha], - author, committer: author, - }); - // Never overwrite a PR branch that moved during this workflow. - await github.rest.git.updateRef({ - owner, repo, ref: 'heads/' + pr.head.ref, - sha: commit.sha, force: false, - }); - await github.rest.issues.createComment({ - owner, repo, issue_number: pull_number, - body: 'Updated 3rdparty to LibreSign/3rdparty#' + - sourcePrNumber + ' (' + source.merge_commit_sha + ').', - }); diff --git a/.github/workflows/command-update-submodule.yml b/.github/workflows/command-update-submodule.yml new file mode 100644 index 0000000000..7a6e4cfcde --- /dev/null +++ b/.github/workflows/command-update-submodule.yml @@ -0,0 +1,126 @@ +# SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors +# SPDX-FileCopyrightText: 2026 LibreCode coop and contributors +# SPDX-License-Identifier: MIT +name: Update submodule reference + +on: + issue_comment: # zizmor: ignore[dangerous-triggers] + types: [created] + +permissions: + contents: read + pull-requests: read + +jobs: + update: + if: github.event.issue.pull_request != '' && github.event.comment.body == '/update-3rdparty' + runs-on: ubuntu-latest + env: + SUBMODULE_PATH: 3rdparty + SOURCE_REPOSITORY: LibreSign/3rdparty + steps: + - name: Check actor permission + uses: skjnldsv/check-actor-permission@69e92a3c4711150929bca9fcf34448c5bf5526e7 # v3.0 + with: + require: write + + # This read-only step never executes code from the pull request. + - name: Resolve merged submodule pull request + id: resolve + uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 + with: + github-token: ${{ github.token }} + script: | + const owner = context.repo.owner; + const repo = context.repo.repo; + const path = process.env.SUBMODULE_PATH; + const sourceRepo = process.env.SOURCE_REPOSITORY; + if (!/^[a-zA-Z0-9_.-]+\/[a-zA-Z0-9_.-]+$/.test(sourceRepo) || + !/^[a-zA-Z0-9_.-]+(\/[a-zA-Z0-9_.-]+)*$/.test(path)) { + throw new Error('Invalid submodule repository or path configuration'); + } + const { data: pr } = await github.rest.pulls.get({ + owner, repo, pull_number: context.issue.number, + }); + if (pr.state !== 'open' || + pr.head.repo?.full_name !== context.repo.owner + '/' + context.repo.repo || + !/^(main|stable\d+)$/.test(pr.base.ref)) { + throw new Error('Expected an open, in-repository PR targeting main or stable'); + } + const prefix = path + ': https://github.com/' + sourceRepo + '/pull/'; + const references = (pr.body || '').split(/\r?\n/) + .map(line => line.match(/^\s*-\s*\[[ xX]\]\s*(.*)$/)) + .filter(Boolean) + .map(match => match[1].trim()) + .filter(line => line.startsWith(prefix)); + if (references.length !== 1) { + throw new Error('Expected exactly one linked submodule PR in the body'); + } + const sourcePr = references[0].slice(prefix.length).trim(); + if (!/^[1-9]\d*$/.test(sourcePr)) { + throw new Error('Invalid linked submodule PR number'); + } + const [sourceOwner, sourceName] = sourceRepo.split('/'); + const { data: source } = await github.rest.pulls.get({ + owner: sourceOwner, repo: sourceName, pull_number: Number(sourcePr), + }); + if (!source.merged_at || !/^[0-9a-f]{40}$/.test(source.merge_commit_sha || '') || + source.base.ref !== pr.base.ref) { + throw new Error('Linked submodule PR must be merged into the same branch'); + } + core.setOutput('head_ref', pr.head.ref); + core.setOutput('head_sha', pr.head.sha); + core.setOutput('merge_sha', source.merge_commit_sha); + core.setOutput('source_pr', sourcePr); + + - name: Checkout trusted default branch + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + fetch-depth: 0 + ref: ${{ github.event.repository.default_branch }} + + - name: Stage and commit submodule pointer + id: update + shell: bash + env: + HEAD_SHA: ${{ steps.resolve.outputs.head_sha }} + MERGE_SHA: ${{ steps.resolve.outputs.merge_sha }} + SOURCE_PR: ${{ steps.resolve.outputs.source_pr }} + run: | + set -euo pipefail + [[ "$HEAD_SHA" =~ ^[0-9a-f]{40}$ ]] + [[ "$MERGE_SHA" =~ ^[0-9a-f]{40}$ ]] + git fetch --no-tags origin "$HEAD_SHA" + git -c core.hooksPath=/dev/null checkout --detach "$HEAD_SHA" + mode=$(git ls-files --stage -- "$SUBMODULE_PATH" | awk '{print $1}') + if ${{ "$mode" != "160000" }}; then + echo "::error::The configured path is not a git submodule" + exit 1 + fi + git update-index --cacheinfo "160000,$MERGE_SHA,$SUBMODULE_PATH" + if git diff --cached --quiet; then + echo 'Submodule already points to the merged commit' + exit 0 + fi + git config --local user.name 'github-actions[bot]' + git config --local user.email '41898282+github-actions[bot]@users.noreply.github.com' + git -c core.hooksPath=/dev/null commit --signoff -m "chore(deps): update $SUBMODULE_PATH from merged PR #$SOURCE_PR" + echo "changed=true" >> "$GITHUB_OUTPUT" + + - name: Push updated reference and comment + if: steps.update.outputs.changed == 'true' + env: + GH_TOKEN: ${{ secrets.COMMAND_BOT_PAT }} # zizmor: ignore[secrets-outside-env] + HEAD_REF: ${{ steps.resolve.outputs.head_ref }} + MERGE_SHA: ${{ steps.resolve.outputs.merge_sha }} + SOURCE_PR: ${{ steps.resolve.outputs.source_pr }} + PR_NUMBER: ${{ github.event.issue.number }} + shell: bash + run: | + set -euo pipefail + gh auth setup-git + # A normal push refuses to overwrite a branch that moved meanwhile. + git push origin "HEAD:refs/heads/$HEAD_REF" + gh pr comment "$PR_NUMBER" --repo "$GITHUB_REPOSITORY" \ + --body "Updated $SUBMODULE_PATH to $SOURCE_REPOSITORY#$SOURCE_PR ($MERGE_SHA)." diff --git a/.github/workflows/command-update-submodule.yml.patch b/.github/workflows/command-update-submodule.yml.patch new file mode 100644 index 0000000000..cc7912ff64 --- /dev/null +++ b/.github/workflows/command-update-submodule.yml.patch @@ -0,0 +1,17 @@ +--- a/.github/workflows/command-update-submodule.yml ++++ b/.github/workflows/command-update-submodule.yml +@@ -13,11 +13,11 @@ + + jobs: + update: ++ if: github.event.issue.pull_request != '' && github.event.comment.body == '/update-3rdparty' +- if: github.event.issue.pull_request != '' && vars.SUBMODULE_UPDATE_COMMAND != '' && github.event.comment.body == vars.SUBMODULE_UPDATE_COMMAND + runs-on: ubuntu-latest + env: ++ SUBMODULE_PATH: 3rdparty ++ SOURCE_REPOSITORY: LibreSign/3rdparty +- SUBMODULE_PATH: ${{ vars.SUBMODULE_PATH }} +- SOURCE_REPOSITORY: ${{ vars.SUBMODULE_SOURCE_REPOSITORY }} + steps: + - name: Check actor permission + uses: skjnldsv/check-actor-permission@69e92a3c4711150929bca9fcf34448c5bf5526e7 # v3.0 From a1c405552ba999d574f75a6f4f80522250b9191b Mon Sep 17 00:00:00 2001 From: Vitor Mattos <1079143+vitormattos@users.noreply.github.com> Date: Wed, 18 Nov 2026 01:29:14 +0000 Subject: [PATCH 5/8] fix(ci): avoid untrusted checkout and preserve exact merged gitlink Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com> --- .../workflows/command-update-submodule.yml | 26 ++++++++++++++----- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/.github/workflows/command-update-submodule.yml b/.github/workflows/command-update-submodule.yml index 7a6e4cfcde..929ce8f953 100644 --- a/.github/workflows/command-update-submodule.yml +++ b/.github/workflows/command-update-submodule.yml @@ -92,27 +92,39 @@ jobs: [[ "$HEAD_SHA" =~ ^[0-9a-f]{40}$ ]] [[ "$MERGE_SHA" =~ ^[0-9a-f]{40}$ ]] git fetch --no-tags origin "$HEAD_SHA" - git -c core.hooksPath=/dev/null checkout --detach "$HEAD_SHA" + # Read the untrusted PR tree into the index, without checking out its files. + git read-tree "$HEAD_SHA^{tree}" mode=$(git ls-files --stage -- "$SUBMODULE_PATH" | awk '{print $1}') - if ${{ "$mode" != "160000" }}; then + if [[ "$mode" != "160000" ]]; then echo "::error::The configured path is not a git submodule" exit 1 fi git update-index --cacheinfo "160000,$MERGE_SHA,$SUBMODULE_PATH" - if git diff --cached --quiet; then + if git diff --cached --quiet "$HEAD_SHA" -- "$SUBMODULE_PATH"; then echo 'Submodule already points to the merged commit' exit 0 fi - git config --local user.name 'github-actions[bot]' - git config --local user.email '41898282+github-actions[bot]@users.noreply.github.com' - git -c core.hooksPath=/dev/null commit --signoff -m "chore(deps): update $SUBMODULE_PATH from merged PR #$SOURCE_PR" + tree_sha=$(git write-tree) + new_sha=$(git \ + -c user.name='github-actions[bot]' \ + -c user.email='41898282+github-actions[bot]@users.noreply.github.com' \ + commit-tree "$tree_sha" -p "$HEAD_SHA" \ + -m "chore(deps): update $SUBMODULE_PATH from merged PR #$SOURCE_PR" \ + -m 'Signed-off-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>') + changed_paths=$(git diff-tree --no-commit-id --name-only -r "$HEAD_SHA" "$new_sha") + if [[ "$changed_paths" != "$SUBMODULE_PATH" ]]; then + echo "::error::Update must change only the configured submodule pointer" + exit 1 + fi echo "changed=true" >> "$GITHUB_OUTPUT" + echo "commit_sha=$new_sha" >> "$GITHUB_OUTPUT" - name: Push updated reference and comment if: steps.update.outputs.changed == 'true' env: GH_TOKEN: ${{ secrets.COMMAND_BOT_PAT }} # zizmor: ignore[secrets-outside-env] HEAD_REF: ${{ steps.resolve.outputs.head_ref }} + NEW_SHA: ${{ steps.update.outputs.commit_sha }} MERGE_SHA: ${{ steps.resolve.outputs.merge_sha }} SOURCE_PR: ${{ steps.resolve.outputs.source_pr }} PR_NUMBER: ${{ github.event.issue.number }} @@ -121,6 +133,6 @@ jobs: set -euo pipefail gh auth setup-git # A normal push refuses to overwrite a branch that moved meanwhile. - git push origin "HEAD:refs/heads/$HEAD_REF" + git push origin "$NEW_SHA:refs/heads/$HEAD_REF" gh pr comment "$PR_NUMBER" --repo "$GITHUB_REPOSITORY" \ --body "Updated $SUBMODULE_PATH to $SOURCE_REPOSITORY#$SOURCE_PR ($MERGE_SHA)." From 70c7027bd6ac88c5aeedffe692a19a4aa08d5ad8 Mon Sep 17 00:00:00 2001 From: Vitor Mattos <1079143+vitormattos@users.noreply.github.com> Date: Wed, 18 Nov 2026 01:31:35 +0000 Subject: [PATCH 6/8] fix(ci): pin trusted LibreSign checkout to main Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com> --- .github/workflows/command-update-submodule.yml | 2 +- .github/workflows/command-update-submodule.yml.patch | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/command-update-submodule.yml b/.github/workflows/command-update-submodule.yml index 929ce8f953..827afde75b 100644 --- a/.github/workflows/command-update-submodule.yml +++ b/.github/workflows/command-update-submodule.yml @@ -78,7 +78,7 @@ jobs: with: persist-credentials: false fetch-depth: 0 - ref: ${{ github.event.repository.default_branch }} + ref: main - name: Stage and commit submodule pointer id: update diff --git a/.github/workflows/command-update-submodule.yml.patch b/.github/workflows/command-update-submodule.yml.patch index cc7912ff64..4ffd4af374 100644 --- a/.github/workflows/command-update-submodule.yml.patch +++ b/.github/workflows/command-update-submodule.yml.patch @@ -15,3 +15,8 @@ steps: - name: Check actor permission uses: skjnldsv/check-actor-permission@69e92a3c4711150929bca9fcf34448c5bf5526e7 # v3.0 +@@ -79,3 +79,3 @@ + persist-credentials: false + fetch-depth: 0 ++ ref: main +- ref: ${{ github.event.repository.default_branch }} From 89f837d619d5918721d4eba29b641eaed68b1511 Mon Sep 17 00:00:00 2001 From: Vitor Mattos <1079143+vitormattos@users.noreply.github.com> Date: Wed, 18 Nov 2026 01:36:00 +0000 Subject: [PATCH 7/8] fix(ci): use shared guarded submodule Action without privileged checkout Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com> --- .../workflows/command-update-submodule.yml | 119 +----------------- .../command-update-submodule.yml.patch | 37 ++++-- 2 files changed, 30 insertions(+), 126 deletions(-) diff --git a/.github/workflows/command-update-submodule.yml b/.github/workflows/command-update-submodule.yml index 827afde75b..84c4b36f6e 100644 --- a/.github/workflows/command-update-submodule.yml +++ b/.github/workflows/command-update-submodule.yml @@ -15,124 +15,15 @@ jobs: update: if: github.event.issue.pull_request != '' && github.event.comment.body == '/update-3rdparty' runs-on: ubuntu-latest - env: - SUBMODULE_PATH: 3rdparty - SOURCE_REPOSITORY: LibreSign/3rdparty steps: - name: Check actor permission uses: skjnldsv/check-actor-permission@69e92a3c4711150929bca9fcf34448c5bf5526e7 # v3.0 with: require: write - # This read-only step never executes code from the pull request. - - name: Resolve merged submodule pull request - id: resolve - uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 + - name: Update merged submodule reference + uses: LibreCodeCoop/.github/actions/update-submodule@2a75cff7318334499053ced8b72d04bc0f795baf # source pinned with: - github-token: ${{ github.token }} - script: | - const owner = context.repo.owner; - const repo = context.repo.repo; - const path = process.env.SUBMODULE_PATH; - const sourceRepo = process.env.SOURCE_REPOSITORY; - if (!/^[a-zA-Z0-9_.-]+\/[a-zA-Z0-9_.-]+$/.test(sourceRepo) || - !/^[a-zA-Z0-9_.-]+(\/[a-zA-Z0-9_.-]+)*$/.test(path)) { - throw new Error('Invalid submodule repository or path configuration'); - } - const { data: pr } = await github.rest.pulls.get({ - owner, repo, pull_number: context.issue.number, - }); - if (pr.state !== 'open' || - pr.head.repo?.full_name !== context.repo.owner + '/' + context.repo.repo || - !/^(main|stable\d+)$/.test(pr.base.ref)) { - throw new Error('Expected an open, in-repository PR targeting main or stable'); - } - const prefix = path + ': https://github.com/' + sourceRepo + '/pull/'; - const references = (pr.body || '').split(/\r?\n/) - .map(line => line.match(/^\s*-\s*\[[ xX]\]\s*(.*)$/)) - .filter(Boolean) - .map(match => match[1].trim()) - .filter(line => line.startsWith(prefix)); - if (references.length !== 1) { - throw new Error('Expected exactly one linked submodule PR in the body'); - } - const sourcePr = references[0].slice(prefix.length).trim(); - if (!/^[1-9]\d*$/.test(sourcePr)) { - throw new Error('Invalid linked submodule PR number'); - } - const [sourceOwner, sourceName] = sourceRepo.split('/'); - const { data: source } = await github.rest.pulls.get({ - owner: sourceOwner, repo: sourceName, pull_number: Number(sourcePr), - }); - if (!source.merged_at || !/^[0-9a-f]{40}$/.test(source.merge_commit_sha || '') || - source.base.ref !== pr.base.ref) { - throw new Error('Linked submodule PR must be merged into the same branch'); - } - core.setOutput('head_ref', pr.head.ref); - core.setOutput('head_sha', pr.head.sha); - core.setOutput('merge_sha', source.merge_commit_sha); - core.setOutput('source_pr', sourcePr); - - - name: Checkout trusted default branch - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - with: - persist-credentials: false - fetch-depth: 0 - ref: main - - - name: Stage and commit submodule pointer - id: update - shell: bash - env: - HEAD_SHA: ${{ steps.resolve.outputs.head_sha }} - MERGE_SHA: ${{ steps.resolve.outputs.merge_sha }} - SOURCE_PR: ${{ steps.resolve.outputs.source_pr }} - run: | - set -euo pipefail - [[ "$HEAD_SHA" =~ ^[0-9a-f]{40}$ ]] - [[ "$MERGE_SHA" =~ ^[0-9a-f]{40}$ ]] - git fetch --no-tags origin "$HEAD_SHA" - # Read the untrusted PR tree into the index, without checking out its files. - git read-tree "$HEAD_SHA^{tree}" - mode=$(git ls-files --stage -- "$SUBMODULE_PATH" | awk '{print $1}') - if [[ "$mode" != "160000" ]]; then - echo "::error::The configured path is not a git submodule" - exit 1 - fi - git update-index --cacheinfo "160000,$MERGE_SHA,$SUBMODULE_PATH" - if git diff --cached --quiet "$HEAD_SHA" -- "$SUBMODULE_PATH"; then - echo 'Submodule already points to the merged commit' - exit 0 - fi - tree_sha=$(git write-tree) - new_sha=$(git \ - -c user.name='github-actions[bot]' \ - -c user.email='41898282+github-actions[bot]@users.noreply.github.com' \ - commit-tree "$tree_sha" -p "$HEAD_SHA" \ - -m "chore(deps): update $SUBMODULE_PATH from merged PR #$SOURCE_PR" \ - -m 'Signed-off-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>') - changed_paths=$(git diff-tree --no-commit-id --name-only -r "$HEAD_SHA" "$new_sha") - if [[ "$changed_paths" != "$SUBMODULE_PATH" ]]; then - echo "::error::Update must change only the configured submodule pointer" - exit 1 - fi - echo "changed=true" >> "$GITHUB_OUTPUT" - echo "commit_sha=$new_sha" >> "$GITHUB_OUTPUT" - - - name: Push updated reference and comment - if: steps.update.outputs.changed == 'true' - env: - GH_TOKEN: ${{ secrets.COMMAND_BOT_PAT }} # zizmor: ignore[secrets-outside-env] - HEAD_REF: ${{ steps.resolve.outputs.head_ref }} - NEW_SHA: ${{ steps.update.outputs.commit_sha }} - MERGE_SHA: ${{ steps.resolve.outputs.merge_sha }} - SOURCE_PR: ${{ steps.resolve.outputs.source_pr }} - PR_NUMBER: ${{ github.event.issue.number }} - shell: bash - run: | - set -euo pipefail - gh auth setup-git - # A normal push refuses to overwrite a branch that moved meanwhile. - git push origin "$NEW_SHA:refs/heads/$HEAD_REF" - gh pr comment "$PR_NUMBER" --repo "$GITHUB_REPOSITORY" \ - --body "Updated $SUBMODULE_PATH to $SOURCE_REPOSITORY#$SOURCE_PR ($MERGE_SHA)." + token: ${{ secrets.COMMAND_BOT_PAT }} # zizmor: ignore[secrets-outside-env] + source-repository: LibreSign/3rdparty + submodule-path: 3rdparty diff --git a/.github/workflows/command-update-submodule.yml.patch b/.github/workflows/command-update-submodule.yml.patch index 4ffd4af374..c74d717be6 100644 --- a/.github/workflows/command-update-submodule.yml.patch +++ b/.github/workflows/command-update-submodule.yml.patch @@ -1,22 +1,35 @@ --- a/.github/workflows/command-update-submodule.yml +++ b/.github/workflows/command-update-submodule.yml -@@ -13,11 +13,11 @@ +@@ -1,29 +1,29 @@ + # SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors + # SPDX-FileCopyrightText: 2026 LibreCode coop and contributors + # SPDX-License-Identifier: MIT + name: Update submodule reference + + on: + issue_comment: # zizmor: ignore[dangerous-triggers] + types: [created] + + permissions: + contents: read + pull-requests: read jobs: update: -+ if: github.event.issue.pull_request != '' && github.event.comment.body == '/update-3rdparty' - if: github.event.issue.pull_request != '' && vars.SUBMODULE_UPDATE_COMMAND != '' && github.event.comment.body == vars.SUBMODULE_UPDATE_COMMAND ++ if: github.event.issue.pull_request != '' && github.event.comment.body == '/update-3rdparty' runs-on: ubuntu-latest - env: -+ SUBMODULE_PATH: 3rdparty -+ SOURCE_REPOSITORY: LibreSign/3rdparty -- SUBMODULE_PATH: ${{ vars.SUBMODULE_PATH }} -- SOURCE_REPOSITORY: ${{ vars.SUBMODULE_SOURCE_REPOSITORY }} steps: - name: Check actor permission uses: skjnldsv/check-actor-permission@69e92a3c4711150929bca9fcf34448c5bf5526e7 # v3.0 -@@ -79,3 +79,3 @@ - persist-credentials: false - fetch-depth: 0 -+ ref: main -- ref: ${{ github.event.repository.default_branch }} + with: + require: write + + - name: Update merged submodule reference + uses: LibreCodeCoop/.github/actions/update-submodule@2a75cff7318334499053ced8b72d04bc0f795baf # source pinned + with: + token: ${{ secrets.COMMAND_BOT_PAT }} # zizmor: ignore[secrets-outside-env] +- source-repository: ${{ vars.SUBMODULE_SOURCE_REPOSITORY }} ++ source-repository: LibreSign/3rdparty +- submodule-path: ${{ vars.SUBMODULE_PATH }} ++ submodule-path: 3rdparty From abd8452ed2f2c9489044406f9169204c5f22ed56 Mon Sep 17 00:00:00 2001 From: Vitor Mattos <1079143+vitormattos@users.noreply.github.com> Date: Wed, 18 Nov 2026 01:38:32 +0000 Subject: [PATCH 8/8] chore(ci): align LibreSign updater with LibreCode-owned shared template Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com> --- .github/workflows/command-update-submodule.yml | 3 +-- .github/workflows/command-update-submodule.yml.patch | 5 ++--- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/.github/workflows/command-update-submodule.yml b/.github/workflows/command-update-submodule.yml index 84c4b36f6e..ef13ee8906 100644 --- a/.github/workflows/command-update-submodule.yml +++ b/.github/workflows/command-update-submodule.yml @@ -1,6 +1,5 @@ -# SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors # SPDX-FileCopyrightText: 2026 LibreCode coop and contributors -# SPDX-License-Identifier: MIT +# SPDX-License-Identifier: AGPL-3.0-or-later name: Update submodule reference on: diff --git a/.github/workflows/command-update-submodule.yml.patch b/.github/workflows/command-update-submodule.yml.patch index c74d717be6..35cba2ef78 100644 --- a/.github/workflows/command-update-submodule.yml.patch +++ b/.github/workflows/command-update-submodule.yml.patch @@ -1,9 +1,8 @@ --- a/.github/workflows/command-update-submodule.yml +++ b/.github/workflows/command-update-submodule.yml -@@ -1,29 +1,29 @@ - # SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors +@@ -1,28 +1,28 @@ # SPDX-FileCopyrightText: 2026 LibreCode coop and contributors - # SPDX-License-Identifier: MIT + # SPDX-License-Identifier: AGPL-3.0-or-later name: Update submodule reference on: