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

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion .github/workflows/dispatch-workflow-repo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ jobs:

- name: Copy all workflow templates
run: |
echo 'SUMMARY<<EOF' >> $GITHUB_ENV
draft_only=0
for workflow in ./source/workflow-templates/*.yml; do
if [ -f "$workflow" ]; then
filename=$(basename "$workflow")
Expand All @@ -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 <bot@nextcloud.com>
author: Nextcloud bot <bot@nextcloud.com>
Expand Down
33 changes: 31 additions & 2 deletions .github/workflows/dispatch-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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<<EOF' >> $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 <bot@nextcloud.com>
author: Nextcloud bot <bot@nextcloud.com>
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Loading