From 2f334f7b44bbe319ee0b5e8604db3fa01a6bd372 Mon Sep 17 00:00:00 2001 From: Vitor Mattos <1079143+vitormattos@users.noreply.github.com> Date: Wed, 18 Nov 2026 01:20:41 +0000 Subject: [PATCH 01/10] ci: import upstream parent submodule PR workflow as shared template Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com> --- .../nextcloud/command-submodule-pr.yml.patch | 132 ++++++++++++++ upstream/sources.json | 9 + upstream/templates.json | 8 + .../vendor/nextcloud/command-submodule-pr.yml | 161 +++++++++++++++++ .../command-submodule-pr.properties.json | 8 + workflow-templates/command-submodule-pr.yml | 167 ++++++++++++++++++ 6 files changed, 485 insertions(+) create mode 100644 patches/nextcloud/command-submodule-pr.yml.patch create mode 100644 upstream/vendor/nextcloud/command-submodule-pr.yml create mode 100644 workflow-templates/command-submodule-pr.properties.json create mode 100644 workflow-templates/command-submodule-pr.yml diff --git a/patches/nextcloud/command-submodule-pr.yml.patch b/patches/nextcloud/command-submodule-pr.yml.patch new file mode 100644 index 0000000..b23a68e --- /dev/null +++ b/patches/nextcloud/command-submodule-pr.yml.patch @@ -0,0 +1,132 @@ +--- upstream/vendor/nextcloud/command-submodule-pr.yml ++++ workflow-templates/command-submodule-pr.yml +@@ -1,6 +1,6 @@ + # SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors + # SPDX-License-Identifier: MIT ++name: Open submodule pull request +-name: Server PR comment + + on: + issue_comment: # zizmor: ignore[dangerous-triggers] +@@ -13,8 +13,8 @@ + init: + runs-on: ubuntu-latest-low + ++ # A consumer patch or repository variable configures the command. ++ if: github.event.issue.pull_request != '' && vars.SUBMODULE_PR_COMMAND != '' && github.event.comment.body == vars.SUBMODULE_PR_COMMAND +- # On pull requests and if the comment starts with `/server-pr` +- if: github.event.issue.pull_request != '' && startsWith(github.event.comment.body, '/server-pr') + + outputs: + head_ref: ${{ steps.comment-branch.outputs.head_ref }} +@@ -75,19 +75,26 @@ + needs: init + + env: ++ TARGET_REPOSITORY: ${{ vars.SUBMODULE_TARGET_REPOSITORY }} ++ SUBMODULE_PATH: ${{ vars.SUBMODULE_PATH }} + HEAD_REF: ${{ needs.init.outputs.head_ref }} + HEAD_SHA: ${{ needs.init.outputs.head_sha }} + BASE_REF: ${{ needs.init.outputs.base_ref }} + PR_NUMBER: ${{ github.event.issue.number }} + PR_TITLE: ${{ github.event.issue.title }} +- REVIEWER: ${{ github.event.comment.user.login }} +- GH_TOKEN: ${{ secrets.COMMAND_BOT_PAT }} # zizmor: ignore[secrets-outside-env] + + steps: ++ - name: Validate target configuration ++ shell: bash ++ run: | ++ set -euo pipefail ++ [[ "$TARGET_REPOSITORY" =~ ^[[:alnum:]_.-]+/[[:alnum:]_.-]+$ ]] || exit 1 ++ [[ "$SUBMODULE_PATH" =~ ^[[:alnum:]_.-]+(/[[:alnum:]_.-]+)*$ ]] || exit 1 ++ + - name: Checkout 3rdparty ${{ needs.init.outputs.head_ref }} + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: ++ path: source +- path: 3rdparty + persist-credentials: false + fetch-depth: 0 + ref: ${{ needs.init.outputs.head_sha }} +@@ -99,57 +106,56 @@ + coverage: none + + - name: Generate composer diff ++ working-directory: source +- working-directory: 3rdparty + run: | + composer global config --no-interaction allow-plugins.ion-bazan/composer-diff true + composer global require --no-interaction ion-bazan/composer-diff + { ++ echo "- [ ] $SUBMODULE_PATH: ${{ github.server_url }}/${{ github.repository }}/pull/$PR_NUMBER" +- echo "- [ ] 3rdparty: ${{ github.server_url }}/${{ github.repository }}/pull/$PR_NUMBER" + echo + composer diff --with-links --base "origin/$BASE_REF:composer.lock" --target composer.lock + } > "$RUNNER_TEMP/pr-body.md" + cat "$RUNNER_TEMP/pr-body.md" + ++ - name: Checkout target repository ${{ needs.init.outputs.base_ref }} +- - name: Checkout server ${{ needs.init.outputs.base_ref }} + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: ++ repository: ${{ env.TARGET_REPOSITORY }} ++ path: parent ++ persist-credentials: false +- repository: nextcloud/server +- path: server +- persist-credentials: true +- # Pushing a new branch to server needs the `workflow` scope, as GitHub can not always verify in time that no workflow is changed +- token: ${{ secrets.COMMAND_BOT_WORKFLOWS }} # zizmor: ignore[secrets-outside-env] + ref: ${{ needs.init.outputs.base_ref }} + ++ - name: Fail if target branch already exists ++ working-directory: parent +- - name: Fail if branch already exists on server +- working-directory: server + run: | + if git ls-remote --exit-code --heads origin "refs/heads/$HEAD_REF"; then ++ echo "Branch $HEAD_REF already exists on $TARGET_REPOSITORY, not overwriting it" +- echo "Branch $HEAD_REF already exists on nextcloud/server, not overwriting it" + exit 1 + fi + + - name: Setup git ++ working-directory: parent +- working-directory: server + run: | ++ git config --local user.email '41898282+github-actions[bot]@users.noreply.github.com' ++ git config --local user.name 'github-actions[bot]' +- git config --local user.email 'nextcloud-command@users.noreply.github.com' +- git config --local user.name 'nextcloud-command' + ++ - name: Commit submodule reference ++ working-directory: parent +- - name: Commit 3rdparty update and push +- working-directory: server + run: | + git checkout -b "$HEAD_REF" ++ git update-index --cacheinfo "160000,$HEAD_SHA,$SUBMODULE_PATH" +- git update-index --cacheinfo "160000,$HEAD_SHA,3rdparty" + git commit --signoff -m "$(sed -E 's/^\[stable[0-9.]*\] *//' <<< "$PR_TITLE")" ++ - name: Push branch and create target pull request ++ env: ++ GH_TOKEN: ${{ secrets.COMMAND_BOT_PAT }} # zizmor: ignore[secrets-outside-env] +- git push origin "$HEAD_REF" +- +- - name: Create server pull request + run: | ++ set -euo pipefail ++ gh auth setup-git ++ git -C parent push origin "$HEAD_REF" ++ url=$(gh pr create --repo "$TARGET_REPOSITORY" --base "$BASE_REF" --head "$HEAD_REF" \ +- url=$(gh pr create --repo nextcloud/server --base "$BASE_REF" --head "$HEAD_REF" \ + --title "$PR_TITLE" \ +- --label dependencies --label '3. to review' \ +- --reviewer "$REVIEWER" \ + --body-file "$RUNNER_TEMP/pr-body.md") ++ gh pr comment "$PR_NUMBER" --repo '${{ github.repository }}' --body "- Parent PR: $url" +- gh pr comment "$PR_NUMBER" --repo '${{ github.repository }}' --body "- Server PR: $url" + + - name: Add reaction on failure + uses: peter-evans/create-or-update-comment@e8674b075228eee787fea43ef493e45ece1004c9 # v5.0.0 diff --git a/upstream/sources.json b/upstream/sources.json index 72081ab..5232210 100644 --- a/upstream/sources.json +++ b/upstream/sources.json @@ -179,6 +179,15 @@ "url": "https://raw.githubusercontent.com/nextcloud/.github/c2798fc61844a6420779add9f5e1b51f8aabfd87/workflow-templates/playwright.yml", "sha256": "26106f8ae4bef2a191c445fb3a246ae6e1ab3f43348b8940feaf356768091a38", "destination": "upstream/vendor/nextcloud/playwright.yml" + }, + { + "name": "nextcloud-command-submodule-pr", + "repository": "nextcloud/3rdparty", + "ref": "master", + "path": ".github/workflows/command-server-pr.yml", + "url": "https://raw.githubusercontent.com/nextcloud/3rdparty/ee8d3bf7a2bfcbc1946da3ffd5afb1b08e317527/.github/workflows/command-server-pr.yml", + "sha256": "856720db49f76fba680b32582bdba88be4d7fc5064aaa7090b3fb77ae03e4ba9", + "destination": "upstream/vendor/nextcloud/command-submodule-pr.yml" } ] } diff --git a/upstream/templates.json b/upstream/templates.json index a9b82c3..2f2e3ca 100644 --- a/upstream/templates.json +++ b/upstream/templates.json @@ -146,6 +146,14 @@ "source": "upstream/vendor/nextcloud/playwright.yml", "patches": [], "destination": "workflow-templates/playwright.yml" + }, + { + "name": "nextcloud-command-submodule-pr", + "source": "upstream/vendor/nextcloud/command-submodule-pr.yml", + "patches": [ + "patches/nextcloud/command-submodule-pr.yml.patch" + ], + "destination": "workflow-templates/command-submodule-pr.yml" } ], "runner_aliases": { diff --git a/upstream/vendor/nextcloud/command-submodule-pr.yml b/upstream/vendor/nextcloud/command-submodule-pr.yml new file mode 100644 index 0000000..d46c595 --- /dev/null +++ b/upstream/vendor/nextcloud/command-submodule-pr.yml @@ -0,0 +1,161 @@ +# SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors +# SPDX-License-Identifier: MIT +name: Server PR comment + +on: + issue_comment: # zizmor: ignore[dangerous-triggers] + types: [created] + +permissions: + contents: read + +jobs: + init: + runs-on: ubuntu-latest-low + + # On pull requests and if the comment starts with `/server-pr` + if: github.event.issue.pull_request != '' && startsWith(github.event.comment.body, '/server-pr') + + outputs: + head_ref: ${{ steps.comment-branch.outputs.head_ref }} + head_sha: ${{ steps.comment-branch.outputs.head_sha }} + base_ref: ${{ steps.comment-branch.outputs.base_ref }} + + steps: + - name: Get repository from pull request comment + uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 + id: get-repository + with: + github-token: ${{secrets.GITHUB_TOKEN}} + script: | + const pull = await github.rest.pulls.get({ + owner: context.repo.owner, + repo: context.repo.repo, + pull_number: context.issue.number + }); + + const repositoryName = pull.data.head?.repo?.full_name + console.log(repositoryName) + return repositoryName + + - name: Disabled on forks + if: ${{ fromJSON(steps.get-repository.outputs.result) != github.repository }} + run: | + echo 'Can not execute /server-pr on forks' + exit 1 + + - name: Check actor permission + uses: skjnldsv/check-actor-permission@69e92a3c4711150929bca9fcf34448c5bf5526e7 # v3.0 + with: + require: write + + - name: Add reaction on start + uses: peter-evans/create-or-update-comment@e8674b075228eee787fea43ef493e45ece1004c9 # v5.0.0 + with: + token: ${{ secrets.COMMAND_BOT_PAT }} # zizmor: ignore[secrets-outside-env] + repository: ${{ github.event.repository.full_name }} + comment-id: ${{ github.event.comment.id }} + reactions: '+1' + + - name: Init branch + uses: xt0rted/pull-request-comment-branch@e8b8daa837e8ea7331c0003c9c316a64c6d8b0b1 # v3.0.0 + id: comment-branch + + - name: Add reaction on failure + uses: peter-evans/create-or-update-comment@e8674b075228eee787fea43ef493e45ece1004c9 # v5.0.0 + if: failure() + with: + token: ${{ secrets.COMMAND_BOT_PAT }} # zizmor: ignore[secrets-outside-env] + repository: ${{ github.event.repository.full_name }} + comment-id: ${{ github.event.comment.id }} + reactions: '-1' + + process: + runs-on: ubuntu-latest-low + needs: init + + env: + HEAD_REF: ${{ needs.init.outputs.head_ref }} + HEAD_SHA: ${{ needs.init.outputs.head_sha }} + BASE_REF: ${{ needs.init.outputs.base_ref }} + PR_NUMBER: ${{ github.event.issue.number }} + PR_TITLE: ${{ github.event.issue.title }} + REVIEWER: ${{ github.event.comment.user.login }} + GH_TOKEN: ${{ secrets.COMMAND_BOT_PAT }} # zizmor: ignore[secrets-outside-env] + + steps: + - name: Checkout 3rdparty ${{ needs.init.outputs.head_ref }} + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + path: 3rdparty + persist-credentials: false + fetch-depth: 0 + ref: ${{ needs.init.outputs.head_sha }} + + - name: Set up php + uses: shivammathur/setup-php@eb7c497e18156a6bbabfef1d3a82760b9eda3962 # 2.40.0 + with: + php-version: 8.3 + coverage: none + + - name: Generate composer diff + working-directory: 3rdparty + run: | + composer global config --no-interaction allow-plugins.ion-bazan/composer-diff true + composer global require --no-interaction ion-bazan/composer-diff + { + echo "- [ ] 3rdparty: ${{ github.server_url }}/${{ github.repository }}/pull/$PR_NUMBER" + echo + composer diff --with-links --base "origin/$BASE_REF:composer.lock" --target composer.lock + } > "$RUNNER_TEMP/pr-body.md" + cat "$RUNNER_TEMP/pr-body.md" + + - name: Checkout server ${{ needs.init.outputs.base_ref }} + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + repository: nextcloud/server + path: server + persist-credentials: true + # Pushing a new branch to server needs the `workflow` scope, as GitHub can not always verify in time that no workflow is changed + token: ${{ secrets.COMMAND_BOT_WORKFLOWS }} # zizmor: ignore[secrets-outside-env] + ref: ${{ needs.init.outputs.base_ref }} + + - name: Fail if branch already exists on server + working-directory: server + run: | + if git ls-remote --exit-code --heads origin "refs/heads/$HEAD_REF"; then + echo "Branch $HEAD_REF already exists on nextcloud/server, not overwriting it" + exit 1 + fi + + - name: Setup git + working-directory: server + run: | + git config --local user.email 'nextcloud-command@users.noreply.github.com' + git config --local user.name 'nextcloud-command' + + - name: Commit 3rdparty update and push + working-directory: server + run: | + git checkout -b "$HEAD_REF" + git update-index --cacheinfo "160000,$HEAD_SHA,3rdparty" + git commit --signoff -m "$(sed -E 's/^\[stable[0-9.]*\] *//' <<< "$PR_TITLE")" + git push origin "$HEAD_REF" + + - name: Create server pull request + run: | + url=$(gh pr create --repo nextcloud/server --base "$BASE_REF" --head "$HEAD_REF" \ + --title "$PR_TITLE" \ + --label dependencies --label '3. to review' \ + --reviewer "$REVIEWER" \ + --body-file "$RUNNER_TEMP/pr-body.md") + gh pr comment "$PR_NUMBER" --repo '${{ github.repository }}' --body "- Server PR: $url" + + - name: Add reaction on failure + uses: peter-evans/create-or-update-comment@e8674b075228eee787fea43ef493e45ece1004c9 # v5.0.0 + if: failure() + with: + token: ${{ secrets.COMMAND_BOT_PAT }} # zizmor: ignore[secrets-outside-env] + repository: '${{ github.event.repository.full_name }}' + comment-id: '${{ github.event.comment.id }}' + reactions: '-1' diff --git a/workflow-templates/command-submodule-pr.properties.json b/workflow-templates/command-submodule-pr.properties.json new file mode 100644 index 0000000..229a3f2 --- /dev/null +++ b/workflow-templates/command-submodule-pr.properties.json @@ -0,0 +1,8 @@ +{ + "name": "Open parent PR for a Composer submodule", + "description": "Create a reviewable parent-repository pull request for a dependency submodule; configure command, repository and path per consumer.", + "iconName": "octicon git-pull-request", + "categories": [ + "Continuous integration" + ] +} diff --git a/workflow-templates/command-submodule-pr.yml b/workflow-templates/command-submodule-pr.yml new file mode 100644 index 0000000..f7caa63 --- /dev/null +++ b/workflow-templates/command-submodule-pr.yml @@ -0,0 +1,167 @@ +# SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors +# SPDX-License-Identifier: MIT +name: Open submodule pull request + +on: + issue_comment: # zizmor: ignore[dangerous-triggers] + types: [created] + +permissions: + contents: read + +jobs: + init: + runs-on: ubuntu-latest-low + + # A consumer patch or repository variable configures the command. + if: github.event.issue.pull_request != '' && vars.SUBMODULE_PR_COMMAND != '' && github.event.comment.body == vars.SUBMODULE_PR_COMMAND + + outputs: + head_ref: ${{ steps.comment-branch.outputs.head_ref }} + head_sha: ${{ steps.comment-branch.outputs.head_sha }} + base_ref: ${{ steps.comment-branch.outputs.base_ref }} + + steps: + - name: Get repository from pull request comment + uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 + id: get-repository + with: + github-token: ${{secrets.GITHUB_TOKEN}} + script: | + const pull = await github.rest.pulls.get({ + owner: context.repo.owner, + repo: context.repo.repo, + pull_number: context.issue.number + }); + + const repositoryName = pull.data.head?.repo?.full_name + console.log(repositoryName) + return repositoryName + + - name: Disabled on forks + if: ${{ fromJSON(steps.get-repository.outputs.result) != github.repository }} + run: | + echo 'Can not execute /server-pr on forks' + exit 1 + + - name: Check actor permission + uses: skjnldsv/check-actor-permission@69e92a3c4711150929bca9fcf34448c5bf5526e7 # v3.0 + with: + require: write + + - name: Add reaction on start + uses: peter-evans/create-or-update-comment@e8674b075228eee787fea43ef493e45ece1004c9 # v5.0.0 + with: + token: ${{ secrets.COMMAND_BOT_PAT }} # zizmor: ignore[secrets-outside-env] + repository: ${{ github.event.repository.full_name }} + comment-id: ${{ github.event.comment.id }} + reactions: '+1' + + - name: Init branch + uses: xt0rted/pull-request-comment-branch@e8b8daa837e8ea7331c0003c9c316a64c6d8b0b1 # v3.0.0 + id: comment-branch + + - name: Add reaction on failure + uses: peter-evans/create-or-update-comment@e8674b075228eee787fea43ef493e45ece1004c9 # v5.0.0 + if: failure() + with: + token: ${{ secrets.COMMAND_BOT_PAT }} # zizmor: ignore[secrets-outside-env] + repository: ${{ github.event.repository.full_name }} + comment-id: ${{ github.event.comment.id }} + reactions: '-1' + + process: + runs-on: ubuntu-latest-low + needs: init + + env: + TARGET_REPOSITORY: ${{ vars.SUBMODULE_TARGET_REPOSITORY }} + SUBMODULE_PATH: ${{ vars.SUBMODULE_PATH }} + HEAD_REF: ${{ needs.init.outputs.head_ref }} + HEAD_SHA: ${{ needs.init.outputs.head_sha }} + BASE_REF: ${{ needs.init.outputs.base_ref }} + PR_NUMBER: ${{ github.event.issue.number }} + PR_TITLE: ${{ github.event.issue.title }} + + steps: + - name: Validate target configuration + shell: bash + run: | + set -euo pipefail + [[ "$TARGET_REPOSITORY" =~ ^[[:alnum:]_.-]+/[[:alnum:]_.-]+$ ]] || exit 1 + [[ "$SUBMODULE_PATH" =~ ^[[:alnum:]_.-]+(/[[:alnum:]_.-]+)*$ ]] || exit 1 + + - name: Checkout 3rdparty ${{ needs.init.outputs.head_ref }} + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + path: source + persist-credentials: false + fetch-depth: 0 + ref: ${{ needs.init.outputs.head_sha }} + + - name: Set up php + uses: shivammathur/setup-php@eb7c497e18156a6bbabfef1d3a82760b9eda3962 # 2.40.0 + with: + php-version: 8.3 + coverage: none + + - name: Generate composer diff + working-directory: source + run: | + composer global config --no-interaction allow-plugins.ion-bazan/composer-diff true + composer global require --no-interaction ion-bazan/composer-diff + { + echo "- [ ] $SUBMODULE_PATH: ${{ github.server_url }}/${{ github.repository }}/pull/$PR_NUMBER" + echo + composer diff --with-links --base "origin/$BASE_REF:composer.lock" --target composer.lock + } > "$RUNNER_TEMP/pr-body.md" + cat "$RUNNER_TEMP/pr-body.md" + + - name: Checkout target repository ${{ needs.init.outputs.base_ref }} + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + repository: ${{ env.TARGET_REPOSITORY }} + path: parent + persist-credentials: false + ref: ${{ needs.init.outputs.base_ref }} + + - name: Fail if target branch already exists + working-directory: parent + run: | + if git ls-remote --exit-code --heads origin "refs/heads/$HEAD_REF"; then + echo "Branch $HEAD_REF already exists on $TARGET_REPOSITORY, not overwriting it" + exit 1 + fi + + - name: Setup git + working-directory: parent + run: | + git config --local user.email '41898282+github-actions[bot]@users.noreply.github.com' + git config --local user.name 'github-actions[bot]' + + - name: Commit submodule reference + working-directory: parent + run: | + git checkout -b "$HEAD_REF" + git update-index --cacheinfo "160000,$HEAD_SHA,$SUBMODULE_PATH" + git commit --signoff -m "$(sed -E 's/^\[stable[0-9.]*\] *//' <<< "$PR_TITLE")" + - name: Push branch and create target pull request + env: + GH_TOKEN: ${{ secrets.COMMAND_BOT_PAT }} # zizmor: ignore[secrets-outside-env] + run: | + set -euo pipefail + gh auth setup-git + git -C parent push origin "$HEAD_REF" + url=$(gh pr create --repo "$TARGET_REPOSITORY" --base "$BASE_REF" --head "$HEAD_REF" \ + --title "$PR_TITLE" \ + --body-file "$RUNNER_TEMP/pr-body.md") + gh pr comment "$PR_NUMBER" --repo '${{ github.repository }}' --body "- Parent PR: $url" + + - name: Add reaction on failure + uses: peter-evans/create-or-update-comment@e8674b075228eee787fea43ef493e45ece1004c9 # v5.0.0 + if: failure() + with: + token: ${{ secrets.COMMAND_BOT_PAT }} # zizmor: ignore[secrets-outside-env] + repository: '${{ github.event.repository.full_name }}' + comment-id: '${{ github.event.comment.id }}' + reactions: '-1' From b8bbd6465a5adebd87b3ca32d43a91f266d272bb Mon Sep 17 00:00:00 2001 From: Vitor Mattos <1079143+vitormattos@users.noreply.github.com> Date: Wed, 18 Nov 2026 01:22:19 +0000 Subject: [PATCH 02/10] ci: track Nextcloud submodule update command with safe reviewable Git flow Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com> --- .../command-update-submodule.yml.patch | 227 ++++++++++++++++++ upstream/sources.json | 9 + upstream/templates.json | 8 + .../nextcloud/command-update-submodule.yml | 128 ++++++++++ .../command-update-submodule.properties.json | 8 + .../command-update-submodule.yml | 126 ++++++++++ 6 files changed, 506 insertions(+) create mode 100644 patches/nextcloud/command-update-submodule.yml.patch create mode 100644 upstream/vendor/nextcloud/command-update-submodule.yml create mode 100644 workflow-templates/command-update-submodule.properties.json create mode 100644 workflow-templates/command-update-submodule.yml diff --git a/patches/nextcloud/command-update-submodule.yml.patch b/patches/nextcloud/command-update-submodule.yml.patch new file mode 100644 index 0000000..552e32d --- /dev/null +++ b/patches/nextcloud/command-update-submodule.yml.patch @@ -0,0 +1,227 @@ +--- upstream/vendor/nextcloud/command-update-submodule.yml ++++ workflow-templates/command-update-submodule.yml +@@ -1,128 +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 +-name: Update 3rdparty command + + on: + issue_comment: # zizmor: ignore[dangerous-triggers] ++ types: [created] +- types: created + + permissions: + contents: read ++ pull-requests: read + + jobs: ++ update: ++ if: github.event.issue.pull_request != '' && vars.SUBMODULE_UPDATE_COMMAND != '' && github.event.comment.body == vars.SUBMODULE_UPDATE_COMMAND +- rebase: + runs-on: ubuntu-latest ++ env: ++ SUBMODULE_PATH: ${{ vars.SUBMODULE_PATH }} ++ SOURCE_REPOSITORY: ${{ vars.SUBMODULE_SOURCE_REPOSITORY }} +- permissions: +- contents: none +- pull-requests: read +- +- # On pull requests and if the comment starts with `/update-3rdparty` +- if: github.event.issue.pull_request != '' && startsWith(github.event.comment.body, '/update-3rdparty') +- + steps: +- # issue_comment events carry no pull_request context in their payload, so we +- # must fetch the PR via the API. This also gives us base.ref for free, avoiding +- # a second API call. The GITHUB_TOKEN needs pull-requests:read (granted above). +- - name: Get pull request metadata +- uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 +- id: get-pr +- with: +- github-token: ${{ secrets.GITHUB_TOKEN }} +- script: | +- const pull = await github.rest.pulls.get({ +- owner: context.repo.owner, +- repo: context.repo.repo, +- pull_number: context.issue.number, +- }); +- core.setOutput('head_repo', pull.data.head.repo?.full_name ?? ''); +- core.setOutput('base_ref', pull.data.base.ref); +- +- - name: Disabled on forks +- if: steps.get-pr.outputs.head_repo != github.repository +- run: | +- echo 'Can not execute /update-3rdparty on forks' +- exit 1 +- + - 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: Add reaction on start +- uses: peter-evans/create-or-update-comment@e8674b075228eee787fea43ef493e45ece1004c9 # v5.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); +- token: ${{ secrets.COMMAND_BOT_PAT }} +- repository: ${{ github.event.repository.full_name }} +- comment-id: ${{ github.event.comment.id }} +- reactions: '+1' + ++ - name: Checkout trusted default branch +- - name: Init branch +- uses: xt0rted/pull-request-comment-branch@e8b8daa837e8ea7331c0003c9c316a64c6d8b0b1 # v3.0.0 +- id: comment-branch +- +- - name: Checkout ${{ steps.comment-branch.outputs.head_ref }} + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false +- submodules: true + fetch-depth: 0 ++ ref: ${{ github.event.repository.default_branch }} +- token: ${{ secrets.COMMAND_BOT_PAT }} +- ref: ${{ steps.comment-branch.outputs.head_ref }} + ++ - name: Stage and commit submodule pointer ++ id: update ++ shell: bash +- - name: Register server reference to fallback to master branch + env: ++ HEAD_SHA: ${{ steps.resolve.outputs.head_sha }} ++ MERGE_SHA: ${{ steps.resolve.outputs.merge_sha }} ++ SOURCE_PR: ${{ steps.resolve.outputs.source_pr }} +- base_ref: ${{ steps.get-pr.outputs.base_ref }} + 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 +- if [[ "$base_ref" == "main" || "$base_ref" == "master" ]]; then +- echo "server_ref=master" >> "$GITHUB_ENV" +- echo "Setting server_ref to master" +- elif [[ "$base_ref" =~ ^stable[0-9]+$ ]]; then +- echo "server_ref=$base_ref" >> "$GITHUB_ENV" +- echo "Setting server_ref to $base_ref" +- else +- echo "Not based on master/main/stable*, so skipping pull 3rdparty command" + 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' +- - name: Setup git +- run: | +- git config --local user.email 'nextcloud-command@users.noreply.github.com' +- git config --local user.name 'nextcloud-command' +- +- - name: Add reaction on failure +- uses: peter-evans/create-or-update-comment@e8674b075228eee787fea43ef493e45ece1004c9 # v5.0.0 +- if: ${{ env.server_ref == '' }} +- with: +- token: ${{ secrets.COMMAND_BOT_PAT }} +- repository: ${{ github.event.repository.full_name }} +- comment-id: ${{ github.event.comment.id }} +- reactions: '-1' +- +- - name: Pull 3rdparty +- if: ${{ env.server_ref != '' }} +- run: | +- git -C 3rdparty fetch origin "$server_ref" +- git -C 3rdparty checkout FETCH_HEAD +- +- - name: Commit and push changes +- if: ${{ env.server_ref != '' }} + 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 +- BOT_TOKEN: ${{ secrets.COMMAND_BOT_PAT }} # zizmor: ignore[secrets-outside-env] + 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)." +- git add 3rdparty +- git remote set-url origin "https://x-access-token:${BOT_TOKEN}@github.com/${{ github.repository }}.git" +- if git diff --quiet HEAD~1 HEAD -- 3rdparty; then +- git commit -s -m "chore(3rdparty): Update submodule to latest $server_ref" +- git push +- else +- git commit -s --amend --no-edit +- git push --force-with-lease +- fi +- +- - name: Add reaction on failure +- uses: peter-evans/create-or-update-comment@e8674b075228eee787fea43ef493e45ece1004c9 # v5.0.0 +- if: failure() +- with: +- token: ${{ secrets.COMMAND_BOT_PAT }} +- repository: ${{ github.event.repository.full_name }} +- comment-id: ${{ github.event.comment.id }} +- reactions: '-1' diff --git a/upstream/sources.json b/upstream/sources.json index 5232210..1b75699 100644 --- a/upstream/sources.json +++ b/upstream/sources.json @@ -188,6 +188,15 @@ "url": "https://raw.githubusercontent.com/nextcloud/3rdparty/ee8d3bf7a2bfcbc1946da3ffd5afb1b08e317527/.github/workflows/command-server-pr.yml", "sha256": "856720db49f76fba680b32582bdba88be4d7fc5064aaa7090b3fb77ae03e4ba9", "destination": "upstream/vendor/nextcloud/command-submodule-pr.yml" + }, + { + "name": "nextcloud-command-update-submodule", + "repository": "nextcloud/server", + "ref": "master", + "path": ".github/workflows/command-pull-3rdparty.yml", + "url": "https://raw.githubusercontent.com/nextcloud/server/1e2085f7a0deaeaf7d28d4ce2bb26448cdecd3d9/.github/workflows/command-pull-3rdparty.yml", + "sha256": "172935e15a88386b5587be26edc6dac73b026470735873339a457bd9c5572e68", + "destination": "upstream/vendor/nextcloud/command-update-submodule.yml" } ] } diff --git a/upstream/templates.json b/upstream/templates.json index 2f2e3ca..3d4ac64 100644 --- a/upstream/templates.json +++ b/upstream/templates.json @@ -154,6 +154,14 @@ "patches/nextcloud/command-submodule-pr.yml.patch" ], "destination": "workflow-templates/command-submodule-pr.yml" + }, + { + "name": "nextcloud-command-update-submodule", + "source": "upstream/vendor/nextcloud/command-update-submodule.yml", + "patches": [ + "patches/nextcloud/command-update-submodule.yml.patch" + ], + "destination": "workflow-templates/command-update-submodule.yml" } ], "runner_aliases": { diff --git a/upstream/vendor/nextcloud/command-update-submodule.yml b/upstream/vendor/nextcloud/command-update-submodule.yml new file mode 100644 index 0000000..79e3455 --- /dev/null +++ b/upstream/vendor/nextcloud/command-update-submodule.yml @@ -0,0 +1,128 @@ +# SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors +# SPDX-License-Identifier: MIT +name: Update 3rdparty command + +on: + issue_comment: # zizmor: ignore[dangerous-triggers] + types: created + +permissions: + contents: read + +jobs: + rebase: + runs-on: ubuntu-latest + permissions: + contents: none + pull-requests: read + + # On pull requests and if the comment starts with `/update-3rdparty` + if: github.event.issue.pull_request != '' && startsWith(github.event.comment.body, '/update-3rdparty') + + steps: + # issue_comment events carry no pull_request context in their payload, so we + # must fetch the PR via the API. This also gives us base.ref for free, avoiding + # a second API call. The GITHUB_TOKEN needs pull-requests:read (granted above). + - name: Get pull request metadata + uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 + id: get-pr + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + const pull = await github.rest.pulls.get({ + owner: context.repo.owner, + repo: context.repo.repo, + pull_number: context.issue.number, + }); + core.setOutput('head_repo', pull.data.head.repo?.full_name ?? ''); + core.setOutput('base_ref', pull.data.base.ref); + + - name: Disabled on forks + if: steps.get-pr.outputs.head_repo != github.repository + run: | + echo 'Can not execute /update-3rdparty on forks' + exit 1 + + - name: Check actor permission + uses: skjnldsv/check-actor-permission@69e92a3c4711150929bca9fcf34448c5bf5526e7 # v3.0 + with: + require: write + + - name: Add reaction on start + uses: peter-evans/create-or-update-comment@e8674b075228eee787fea43ef493e45ece1004c9 # v5.0.0 + with: + token: ${{ secrets.COMMAND_BOT_PAT }} + repository: ${{ github.event.repository.full_name }} + comment-id: ${{ github.event.comment.id }} + reactions: '+1' + + - name: Init branch + uses: xt0rted/pull-request-comment-branch@e8b8daa837e8ea7331c0003c9c316a64c6d8b0b1 # v3.0.0 + id: comment-branch + + - name: Checkout ${{ steps.comment-branch.outputs.head_ref }} + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + submodules: true + fetch-depth: 0 + token: ${{ secrets.COMMAND_BOT_PAT }} + ref: ${{ steps.comment-branch.outputs.head_ref }} + + - name: Register server reference to fallback to master branch + env: + base_ref: ${{ steps.get-pr.outputs.base_ref }} + run: | + if [[ "$base_ref" == "main" || "$base_ref" == "master" ]]; then + echo "server_ref=master" >> "$GITHUB_ENV" + echo "Setting server_ref to master" + elif [[ "$base_ref" =~ ^stable[0-9]+$ ]]; then + echo "server_ref=$base_ref" >> "$GITHUB_ENV" + echo "Setting server_ref to $base_ref" + else + echo "Not based on master/main/stable*, so skipping pull 3rdparty command" + fi + + - name: Setup git + run: | + git config --local user.email 'nextcloud-command@users.noreply.github.com' + git config --local user.name 'nextcloud-command' + + - name: Add reaction on failure + uses: peter-evans/create-or-update-comment@e8674b075228eee787fea43ef493e45ece1004c9 # v5.0.0 + if: ${{ env.server_ref == '' }} + with: + token: ${{ secrets.COMMAND_BOT_PAT }} + repository: ${{ github.event.repository.full_name }} + comment-id: ${{ github.event.comment.id }} + reactions: '-1' + + - name: Pull 3rdparty + if: ${{ env.server_ref != '' }} + run: | + git -C 3rdparty fetch origin "$server_ref" + git -C 3rdparty checkout FETCH_HEAD + + - name: Commit and push changes + if: ${{ env.server_ref != '' }} + env: + BOT_TOKEN: ${{ secrets.COMMAND_BOT_PAT }} # zizmor: ignore[secrets-outside-env] + run: | + git add 3rdparty + git remote set-url origin "https://x-access-token:${BOT_TOKEN}@github.com/${{ github.repository }}.git" + if git diff --quiet HEAD~1 HEAD -- 3rdparty; then + git commit -s -m "chore(3rdparty): Update submodule to latest $server_ref" + git push + else + git commit -s --amend --no-edit + git push --force-with-lease + fi + + - name: Add reaction on failure + uses: peter-evans/create-or-update-comment@e8674b075228eee787fea43ef493e45ece1004c9 # v5.0.0 + if: failure() + with: + token: ${{ secrets.COMMAND_BOT_PAT }} + repository: ${{ github.event.repository.full_name }} + comment-id: ${{ github.event.comment.id }} + reactions: '-1' diff --git a/workflow-templates/command-update-submodule.properties.json b/workflow-templates/command-update-submodule.properties.json new file mode 100644 index 0000000..9e3a387 --- /dev/null +++ b/workflow-templates/command-update-submodule.properties.json @@ -0,0 +1,8 @@ +{ + "name": "Update parent PR submodule from merged dependency PR", + "description": "Update a submodule pointer using only a verified merged source PR; set the command, repository and path for each consumer.", + "iconName": "octicon git-pull-request", + "categories": [ + "Continuous integration" + ] +} diff --git a/workflow-templates/command-update-submodule.yml b/workflow-templates/command-update-submodule.yml new file mode 100644 index 0000000..af7ed67 --- /dev/null +++ b/workflow-templates/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 != '' && vars.SUBMODULE_UPDATE_COMMAND != '' && github.event.comment.body == vars.SUBMODULE_UPDATE_COMMAND + runs-on: ubuntu-latest + env: + SUBMODULE_PATH: ${{ vars.SUBMODULE_PATH }} + SOURCE_REPOSITORY: ${{ vars.SUBMODULE_SOURCE_REPOSITORY }} + 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)." From bfca2144c8b37b7a702ede490df8e6e533cfc730 Mon Sep 17 00:00:00 2001 From: Vitor Mattos <1079143+vitormattos@users.noreply.github.com> Date: Wed, 18 Nov 2026 01:24:12 +0000 Subject: [PATCH 03/10] test(ci): verify inherited workflow contracts and submodule PR boundaries Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com> --- docs/cross-repository-automation.md | 22 +++++ tests/test_submodule_workflows.py | 122 ++++++++++++++++++++++++++++ 2 files changed, 144 insertions(+) create mode 100644 tests/test_submodule_workflows.py diff --git a/docs/cross-repository-automation.md b/docs/cross-repository-automation.md index 4eb27d7..5abb744 100644 --- a/docs/cross-repository-automation.md +++ b/docs/cross-repository-automation.md @@ -52,6 +52,28 @@ Consumer-specific changes belong in `.github/workflows/.patch`. Do not The catalog updater targets only the consumer's default branch by default. Projects with maintained long-lived release branches should declare those branches through a consumer-local patch to `sync-workflow-templates.yml`; branch lifecycle is consumer policy and must not be hard-coded in the organization template. +## Submodule dependency commands + +The optional `command-submodule-pr.yml` and `command-update-submodule.yml` +templates track pinned sources from `nextcloud/3rdparty` and `nextcloud/server`. +The differences needed for other repositories are managed as reviewable +`patches/nextcloud/` and verified against immutable upstream checksums. + +A consumer must install each workflow and configure its parameters using +Actions variables or a consumer-local `.github/workflows/.yml.patch`: + +- `command-submodule-pr.yml`: `SUBMODULE_PR_COMMAND`, + `SUBMODULE_TARGET_REPOSITORY` and `SUBMODULE_PATH`. +- `command-update-submodule.yml`: `SUBMODULE_UPDATE_COMMAND`, + `SUBMODULE_SOURCE_REPOSITORY` and `SUBMODULE_PATH`. + +The creation command expects a Composer lockfile in the source PR. The update +command requires a linked source PR already merged into the same target branch +and uses its exact merged SHA. Both commands require maintainer authorization, +repository-hosted PR branches and a scoped publishing credential. No force +push is performed. Publishing credentials are not available to dependency +analysis or staging steps. + ## Publishing templates `LibreCodeCoop/.github` is the source of truth for LibreCode-managed workflow templates and the distribution catalog consumed by repository updaters. Templates derived from external upstream sources are refreshed through the pinned upstream/patch pipeline rather than edited as independent downstream implementations. diff --git a/tests/test_submodule_workflows.py b/tests/test_submodule_workflows.py new file mode 100644 index 0000000..c83d928 --- /dev/null +++ b/tests/test_submodule_workflows.py @@ -0,0 +1,122 @@ +# SPDX-FileCopyrightText: 2026 LibreCode coop and contributors +# SPDX-License-Identifier: AGPL-3.0-or-later + +"""Contracts for the inherited submodule command workflows.""" + +import hashlib +import json +import re +import shutil +import subprocess +import unittest +from pathlib import Path + +from scripts.render_upstream import check, load_templates + +ROOT = Path(__file__).resolve().parents[1] + + +class SubmoduleCommandTest(unittest.TestCase): + def test_upstream_provenance_and_rendering(self) -> None: + manifest = json.loads((ROOT / "upstream/sources.json").read_text()) + expected = { + "nextcloud-command-submodule-pr": "nextcloud/3rdparty", + "nextcloud-command-update-submodule": "nextcloud/server", + } + for name, repo in expected.items(): + with self.subTest(name=name): + item = next(x for x in manifest["sources"] if x["name"] == name) + self.assertEqual(item["repository"], repo) + self.assertRegex(item["url"], r"/[0-9a-f]{40}/") + source = (ROOT / item["destination"]).read_bytes() + self.assertEqual(hashlib.sha256(source).hexdigest(), item["sha256"]) + check(load_templates(ROOT / "upstream/templates.json"), ROOT) + + def test_no_publish_secrets_during_dependency_analysis_or_staging(self) -> None: + source = (ROOT / "workflow-templates/command-submodule-pr.yml").read_text() + process = source.split(" process:\n", 1)[1] + before_publish = process.split( + " - name: Push branch and create target pull request", 1 + )[0] + self.assertNotIn("secrets.COMMAND_BOT_PAT", before_publish) + self.assertIn("composer diff --with-links", before_publish) + self.assertIn("persist-credentials: false", before_publish) + self.assertIn("gh auth setup-git", process) + + updater = (ROOT / "workflow-templates/command-update-submodule.yml").read_text() + before_publish = updater.split( + " - name: Push updated reference and comment", 1 + )[0] + self.assertNotIn("secrets.COMMAND_BOT_PAT", before_publish) + self.assertIn("git -c core.hooksPath=/dev/null commit --signoff", before_publish) + self.assertIn("persist-credentials: false", before_publish) + self.assertNotIn("force-with-lease", updater) + self.assertIn("ref: $" + "{{ github.event.repository.default_branch }}", updater) + + @staticmethod + def resolver() -> str: + lines = (ROOT / "workflow-templates/command-update-submodule.yml").read_text().splitlines() + start = lines.index(" script: |") + 1 + script = [] + for line in lines[start:]: + if line and not line.startswith(" "): + break + script.append(line[12:] if line else "") + return "\n".join(script) + + def test_linked_source_pr_authorization_cases(self) -> None: + if not shutil.which("node"): + self.skipTest("Node.js unavailable") + js = "const code = " + json.dumps(self.resolver()) + ";\n" + r""" +const assert = require('node:assert/strict'); +const runScript = new Function('github', 'context', 'core', 'process', + 'return (async () => {\n' + code + '\n})();'); +async function runCase(name, ok, edit = () => {}, path = '3rdparty') { + const parent = {state: 'open', body: '- [ ] 3rdparty: https://github.com/LibreSign/3rdparty/pull/17', + head: {ref: 'deps/update', sha: 'a'.repeat(40), + repo: {full_name: 'LibreSign/libresign'}}, base: {ref: 'main'}}; + const source = {merged_at: '2026-11-17T12:00:00Z', + merge_commit_sha: 'b'.repeat(40), base: {ref: 'main'}}; + edit(parent, source); + const outputs = {}; + const github = {rest: {pulls: {get: async (args) => ({ + data: args.repo === '3rdparty' ? source : parent + })}}}; + const context = {repo: {owner: 'LibreSign', repo: 'libresign'}, issue: {number: 33}}; + const core = {setOutput: (k, v) => { outputs[k] = v; }}; + const process = {env: {SUBMODULE_PATH: path, SOURCE_REPOSITORY: 'LibreSign/3rdparty'}}; + let err; + try { await runScript(github, context, core, process); } catch (e) { err = e; } + assert.equal(!Boolean(err), ok, name + ': ' + err); + if (ok) { + assert.equal(outputs.merge_sha, 'b'.repeat(40)); + assert.equal(outputs.source_pr, '17'); + } else { + assert.deepEqual(outputs, {}); + } +} +(async () => { + await runCase('valid', true); + await runCase('checked link', true, p => p.body = p.body.replace('[ ]', '[x]')); + await runCase('fork', false, p => p.head.repo.full_name = 'fork/libresign'); + await runCase('closed', false, p => p.state = 'closed'); + await runCase('wrong target', false, p => p.base.ref = 'feature'); + await runCase('not merged', false, (p,s) => s.merged_at = null); + await runCase('branch mismatch', false, (p,s) => s.base.ref = 'stable35'); + await runCase('no link', false, p => p.body = ''); + await runCase('duplicate', false, p => p.body += '\n' + p.body); + await runCase('wrong source', false, p => + p.body = p.body.replace('LibreSign/3rdparty', 'another/3rdparty')); + await runCase('unsafe path', false, () => {}, '../3rdparty'); + console.log('11 resolver cases passed'); +})().catch(e => { console.error(e); process.exitCode = 1; }); +""" + result = subprocess.run( + ["node", "-e", js], check=False, capture_output=True, text=True + ) + self.assertEqual(result.returncode, 0, result.stderr) + self.assertIn("11 resolver cases passed", result.stdout) + + +if __name__ == "__main__": + unittest.main() From 50d544ce0c85531780a7ac7bf7040b6727548a87 Mon Sep 17 00:00:00 2001 From: Vitor Mattos <1079143+vitormattos@users.noreply.github.com> Date: Wed, 18 Nov 2026 01:26:35 +0000 Subject: [PATCH 04/10] fix(ci): apply shared runner aliases to rendered submodule template Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com> --- workflow-templates/command-submodule-pr.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/workflow-templates/command-submodule-pr.yml b/workflow-templates/command-submodule-pr.yml index f7caa63..30087a1 100644 --- a/workflow-templates/command-submodule-pr.yml +++ b/workflow-templates/command-submodule-pr.yml @@ -11,7 +11,7 @@ permissions: jobs: init: - runs-on: ubuntu-latest-low + runs-on: ubuntu-latest # A consumer patch or repository variable configures the command. if: github.event.issue.pull_request != '' && vars.SUBMODULE_PR_COMMAND != '' && github.event.comment.body == vars.SUBMODULE_PR_COMMAND @@ -71,7 +71,7 @@ jobs: reactions: '-1' process: - runs-on: ubuntu-latest-low + runs-on: ubuntu-latest needs: init env: From b858babebe8543f60bd2725b4cc0c135cd8ca2ad Mon Sep 17 00:00:00 2001 From: Vitor Mattos <1079143+vitormattos@users.noreply.github.com> Date: Wed, 18 Nov 2026 01:28:51 +0000 Subject: [PATCH 05/10] fix(ci): update submodule without checking out untrusted PR content Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com> --- .../command-update-submodule.yml.patch | 28 +++++-- tests/test_submodule_workflows.py | 78 ++++++++++++++++++- .../command-update-submodule.yml | 26 +++++-- 3 files changed, 116 insertions(+), 16 deletions(-) diff --git a/patches/nextcloud/command-update-submodule.yml.patch b/patches/nextcloud/command-update-submodule.yml.patch index 552e32d..2424710 100644 --- a/patches/nextcloud/command-update-submodule.yml.patch +++ b/patches/nextcloud/command-update-submodule.yml.patch @@ -1,6 +1,6 @@ --- upstream/vendor/nextcloud/command-update-submodule.yml +++ workflow-templates/command-update-submodule.yml -@@ -1,128 +1,126 @@ +@@ -1,128 +1,138 @@ # SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors +# SPDX-FileCopyrightText: 2026 LibreCode coop and contributors # SPDX-License-Identifier: MIT @@ -144,16 +144,29 @@ + [[ "$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 ++ 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 - if [[ "$base_ref" == "main" || "$base_ref" == "master" ]]; then - echo "server_ref=master" >> "$GITHUB_ENV" - echo "Setting server_ref to master" @@ -163,10 +176,8 @@ - else - echo "Not based on master/main/stable*, so skipping pull 3rdparty command" 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" ++ echo "commit_sha=$new_sha" >> "$GITHUB_OUTPUT" + - name: Push updated reference and comment + if: steps.update.outputs.changed == 'true' @@ -195,6 +206,7 @@ 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 }} @@ -204,7 +216,7 @@ + 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)." - git add 3rdparty diff --git a/tests/test_submodule_workflows.py b/tests/test_submodule_workflows.py index c83d928..474c72c 100644 --- a/tests/test_submodule_workflows.py +++ b/tests/test_submodule_workflows.py @@ -48,7 +48,83 @@ def test_no_publish_secrets_during_dependency_analysis_or_staging(self) -> None: " - name: Push updated reference and comment", 1 )[0] self.assertNotIn("secrets.COMMAND_BOT_PAT", before_publish) - self.assertIn("git -c core.hooksPath=/dev/null commit --signoff", before_publish) + self.assertIn('git read-tree "$HEAD_SHA^{tree}"', before_publish) + self.assertIn("commit-tree", before_publish) + self.assertIn("Signed-off-by: github-actions[bot]", before_publish) + self.assertNotIn("checkout --detach", before_publish) + self.assertNotIn('if + self.assertIn("persist-credentials: false", before_publish) + self.assertNotIn("force-with-lease", updater) + self.assertIn("ref: $" + "{{ github.event.repository.default_branch }}", updater) + + @staticmethod + def resolver() -> str: + lines = (ROOT / "workflow-templates/command-update-submodule.yml").read_text().splitlines() + start = lines.index(" script: |") + 1 + script = [] + for line in lines[start:]: + if line and not line.startswith(" "): + break + script.append(line[12:] if line else "") + return "\n".join(script) + + def test_linked_source_pr_authorization_cases(self) -> None: + if not shutil.which("node"): + self.skipTest("Node.js unavailable") + js = "const code = " + json.dumps(self.resolver()) + ";\n" + r""" +const assert = require('node:assert/strict'); +const runScript = new Function('github', 'context', 'core', 'process', + 'return (async () => {\n' + code + '\n})();'); +async function runCase(name, ok, edit = () => {}, path = '3rdparty') { + const parent = {state: 'open', body: '- [ ] 3rdparty: https://github.com/LibreSign/3rdparty/pull/17', + head: {ref: 'deps/update', sha: 'a'.repeat(40), + repo: {full_name: 'LibreSign/libresign'}}, base: {ref: 'main'}}; + const source = {merged_at: '2026-11-17T12:00:00Z', + merge_commit_sha: 'b'.repeat(40), base: {ref: 'main'}}; + edit(parent, source); + const outputs = {}; + const github = {rest: {pulls: {get: async (args) => ({ + data: args.repo === '3rdparty' ? source : parent + })}}}; + const context = {repo: {owner: 'LibreSign', repo: 'libresign'}, issue: {number: 33}}; + const core = {setOutput: (k, v) => { outputs[k] = v; }}; + const process = {env: {SUBMODULE_PATH: path, SOURCE_REPOSITORY: 'LibreSign/3rdparty'}}; + let err; + try { await runScript(github, context, core, process); } catch (e) { err = e; } + assert.equal(!Boolean(err), ok, name + ': ' + err); + if (ok) { + assert.equal(outputs.merge_sha, 'b'.repeat(40)); + assert.equal(outputs.source_pr, '17'); + } else { + assert.deepEqual(outputs, {}); + } +} +(async () => { + await runCase('valid', true); + await runCase('checked link', true, p => p.body = p.body.replace('[ ]', '[x]')); + await runCase('fork', false, p => p.head.repo.full_name = 'fork/libresign'); + await runCase('closed', false, p => p.state = 'closed'); + await runCase('wrong target', false, p => p.base.ref = 'feature'); + await runCase('not merged', false, (p,s) => s.merged_at = null); + await runCase('branch mismatch', false, (p,s) => s.base.ref = 'stable35'); + await runCase('no link', false, p => p.body = ''); + await runCase('duplicate', false, p => p.body += '\n' + p.body); + await runCase('wrong source', false, p => + p.body = p.body.replace('LibreSign/3rdparty', 'another/3rdparty')); + await runCase('unsafe path', false, () => {}, '../3rdparty'); + console.log('11 resolver cases passed'); +})().catch(e => { console.error(e); process.exitCode = 1; }); +""" + result = subprocess.run( + ["node", "-e", js], check=False, capture_output=True, text=True + ) + self.assertEqual(result.returncode, 0, result.stderr) + self.assertIn("11 resolver cases passed", result.stdout) + + +if __name__ == "__main__": + unittest.main() + + '{{ "$mode"', before_publish) self.assertIn("persist-credentials: false", before_publish) self.assertNotIn("force-with-lease", updater) self.assertIn("ref: $" + "{{ github.event.repository.default_branch }}", updater) diff --git a/workflow-templates/command-update-submodule.yml b/workflow-templates/command-update-submodule.yml index af7ed67..59fcb47 100644 --- a/workflow-templates/command-update-submodule.yml +++ b/workflow-templates/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 e724b047359809198ab43f91134f655210b28413 Mon Sep 17 00:00:00 2001 From: Vitor Mattos <1079143+vitormattos@users.noreply.github.com> Date: Wed, 18 Nov 2026 01:29:48 +0000 Subject: [PATCH 06/10] fix(test): repair malformed workflow assertion Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com> --- tests/test_submodule_workflows.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/test_submodule_workflows.py b/tests/test_submodule_workflows.py index 474c72c..beb9daf 100644 --- a/tests/test_submodule_workflows.py +++ b/tests/test_submodule_workflows.py @@ -52,7 +52,6 @@ def test_no_publish_secrets_during_dependency_analysis_or_staging(self) -> None: self.assertIn("commit-tree", before_publish) self.assertIn("Signed-off-by: github-actions[bot]", before_publish) self.assertNotIn("checkout --detach", before_publish) - self.assertNotIn('if self.assertIn("persist-credentials: false", before_publish) self.assertNotIn("force-with-lease", updater) self.assertIn("ref: $" + "{{ github.event.repository.default_branch }}", updater) From 5079eb62c015fc22cc82703710949ebf75766cbd Mon Sep 17 00:00:00 2001 From: Vitor Mattos <1079143+vitormattos@users.noreply.github.com> Date: Wed, 18 Nov 2026 01:31:00 +0000 Subject: [PATCH 07/10] fix(test): remove duplicated trailing test content Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com> --- tests/test_submodule_workflows.py | 72 ------------------------------- 1 file changed, 72 deletions(-) diff --git a/tests/test_submodule_workflows.py b/tests/test_submodule_workflows.py index beb9daf..36dfc7e 100644 --- a/tests/test_submodule_workflows.py +++ b/tests/test_submodule_workflows.py @@ -121,77 +121,5 @@ def test_linked_source_pr_authorization_cases(self) -> None: self.assertIn("11 resolver cases passed", result.stdout) -if __name__ == "__main__": - unittest.main() - + '{{ "$mode"', before_publish) - self.assertIn("persist-credentials: false", before_publish) - self.assertNotIn("force-with-lease", updater) - self.assertIn("ref: $" + "{{ github.event.repository.default_branch }}", updater) - - @staticmethod - def resolver() -> str: - lines = (ROOT / "workflow-templates/command-update-submodule.yml").read_text().splitlines() - start = lines.index(" script: |") + 1 - script = [] - for line in lines[start:]: - if line and not line.startswith(" "): - break - script.append(line[12:] if line else "") - return "\n".join(script) - - def test_linked_source_pr_authorization_cases(self) -> None: - if not shutil.which("node"): - self.skipTest("Node.js unavailable") - js = "const code = " + json.dumps(self.resolver()) + ";\n" + r""" -const assert = require('node:assert/strict'); -const runScript = new Function('github', 'context', 'core', 'process', - 'return (async () => {\n' + code + '\n})();'); -async function runCase(name, ok, edit = () => {}, path = '3rdparty') { - const parent = {state: 'open', body: '- [ ] 3rdparty: https://github.com/LibreSign/3rdparty/pull/17', - head: {ref: 'deps/update', sha: 'a'.repeat(40), - repo: {full_name: 'LibreSign/libresign'}}, base: {ref: 'main'}}; - const source = {merged_at: '2026-11-17T12:00:00Z', - merge_commit_sha: 'b'.repeat(40), base: {ref: 'main'}}; - edit(parent, source); - const outputs = {}; - const github = {rest: {pulls: {get: async (args) => ({ - data: args.repo === '3rdparty' ? source : parent - })}}}; - const context = {repo: {owner: 'LibreSign', repo: 'libresign'}, issue: {number: 33}}; - const core = {setOutput: (k, v) => { outputs[k] = v; }}; - const process = {env: {SUBMODULE_PATH: path, SOURCE_REPOSITORY: 'LibreSign/3rdparty'}}; - let err; - try { await runScript(github, context, core, process); } catch (e) { err = e; } - assert.equal(!Boolean(err), ok, name + ': ' + err); - if (ok) { - assert.equal(outputs.merge_sha, 'b'.repeat(40)); - assert.equal(outputs.source_pr, '17'); - } else { - assert.deepEqual(outputs, {}); - } -} -(async () => { - await runCase('valid', true); - await runCase('checked link', true, p => p.body = p.body.replace('[ ]', '[x]')); - await runCase('fork', false, p => p.head.repo.full_name = 'fork/libresign'); - await runCase('closed', false, p => p.state = 'closed'); - await runCase('wrong target', false, p => p.base.ref = 'feature'); - await runCase('not merged', false, (p,s) => s.merged_at = null); - await runCase('branch mismatch', false, (p,s) => s.base.ref = 'stable35'); - await runCase('no link', false, p => p.body = ''); - await runCase('duplicate', false, p => p.body += '\n' + p.body); - await runCase('wrong source', false, p => - p.body = p.body.replace('LibreSign/3rdparty', 'another/3rdparty')); - await runCase('unsafe path', false, () => {}, '../3rdparty'); - console.log('11 resolver cases passed'); -})().catch(e => { console.error(e); process.exitCode = 1; }); -""" - result = subprocess.run( - ["node", "-e", js], check=False, capture_output=True, text=True - ) - self.assertEqual(result.returncode, 0, result.stderr) - self.assertIn("11 resolver cases passed", result.stdout) - - if __name__ == "__main__": unittest.main() From 2a75cff7318334499053ced8b72d04bc0f795baf Mon Sep 17 00:00:00 2001 From: Vitor Mattos <1079143+vitormattos@users.noreply.github.com> Date: Wed, 18 Nov 2026 01:34:02 +0000 Subject: [PATCH 08/10] feat(ci): add tested reusable gitlink update action without PR checkout Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com> --- actions/update-submodule/action.yml | 30 +++++++ actions/update-submodule/update.js | 96 ++++++++++++++++++++++ actions/update-submodule/update.test.js | 103 ++++++++++++++++++++++++ 3 files changed, 229 insertions(+) create mode 100644 actions/update-submodule/action.yml create mode 100644 actions/update-submodule/update.js create mode 100644 actions/update-submodule/update.test.js diff --git a/actions/update-submodule/action.yml b/actions/update-submodule/action.yml new file mode 100644 index 0000000..c2284e8 --- /dev/null +++ b/actions/update-submodule/action.yml @@ -0,0 +1,30 @@ +# SPDX-FileCopyrightText: 2026 LibreCode coop and contributors +# SPDX-License-Identifier: AGPL-3.0-or-later + +name: Update a linked submodule from a merged pull request +description: Updates a gitlink through the GitHub API without checking out PR code. + +inputs: + token: + description: Token limited to the parent and source repository operations + required: true + source-repository: + description: Repository containing the already merged source pull request + required: true + submodule-path: + description: Gitlink path within the parent repository + required: true + +runs: + using: composite + steps: + - name: Verify and update submodule gitlink + uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 + env: + SUBMODULE_PATH: ${{ inputs.submodule-path }} + SOURCE_REPOSITORY: ${{ inputs.source-repository }} + with: + github-token: ${{ inputs.token }} + script: | + const run = require('${{ github.action_path }}/update.js') + await run({ github, context, core, env: process.env }) diff --git a/actions/update-submodule/update.js b/actions/update-submodule/update.js new file mode 100644 index 0000000..4af0622 --- /dev/null +++ b/actions/update-submodule/update.js @@ -0,0 +1,96 @@ +// SPDX-FileCopyrightText: 2026 LibreCode coop and contributors +// SPDX-License-Identifier: AGPL-3.0-or-later + +'use strict' + +const BOT = { + name: 'github-actions[bot]', + email: '41898282+github-actions[bot]@users.noreply.github.com', +} + +function validatePath(path) { + return /^[a-zA-Z0-9_.-]+(\/[a-zA-Z0-9_.-]+)*$/.test(path) && + !path.split('/').some(part => part === '.' || part === '..') +} + +async function updateSubmodule({ github, context, core, env }) { + const owner = context.repo.owner + const repo = context.repo.repo + const submodule = env.SUBMODULE_PATH + const sourceRepository = env.SOURCE_REPOSITORY + if (!validatePath(submodule) || + !/^[a-zA-Z0-9_.-]+\/[a-zA-Z0-9_.-]+$/.test(sourceRepository)) { + throw new Error('Invalid submodule path or source repository 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 !== owner + '/' + repo || + !/^(main|stable\d+)$/.test(pr.base.ref)) { + throw new Error('Only open, same-repository PRs targeting main or stable are supported') + } + + const prefix = submodule + ': https://github.com/' + sourceRepository + '/pull/' + const matches = (pr.body || '').split(/\r?\n/) + .map(line => line.match(/^\s*-\s*\[[ xX]\]\s*(.*)$/)) + .filter(Boolean) + .map(match => match[1].trim()) + .filter(text => text.startsWith(prefix)) + if (matches.length !== 1) { + throw new Error('Expected exactly one linked submodule PR') + } + const sourceNumber = matches[0].slice(prefix.length).trim() + if (!/^[1-9]\d*$/.test(sourceNumber)) { + throw new Error('Invalid linked submodule PR number') + } + const [sourceOwner, sourceName] = sourceRepository.split('/') + const { data: source } = await github.rest.pulls.get({ + owner: sourceOwner, repo: sourceName, pull_number: Number(sourceNumber), + }) + if (!source.merged_at || !/^[a-f0-9]{40}$/.test(source.merge_commit_sha || '') || + source.base.ref !== pr.base.ref) { + throw new Error('The linked dependency PR must be merged into the same target branch') + } + + const { data: commit } = await github.rest.git.getCommit({ + owner, repo, commit_sha: pr.head.sha, + }) + const { data: currentTree } = await github.rest.git.getTree({ + owner, repo, tree_sha: commit.tree.sha, + }) + const gitlink = currentTree.tree.find(entry => + entry.path === submodule && entry.mode === '160000') + if (!gitlink) { + throw new Error('The configured path is not a git submodule') + } + if (gitlink.sha === source.merge_commit_sha) { + core.notice('Submodule already references the merged dependency') + return + } + + const { data: tree } = await github.rest.git.createTree({ + owner, repo, base_tree: commit.tree.sha, + tree: [{ path: submodule, mode: '160000', type: 'commit', + sha: source.merge_commit_sha }], + }) + const subject = 'chore(deps): update ' + submodule + + ' from merged PR #' + sourceNumber + const message = subject + '\n\nSigned-off-by: ' + + BOT.name + ' <' + BOT.email + '>' + const { data: updated } = await github.rest.git.createCommit({ + owner, repo, message, tree: tree.sha, parents: [pr.head.sha], + author: BOT, committer: BOT, + }) + await github.rest.git.updateRef({ + owner, repo, ref: 'heads/' + pr.head.ref, sha: updated.sha, force: false, + }) + await github.rest.issues.createComment({ + owner, repo, issue_number: context.issue.number, + body: 'Updated ' + submodule + ' to ' + sourceRepository + '#' + + sourceNumber + ' (' + source.merge_commit_sha + ').', + }) +} + +module.exports = updateSubmodule diff --git a/actions/update-submodule/update.test.js b/actions/update-submodule/update.test.js new file mode 100644 index 0000000..2adfbf1 --- /dev/null +++ b/actions/update-submodule/update.test.js @@ -0,0 +1,103 @@ +// SPDX-FileCopyrightText: 2026 LibreCode coop and contributors +// SPDX-License-Identifier: AGPL-3.0-or-later + +'use strict' + +const test = require('node:test') +const assert = require('node:assert/strict') +const update = require('./update.js') + +const sha = chr => chr.repeat(40) + +function fixture(change = () => {}, envChange = {}) { + const parent = { + state: 'open', + head: { repo: {full_name: 'LibreSign/libresign'}, ref: 'deps/upgrade', sha: sha('a') }, + base: {ref: 'main'}, + body: '- [ ] 3rdparty: https://github.com/LibreSign/3rdparty/pull/17', + } + const source = { + merged_at: '2026-11-17T12:00:00Z', + merge_commit_sha: sha('b'), + base: {ref: 'main'}, + } + const gitlink = {path: '3rdparty', mode: '160000', type: 'commit', sha: sha('c')} + change({parent, source, gitlink}) + const calls = [] + const wrap = (name, fn) => async args => { + calls.push({name, args}) + return {data: await fn(args)} + } + const github = {rest: { + pulls: {get: wrap('pulls.get', args => args.repo === '3rdparty' ? source : parent)}, + git: { + getCommit: wrap('git.getCommit', () => ({tree: {sha: sha('d')}})), + getTree: wrap('git.getTree', () => ({tree: [gitlink]})), + createTree: wrap('git.createTree', () => ({sha: sha('e')})), + createCommit: wrap('git.createCommit', () => ({sha: sha('f')})), + updateRef: wrap('git.updateRef', () => ({})), + }, + issues: {createComment: wrap('issues.createComment', () => ({}))}, + }} + const notices = [] + const context = {repo: {owner: 'LibreSign', repo: 'libresign'}, issue: {number: 42}} + const core = {notice: text => notices.push(text)} + const env = {SUBMODULE_PATH: '3rdparty', SOURCE_REPOSITORY: 'LibreSign/3rdparty', ...envChange} + return {github, context, core, env, calls, notices} +} + +test('updates only the gitlink at the exact merged SHA, with DCO and no force push', async () => { + const f = fixture() + await update(f) + const tree = f.calls.find(x => x.name === 'git.createTree').args + assert.deepEqual(tree.tree, [{path: '3rdparty', mode: '160000', type: 'commit', sha: sha('b')}]) + assert.equal(tree.base_tree, sha('d')) + const commit = f.calls.find(x => x.name === 'git.createCommit').args + assert.deepEqual(commit.parents, [sha('a')]) + assert.match(commit.message, /Signed-off-by: github-actions\[bot\]/) + const pushed = f.calls.find(x => x.name === 'git.updateRef').args + assert.equal(pushed.force, false) + assert.equal(pushed.ref, 'heads/deps/upgrade') + assert.equal(f.calls.at(-1).name, 'issues.createComment') +}) + +const cases = [ + ['fork is rejected', ({parent}) => {parent.head.repo.full_name = 'fork/libresign'}], + ['closed target is rejected', ({parent}) => {parent.state = 'closed'}], + ['unsupported target branch is rejected', ({parent}) => {parent.base.ref = 'feature'}], + ['missing linked source PR is rejected', ({parent}) => {parent.body = ''}], + ['duplicate linked source PRs are rejected', ({parent}) => {parent.body += '\n' + parent.body}], + ['unmerged source is rejected', ({source}) => {source.merged_at = null}], + ['mismatched source branch is rejected', ({source}) => {source.base.ref = 'stable35'}], + ['unrecognized submodule is rejected', ({gitlink}) => {gitlink.path = 'other'}], +] +for (const [name, change] of cases) { + test(name, async () => { + const f = fixture(change) + await assert.rejects(update(f)) + assert.equal(f.calls.some(x => x.name === 'git.createCommit'), false) + }) +} + +test('path traversal is rejected before any API access', async () => { + const f = fixture(() => {}, {SUBMODULE_PATH: '../3rdparty'}) + await assert.rejects(update(f), /Invalid submodule path/) + assert.equal(f.calls.length, 0) +}) + +test('idempotent update does not create commits or comments', async () => { + const f = fixture(({source, gitlink}) => {gitlink.sha = source.merge_commit_sha}) + await update(f) + assert.equal(f.calls.some(x => x.name === 'git.createCommit'), false) + assert.equal(f.calls.some(x => x.name === 'issues.createComment'), false) + assert.equal(f.notices.length, 1) +}) + +test('concurrent ref movement rejects without reporting success', async () => { + const f = fixture() + f.github.rest.git.updateRef = async () => { + throw new Error('Reference changed') + } + await assert.rejects(update(f), /Reference changed/) + assert.equal(f.calls.some(x => x.name === 'issues.createComment'), false) +}) From cb99101664010cd1448218b16d77bf02f6aa6d63 Mon Sep 17 00:00:00 2001 From: Vitor Mattos <1079143+vitormattos@users.noreply.github.com> Date: Wed, 18 Nov 2026 01:34:38 +0000 Subject: [PATCH 09/10] refactor(ci): delegate submodule mutation to pinned tested shared action Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com> --- .../command-update-submodule.yml.patch | 133 +++--------------- tests/test_submodule_workflows.py | 98 ++++--------- .../command-update-submodule.yml | 119 +--------------- 3 files changed, 48 insertions(+), 302 deletions(-) diff --git a/patches/nextcloud/command-update-submodule.yml.patch b/patches/nextcloud/command-update-submodule.yml.patch index 2424710..3b476ed 100644 --- a/patches/nextcloud/command-update-submodule.yml.patch +++ b/patches/nextcloud/command-update-submodule.yml.patch @@ -1,6 +1,6 @@ --- upstream/vendor/nextcloud/command-update-submodule.yml +++ workflow-templates/command-update-submodule.yml -@@ -1,128 +1,138 @@ +@@ -1,128 +1,29 @@ # SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors +# SPDX-FileCopyrightText: 2026 LibreCode coop and contributors # SPDX-License-Identifier: MIT @@ -21,9 +21,6 @@ + if: github.event.issue.pull_request != '' && vars.SUBMODULE_UPDATE_COMMAND != '' && github.event.comment.body == vars.SUBMODULE_UPDATE_COMMAND - rebase: runs-on: ubuntu-latest -+ env: -+ SUBMODULE_PATH: ${{ vars.SUBMODULE_PATH }} -+ SOURCE_REPOSITORY: ${{ vars.SUBMODULE_SOURCE_REPOSITORY }} - permissions: - contents: none - pull-requests: read @@ -60,113 +57,36 @@ 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 - - name: Add reaction on start - uses: peter-evans/create-or-update-comment@e8674b075228eee787fea43ef493e45ece1004c9 # v5.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); ++ token: ${{ secrets.COMMAND_BOT_PAT }} # zizmor: ignore[secrets-outside-env] ++ source-repository: ${{ vars.SUBMODULE_SOURCE_REPOSITORY }} ++ submodule-path: ${{ vars.SUBMODULE_PATH }} - token: ${{ secrets.COMMAND_BOT_PAT }} - repository: ${{ github.event.repository.full_name }} - comment-id: ${{ github.event.comment.id }} - reactions: '+1' - -+ - name: Checkout trusted default branch +- - - name: Init branch - uses: xt0rted/pull-request-comment-branch@e8b8daa837e8ea7331c0003c9c316a64c6d8b0b1 # v3.0.0 - id: comment-branch - - - name: Checkout ${{ steps.comment-branch.outputs.head_ref }} - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - with: - persist-credentials: false +- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 +- with: +- persist-credentials: false - submodules: true - fetch-depth: 0 -+ ref: ${{ github.event.repository.default_branch }} +- fetch-depth: 0 - token: ${{ secrets.COMMAND_BOT_PAT }} - ref: ${{ steps.comment-branch.outputs.head_ref }} - -+ - name: Stage and commit submodule pointer -+ id: update -+ shell: bash +- - - name: Register server reference to fallback to master branch - env: -+ HEAD_SHA: ${{ steps.resolve.outputs.head_sha }} -+ MERGE_SHA: ${{ steps.resolve.outputs.merge_sha }} -+ SOURCE_PR: ${{ steps.resolve.outputs.source_pr }} +- env: - base_ref: ${{ steps.get-pr.outputs.base_ref }} - 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 +- run: | - if [[ "$base_ref" == "main" || "$base_ref" == "master" ]]; then - echo "server_ref=master" >> "$GITHUB_ENV" - echo "Setting server_ref to master" @@ -175,12 +95,8 @@ - echo "Setting server_ref to $base_ref" - else - echo "Not based on master/main/stable*, so skipping pull 3rdparty command" - 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' +- fi +- - - name: Setup git - run: | - git config --local user.email 'nextcloud-command@users.noreply.github.com' @@ -203,22 +119,9 @@ - - - name: Commit and push changes - if: ${{ env.server_ref != '' }} - 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 +- env: - BOT_TOKEN: ${{ secrets.COMMAND_BOT_PAT }} # zizmor: ignore[secrets-outside-env] - 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)." +- run: | - git add 3rdparty - git remote set-url origin "https://x-access-token:${BOT_TOKEN}@github.com/${{ github.repository }}.git" - if git diff --quiet HEAD~1 HEAD -- 3rdparty; then diff --git a/tests/test_submodule_workflows.py b/tests/test_submodule_workflows.py index 36dfc7e..0c257bf 100644 --- a/tests/test_submodule_workflows.py +++ b/tests/test_submodule_workflows.py @@ -1,7 +1,7 @@ # SPDX-FileCopyrightText: 2026 LibreCode coop and contributors # SPDX-License-Identifier: AGPL-3.0-or-later -"""Contracts for the inherited submodule command workflows.""" +"""Contracts for inherited, testable submodule commands.""" import hashlib import json @@ -32,7 +32,7 @@ def test_upstream_provenance_and_rendering(self) -> None: self.assertEqual(hashlib.sha256(source).hexdigest(), item["sha256"]) check(load_templates(ROOT / "upstream/templates.json"), ROOT) - def test_no_publish_secrets_during_dependency_analysis_or_staging(self) -> None: + def test_no_publish_secrets_during_composer_analysis(self) -> None: source = (ROOT / "workflow-templates/command-submodule-pr.yml").read_text() process = source.split(" process:\n", 1)[1] before_publish = process.split( @@ -43,82 +43,34 @@ def test_no_publish_secrets_during_dependency_analysis_or_staging(self) -> None: self.assertIn("persist-credentials: false", before_publish) self.assertIn("gh auth setup-git", process) - updater = (ROOT / "workflow-templates/command-update-submodule.yml").read_text() - before_publish = updater.split( - " - name: Push updated reference and comment", 1 - )[0] - self.assertNotIn("secrets.COMMAND_BOT_PAT", before_publish) - self.assertIn('git read-tree "$HEAD_SHA^{tree}"', before_publish) - self.assertIn("commit-tree", before_publish) - self.assertIn("Signed-off-by: github-actions[bot]", before_publish) - self.assertNotIn("checkout --detach", before_publish) - self.assertIn("persist-credentials: false", before_publish) - self.assertNotIn("force-with-lease", updater) - self.assertIn("ref: $" + "{{ github.event.repository.default_branch }}", updater) - - @staticmethod - def resolver() -> str: - lines = (ROOT / "workflow-templates/command-update-submodule.yml").read_text().splitlines() - start = lines.index(" script: |") + 1 - script = [] - for line in lines[start:]: - if line and not line.startswith(" "): - break - script.append(line[12:] if line else "") - return "\n".join(script) + def test_update_is_composite_action_without_pr_checkout(self) -> None: + workflow = (ROOT / "workflow-templates/command-update-submodule.yml").read_text() + self.assertNotIn("actions/checkout", workflow) + self.assertNotIn("git read-tree", workflow) + self.assertIn("Check actor permission", workflow) + self.assertRegex( + workflow, + r"uses: LibreCodeCoop/\.github/actions/update-submodule@[0-9a-f]{40}", + ) + action = (ROOT / "actions/update-submodule/action.yml").read_text() + self.assertIn("uses: actions/github-script@", action) + self.assertIn("source-repository:", action) + self.assertIn("submodule-path:", action) + impl = (ROOT / "actions/update-submodule/update.js").read_text() + for contract in ("force: false", "Signed-off-by:", "createTree", + "createCommit", "updateRef"): + self.assertIn(contract, impl) - def test_linked_source_pr_authorization_cases(self) -> None: + def test_update_action_negative_and_positive_cases(self) -> None: if not shutil.which("node"): self.skipTest("Node.js unavailable") - js = "const code = " + json.dumps(self.resolver()) + ";\n" + r""" -const assert = require('node:assert/strict'); -const runScript = new Function('github', 'context', 'core', 'process', - 'return (async () => {\n' + code + '\n})();'); -async function runCase(name, ok, edit = () => {}, path = '3rdparty') { - const parent = {state: 'open', body: '- [ ] 3rdparty: https://github.com/LibreSign/3rdparty/pull/17', - head: {ref: 'deps/update', sha: 'a'.repeat(40), - repo: {full_name: 'LibreSign/libresign'}}, base: {ref: 'main'}}; - const source = {merged_at: '2026-11-17T12:00:00Z', - merge_commit_sha: 'b'.repeat(40), base: {ref: 'main'}}; - edit(parent, source); - const outputs = {}; - const github = {rest: {pulls: {get: async (args) => ({ - data: args.repo === '3rdparty' ? source : parent - })}}}; - const context = {repo: {owner: 'LibreSign', repo: 'libresign'}, issue: {number: 33}}; - const core = {setOutput: (k, v) => { outputs[k] = v; }}; - const process = {env: {SUBMODULE_PATH: path, SOURCE_REPOSITORY: 'LibreSign/3rdparty'}}; - let err; - try { await runScript(github, context, core, process); } catch (e) { err = e; } - assert.equal(!Boolean(err), ok, name + ': ' + err); - if (ok) { - assert.equal(outputs.merge_sha, 'b'.repeat(40)); - assert.equal(outputs.source_pr, '17'); - } else { - assert.deepEqual(outputs, {}); - } -} -(async () => { - await runCase('valid', true); - await runCase('checked link', true, p => p.body = p.body.replace('[ ]', '[x]')); - await runCase('fork', false, p => p.head.repo.full_name = 'fork/libresign'); - await runCase('closed', false, p => p.state = 'closed'); - await runCase('wrong target', false, p => p.base.ref = 'feature'); - await runCase('not merged', false, (p,s) => s.merged_at = null); - await runCase('branch mismatch', false, (p,s) => s.base.ref = 'stable35'); - await runCase('no link', false, p => p.body = ''); - await runCase('duplicate', false, p => p.body += '\n' + p.body); - await runCase('wrong source', false, p => - p.body = p.body.replace('LibreSign/3rdparty', 'another/3rdparty')); - await runCase('unsafe path', false, () => {}, '../3rdparty'); - console.log('11 resolver cases passed'); -})().catch(e => { console.error(e); process.exitCode = 1; }); -""" + test_file = ROOT / "actions/update-submodule/update.test.js" result = subprocess.run( - ["node", "-e", js], check=False, capture_output=True, text=True + ["node", "--test", str(test_file)], + check=False, capture_output=True, text=True, ) - self.assertEqual(result.returncode, 0, result.stderr) - self.assertIn("11 resolver cases passed", result.stdout) + self.assertEqual(result.returncode, 0, result.stderr + result.stdout) + self.assertIn("fail 0", result.stdout) if __name__ == "__main__": diff --git a/workflow-templates/command-update-submodule.yml b/workflow-templates/command-update-submodule.yml index 59fcb47..c75edbc 100644 --- a/workflow-templates/command-update-submodule.yml +++ b/workflow-templates/command-update-submodule.yml @@ -15,124 +15,15 @@ jobs: update: 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: ${{ vars.SUBMODULE_PATH }} - SOURCE_REPOSITORY: ${{ vars.SUBMODULE_SOURCE_REPOSITORY }} 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: ${{ 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" - # 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: ${{ vars.SUBMODULE_SOURCE_REPOSITORY }} + submodule-path: ${{ vars.SUBMODULE_PATH }} From b19b4f6701bcdac30fd1dd249714efbe9794f3de Mon Sep 17 00:00:00 2001 From: Vitor Mattos <1079143+vitormattos@users.noreply.github.com> Date: Wed, 18 Nov 2026 01:38:17 +0000 Subject: [PATCH 10/10] refactor(ci): own secure updater instead of replacing Nextcloud Server workflow wholesale Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com> --- docs/cross-repository-automation.md | 12 +- .../command-update-submodule.yml.patch | 142 ------------------ tests/test_submodule_workflows.py | 1 - upstream/sources.json | 9 -- upstream/templates.json | 8 - .../nextcloud/command-update-submodule.yml | 128 ---------------- .../command-update-submodule.yml | 3 +- 7 files changed, 9 insertions(+), 294 deletions(-) delete mode 100644 patches/nextcloud/command-update-submodule.yml.patch delete mode 100644 upstream/vendor/nextcloud/command-update-submodule.yml diff --git a/docs/cross-repository-automation.md b/docs/cross-repository-automation.md index 5abb744..a2b825e 100644 --- a/docs/cross-repository-automation.md +++ b/docs/cross-repository-automation.md @@ -54,10 +54,14 @@ The catalog updater targets only the consumer's default branch by default. Proje ## Submodule dependency commands -The optional `command-submodule-pr.yml` and `command-update-submodule.yml` -templates track pinned sources from `nextcloud/3rdparty` and `nextcloud/server`. -The differences needed for other repositories are managed as reviewable -`patches/nextcloud/` and verified against immutable upstream checksums. +`command-submodule-pr.yml` tracks a pinned upstream workflow from +`nextcloud/3rdparty`; its generic changes live in `patches/nextcloud/` +and are verified against immutable upstream checksums. + +`command-update-submodule.yml` is LibreCode-owned. It delegates to the +version-pinned, tested `actions/update-submodule` Action: the Nextcloud Server +command is a conceptual reference, but its implementation is intentionally +not copied because it updates a moving branch tip and can rewrite commits. A consumer must install each workflow and configure its parameters using Actions variables or a consumer-local `.github/workflows/.yml.patch`: diff --git a/patches/nextcloud/command-update-submodule.yml.patch b/patches/nextcloud/command-update-submodule.yml.patch deleted file mode 100644 index 3b476ed..0000000 --- a/patches/nextcloud/command-update-submodule.yml.patch +++ /dev/null @@ -1,142 +0,0 @@ ---- upstream/vendor/nextcloud/command-update-submodule.yml -+++ workflow-templates/command-update-submodule.yml -@@ -1,128 +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 --name: Update 3rdparty command - - on: - issue_comment: # zizmor: ignore[dangerous-triggers] -+ types: [created] -- types: created - - permissions: - contents: read -+ pull-requests: read - - jobs: -+ update: -+ if: github.event.issue.pull_request != '' && vars.SUBMODULE_UPDATE_COMMAND != '' && github.event.comment.body == vars.SUBMODULE_UPDATE_COMMAND -- rebase: - runs-on: ubuntu-latest -- permissions: -- contents: none -- pull-requests: read -- -- # On pull requests and if the comment starts with `/update-3rdparty` -- if: github.event.issue.pull_request != '' && startsWith(github.event.comment.body, '/update-3rdparty') -- - steps: -- # issue_comment events carry no pull_request context in their payload, so we -- # must fetch the PR via the API. This also gives us base.ref for free, avoiding -- # a second API call. The GITHUB_TOKEN needs pull-requests:read (granted above). -- - name: Get pull request metadata -- uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 -- id: get-pr -- with: -- github-token: ${{ secrets.GITHUB_TOKEN }} -- script: | -- const pull = await github.rest.pulls.get({ -- owner: context.repo.owner, -- repo: context.repo.repo, -- pull_number: context.issue.number, -- }); -- core.setOutput('head_repo', pull.data.head.repo?.full_name ?? ''); -- core.setOutput('base_ref', pull.data.base.ref); -- -- - name: Disabled on forks -- if: steps.get-pr.outputs.head_repo != github.repository -- run: | -- echo 'Can not execute /update-3rdparty on forks' -- exit 1 -- - - name: Check actor permission - uses: skjnldsv/check-actor-permission@69e92a3c4711150929bca9fcf34448c5bf5526e7 # v3.0 - with: - require: write - -+ - name: Update merged submodule reference -+ uses: LibreCodeCoop/.github/actions/update-submodule@2a75cff7318334499053ced8b72d04bc0f795baf # source pinned -- - name: Add reaction on start -- uses: peter-evans/create-or-update-comment@e8674b075228eee787fea43ef493e45ece1004c9 # v5.0.0 - with: -+ token: ${{ secrets.COMMAND_BOT_PAT }} # zizmor: ignore[secrets-outside-env] -+ source-repository: ${{ vars.SUBMODULE_SOURCE_REPOSITORY }} -+ submodule-path: ${{ vars.SUBMODULE_PATH }} -- token: ${{ secrets.COMMAND_BOT_PAT }} -- repository: ${{ github.event.repository.full_name }} -- comment-id: ${{ github.event.comment.id }} -- reactions: '+1' -- -- - name: Init branch -- uses: xt0rted/pull-request-comment-branch@e8b8daa837e8ea7331c0003c9c316a64c6d8b0b1 # v3.0.0 -- id: comment-branch -- -- - name: Checkout ${{ steps.comment-branch.outputs.head_ref }} -- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 -- with: -- persist-credentials: false -- submodules: true -- fetch-depth: 0 -- token: ${{ secrets.COMMAND_BOT_PAT }} -- ref: ${{ steps.comment-branch.outputs.head_ref }} -- -- - name: Register server reference to fallback to master branch -- env: -- base_ref: ${{ steps.get-pr.outputs.base_ref }} -- run: | -- if [[ "$base_ref" == "main" || "$base_ref" == "master" ]]; then -- echo "server_ref=master" >> "$GITHUB_ENV" -- echo "Setting server_ref to master" -- elif [[ "$base_ref" =~ ^stable[0-9]+$ ]]; then -- echo "server_ref=$base_ref" >> "$GITHUB_ENV" -- echo "Setting server_ref to $base_ref" -- else -- echo "Not based on master/main/stable*, so skipping pull 3rdparty command" -- fi -- -- - name: Setup git -- run: | -- git config --local user.email 'nextcloud-command@users.noreply.github.com' -- git config --local user.name 'nextcloud-command' -- -- - name: Add reaction on failure -- uses: peter-evans/create-or-update-comment@e8674b075228eee787fea43ef493e45ece1004c9 # v5.0.0 -- if: ${{ env.server_ref == '' }} -- with: -- token: ${{ secrets.COMMAND_BOT_PAT }} -- repository: ${{ github.event.repository.full_name }} -- comment-id: ${{ github.event.comment.id }} -- reactions: '-1' -- -- - name: Pull 3rdparty -- if: ${{ env.server_ref != '' }} -- run: | -- git -C 3rdparty fetch origin "$server_ref" -- git -C 3rdparty checkout FETCH_HEAD -- -- - name: Commit and push changes -- if: ${{ env.server_ref != '' }} -- env: -- BOT_TOKEN: ${{ secrets.COMMAND_BOT_PAT }} # zizmor: ignore[secrets-outside-env] -- run: | -- git add 3rdparty -- git remote set-url origin "https://x-access-token:${BOT_TOKEN}@github.com/${{ github.repository }}.git" -- if git diff --quiet HEAD~1 HEAD -- 3rdparty; then -- git commit -s -m "chore(3rdparty): Update submodule to latest $server_ref" -- git push -- else -- git commit -s --amend --no-edit -- git push --force-with-lease -- fi -- -- - name: Add reaction on failure -- uses: peter-evans/create-or-update-comment@e8674b075228eee787fea43ef493e45ece1004c9 # v5.0.0 -- if: failure() -- with: -- token: ${{ secrets.COMMAND_BOT_PAT }} -- repository: ${{ github.event.repository.full_name }} -- comment-id: ${{ github.event.comment.id }} -- reactions: '-1' diff --git a/tests/test_submodule_workflows.py b/tests/test_submodule_workflows.py index 0c257bf..aef5412 100644 --- a/tests/test_submodule_workflows.py +++ b/tests/test_submodule_workflows.py @@ -21,7 +21,6 @@ def test_upstream_provenance_and_rendering(self) -> None: manifest = json.loads((ROOT / "upstream/sources.json").read_text()) expected = { "nextcloud-command-submodule-pr": "nextcloud/3rdparty", - "nextcloud-command-update-submodule": "nextcloud/server", } for name, repo in expected.items(): with self.subTest(name=name): diff --git a/upstream/sources.json b/upstream/sources.json index 1b75699..5232210 100644 --- a/upstream/sources.json +++ b/upstream/sources.json @@ -188,15 +188,6 @@ "url": "https://raw.githubusercontent.com/nextcloud/3rdparty/ee8d3bf7a2bfcbc1946da3ffd5afb1b08e317527/.github/workflows/command-server-pr.yml", "sha256": "856720db49f76fba680b32582bdba88be4d7fc5064aaa7090b3fb77ae03e4ba9", "destination": "upstream/vendor/nextcloud/command-submodule-pr.yml" - }, - { - "name": "nextcloud-command-update-submodule", - "repository": "nextcloud/server", - "ref": "master", - "path": ".github/workflows/command-pull-3rdparty.yml", - "url": "https://raw.githubusercontent.com/nextcloud/server/1e2085f7a0deaeaf7d28d4ce2bb26448cdecd3d9/.github/workflows/command-pull-3rdparty.yml", - "sha256": "172935e15a88386b5587be26edc6dac73b026470735873339a457bd9c5572e68", - "destination": "upstream/vendor/nextcloud/command-update-submodule.yml" } ] } diff --git a/upstream/templates.json b/upstream/templates.json index 3d4ac64..2f2e3ca 100644 --- a/upstream/templates.json +++ b/upstream/templates.json @@ -154,14 +154,6 @@ "patches/nextcloud/command-submodule-pr.yml.patch" ], "destination": "workflow-templates/command-submodule-pr.yml" - }, - { - "name": "nextcloud-command-update-submodule", - "source": "upstream/vendor/nextcloud/command-update-submodule.yml", - "patches": [ - "patches/nextcloud/command-update-submodule.yml.patch" - ], - "destination": "workflow-templates/command-update-submodule.yml" } ], "runner_aliases": { diff --git a/upstream/vendor/nextcloud/command-update-submodule.yml b/upstream/vendor/nextcloud/command-update-submodule.yml deleted file mode 100644 index 79e3455..0000000 --- a/upstream/vendor/nextcloud/command-update-submodule.yml +++ /dev/null @@ -1,128 +0,0 @@ -# SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors -# SPDX-License-Identifier: MIT -name: Update 3rdparty command - -on: - issue_comment: # zizmor: ignore[dangerous-triggers] - types: created - -permissions: - contents: read - -jobs: - rebase: - runs-on: ubuntu-latest - permissions: - contents: none - pull-requests: read - - # On pull requests and if the comment starts with `/update-3rdparty` - if: github.event.issue.pull_request != '' && startsWith(github.event.comment.body, '/update-3rdparty') - - steps: - # issue_comment events carry no pull_request context in their payload, so we - # must fetch the PR via the API. This also gives us base.ref for free, avoiding - # a second API call. The GITHUB_TOKEN needs pull-requests:read (granted above). - - name: Get pull request metadata - uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 - id: get-pr - with: - github-token: ${{ secrets.GITHUB_TOKEN }} - script: | - const pull = await github.rest.pulls.get({ - owner: context.repo.owner, - repo: context.repo.repo, - pull_number: context.issue.number, - }); - core.setOutput('head_repo', pull.data.head.repo?.full_name ?? ''); - core.setOutput('base_ref', pull.data.base.ref); - - - name: Disabled on forks - if: steps.get-pr.outputs.head_repo != github.repository - run: | - echo 'Can not execute /update-3rdparty on forks' - exit 1 - - - name: Check actor permission - uses: skjnldsv/check-actor-permission@69e92a3c4711150929bca9fcf34448c5bf5526e7 # v3.0 - with: - require: write - - - name: Add reaction on start - uses: peter-evans/create-or-update-comment@e8674b075228eee787fea43ef493e45ece1004c9 # v5.0.0 - with: - token: ${{ secrets.COMMAND_BOT_PAT }} - repository: ${{ github.event.repository.full_name }} - comment-id: ${{ github.event.comment.id }} - reactions: '+1' - - - name: Init branch - uses: xt0rted/pull-request-comment-branch@e8b8daa837e8ea7331c0003c9c316a64c6d8b0b1 # v3.0.0 - id: comment-branch - - - name: Checkout ${{ steps.comment-branch.outputs.head_ref }} - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - with: - persist-credentials: false - submodules: true - fetch-depth: 0 - token: ${{ secrets.COMMAND_BOT_PAT }} - ref: ${{ steps.comment-branch.outputs.head_ref }} - - - name: Register server reference to fallback to master branch - env: - base_ref: ${{ steps.get-pr.outputs.base_ref }} - run: | - if [[ "$base_ref" == "main" || "$base_ref" == "master" ]]; then - echo "server_ref=master" >> "$GITHUB_ENV" - echo "Setting server_ref to master" - elif [[ "$base_ref" =~ ^stable[0-9]+$ ]]; then - echo "server_ref=$base_ref" >> "$GITHUB_ENV" - echo "Setting server_ref to $base_ref" - else - echo "Not based on master/main/stable*, so skipping pull 3rdparty command" - fi - - - name: Setup git - run: | - git config --local user.email 'nextcloud-command@users.noreply.github.com' - git config --local user.name 'nextcloud-command' - - - name: Add reaction on failure - uses: peter-evans/create-or-update-comment@e8674b075228eee787fea43ef493e45ece1004c9 # v5.0.0 - if: ${{ env.server_ref == '' }} - with: - token: ${{ secrets.COMMAND_BOT_PAT }} - repository: ${{ github.event.repository.full_name }} - comment-id: ${{ github.event.comment.id }} - reactions: '-1' - - - name: Pull 3rdparty - if: ${{ env.server_ref != '' }} - run: | - git -C 3rdparty fetch origin "$server_ref" - git -C 3rdparty checkout FETCH_HEAD - - - name: Commit and push changes - if: ${{ env.server_ref != '' }} - env: - BOT_TOKEN: ${{ secrets.COMMAND_BOT_PAT }} # zizmor: ignore[secrets-outside-env] - run: | - git add 3rdparty - git remote set-url origin "https://x-access-token:${BOT_TOKEN}@github.com/${{ github.repository }}.git" - if git diff --quiet HEAD~1 HEAD -- 3rdparty; then - git commit -s -m "chore(3rdparty): Update submodule to latest $server_ref" - git push - else - git commit -s --amend --no-edit - git push --force-with-lease - fi - - - name: Add reaction on failure - uses: peter-evans/create-or-update-comment@e8674b075228eee787fea43ef493e45ece1004c9 # v5.0.0 - if: failure() - with: - token: ${{ secrets.COMMAND_BOT_PAT }} - repository: ${{ github.event.repository.full_name }} - comment-id: ${{ github.event.comment.id }} - reactions: '-1' diff --git a/workflow-templates/command-update-submodule.yml b/workflow-templates/command-update-submodule.yml index c75edbc..f1eee96 100644 --- a/workflow-templates/command-update-submodule.yml +++ b/workflow-templates/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: