From 2a7824c16063c149968642b07140e11fa4080c44 Mon Sep 17 00:00:00 2001 From: Maksim Sukharev Date: Wed, 21 Oct 2026 18:05:11 +0200 Subject: [PATCH] feat(dispatch-workflow): reapply workflow patches like the sync workflow - Dispatch overwrote the workflows and dropped repository changes stored as `workflow.yml.patch` - Use the same patch handling as `sync-workflow-templates.yml` - If a patch fails, the PR is a draft and its body lists the failed workflow - Only commit `.github/workflows/*.yml`, so `.orig` and `.rej` files stay out of the PR - Mention the dispatch workflows in the "Patching workflows" section of the README Assisted-by: ClaudeCode:claude-opus-5-5 Signed-off-by: Maksim Sukharev --- .github/workflows/dispatch-workflow-repo.yml | 28 ++++++++++++++++- .github/workflows/dispatch-workflow.yml | 33 ++++++++++++++++++-- README.md | 4 +-- 3 files changed, 60 insertions(+), 5 deletions(-) diff --git a/.github/workflows/dispatch-workflow-repo.yml b/.github/workflows/dispatch-workflow-repo.yml index e9439645..5097b63c 100644 --- a/.github/workflows/dispatch-workflow-repo.yml +++ b/.github/workflows/dispatch-workflow-repo.yml @@ -65,6 +65,8 @@ jobs: - name: Copy all workflow templates run: | + echo 'SUMMARY<> $GITHUB_ENV + draft_only=0 for workflow in ./source/workflow-templates/*.yml; do if [ -f "$workflow" ]; then filename=$(basename "$workflow") @@ -73,18 +75,42 @@ jobs: # Only copy if the file exists in the target repository if [ -f "$target_file" ]; then echo "Updating existing workflow: $filename" + echo "- 🆙 Updated $filename" >> $GITHUB_ENV cp "$workflow" "$target_file" + + # Apply patch if one exists + if [ -f "$target_file.patch" ]; then + echo "🩹 Applying patch" + cd ./target + set +e + patch -p1 < ".github/workflows/$filename.patch" + patch_worked=$? + set -e + cd - + if [[ "$patch_worked" == "0" ]]; then + echo " - Patch applied" >> $GITHUB_ENV + else + echo " - [ ] ❌ Patch failed" >> $GITHUB_ENV + draft_only=1 + fi + fi else echo "Skipping $filename (does not exist in target repository)" fi fi done + echo 'EOF' >> $GITHUB_ENV + echo "DRAFT_ONLY=${draft_only}" >> $GITHUB_ENV - name: Create Pull Request uses: peter-evans/create-pull-request@5f6978faf089d4d20b00c7766989d076bb2fc7f1 # v8.1.1 with: - body: 'Automated update of all workflow templates from https://github.com/${{ github.repository }} triggered by ${{ github.actor }}' + body: | + Automated update of all workflow templates from https://github.com/${{ github.repository }} triggered by ${{ github.actor }} + ${{ env.SUMMARY }} branch: 'feat/workflow-auto-update-all-templates-${{ github.event.inputs.branch }}' + draft: ${{ env.DRAFT_ONLY == 1 }} + add-paths: .github/workflows/*.yml commit-message: 'ci: update all workflow templates from organization template repository' committer: Nextcloud bot author: Nextcloud bot diff --git a/.github/workflows/dispatch-workflow.yml b/.github/workflows/dispatch-workflow.yml index 02861016..2827e8e1 100644 --- a/.github/workflows/dispatch-workflow.yml +++ b/.github/workflows/dispatch-workflow.yml @@ -93,14 +93,43 @@ jobs: - name: Copy workflow # zizmor: ignore[template-injection] if: steps.check_file_existence.outputs.files_exists == 'true' - run: cp './source/workflow-templates/${{ github.event.inputs.name }}' ./target/.github/workflows + run: | + echo 'SUMMARY<> $GITHUB_ENV + draft_only=0 + filename='${{ github.event.inputs.name }}' + target_file="./target/.github/workflows/$filename" + echo "- 🆙 Updated $filename" >> $GITHUB_ENV + cp "./source/workflow-templates/$filename" "$target_file" + + # Apply patch if one exists + if [ -f "$target_file.patch" ]; then + echo "🩹 Applying patch" + cd ./target + set +e + patch -p1 < ".github/workflows/$filename.patch" + patch_worked=$? + set -e + cd - + if [[ "$patch_worked" == "0" ]]; then + echo " - Patch applied" >> $GITHUB_ENV + else + echo " - [ ] ❌ Patch failed" >> $GITHUB_ENV + draft_only=1 + fi + fi + echo 'EOF' >> $GITHUB_ENV + echo "DRAFT_ONLY=${draft_only}" >> $GITHUB_ENV - name: Create Pull Request if: steps.check_file_existence.outputs.files_exists == 'true' uses: peter-evans/create-pull-request@5f6978faf089d4d20b00c7766989d076bb2fc7f1 # v8.1.1 with: - body: 'Automated update of the ${{ github.event.inputs.name }} workflow from https://github.com/${{ github.repository }} triggered by ${{ github.actor }}' + body: | + Automated update of the ${{ github.event.inputs.name }} workflow from https://github.com/${{ github.repository }} triggered by ${{ github.actor }} + ${{ env.SUMMARY }} branch: 'feat/workflow-auto-update-${{ github.event.inputs.name }}' + draft: ${{ env.DRAFT_ONLY == 1 }} + add-paths: .github/workflows/*.yml commit-message: 'ci: update ${{ github.event.inputs.name }} workflow from template' committer: Nextcloud bot author: Nextcloud bot diff --git a/README.md b/README.md index 7bbe9ce1..13c726b2 100644 --- a/README.md +++ b/README.md @@ -34,8 +34,8 @@ Example: 1. Modify `.github/workflows/phpunit-mariadb.yml` 2. Save patch `git diff .github/workflows/phpunit-mariadb.yml > .github/workflows/phpunit-mariadb.yml.patch` -The `sync-workflow-templates.yml` action also supports this and reapplies the patches if possible. -If there was an error it will be outlined in the PR description. +The `sync-workflow-templates.yml` action and the organization dispatch workflows (`dispatch-workflow.yml`, `dispatch-workflow-repo.yml` and `dispatch-workflow-org.yml`) also support this and reapply the patches if possible. +If there was an error it will be outlined in the PR description and the PR is opened as a draft. ## Update workflows manually