Skip to content

Commit 82d068a

Browse files
Merge pull request #2493 from nextcloud/enh/noid/add-sync-workflow-action
chore(actions): add sync-workflow-templates github action
2 parents 5fb8683 + 0729502 commit 82d068a

1 file changed

Lines changed: 141 additions & 0 deletions

File tree

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
# This workflow is provided via the organization template repository
2+
#
3+
# https://github.com/nextcloud/.github
4+
# https://docs.github.com/en/actions/learn-github-actions/sharing-workflows-with-your-organization
5+
#
6+
# SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
7+
# SPDX-License-Identifier: MIT
8+
9+
# This workflow will update all workflow templates
10+
# Additionally it will reapply `workflow.yml.patch` files after syncing and only then commit the result
11+
name: Update workflows
12+
on:
13+
workflow_dispatch:
14+
schedule:
15+
- cron: "5 2 * * 0"
16+
17+
permissions:
18+
contents: read
19+
20+
jobs:
21+
dispatch:
22+
runs-on: ubuntu-latest
23+
24+
strategy:
25+
fail-fast: false
26+
matrix:
27+
branches:
28+
- ${{ github.event.repository.default_branch }}
29+
- 'stable34'
30+
- 'stable33'
31+
- 'stable32'
32+
33+
name: Update workflows in ${{ matrix.branches }}
34+
35+
permissions:
36+
contents: write
37+
pull-requests: write
38+
39+
steps:
40+
- name: Check actor permission
41+
uses: skjnldsv/check-actor-permission@69e92a3c4711150929bca9fcf34448c5bf5526e7 # v3.0
42+
with:
43+
require: admin
44+
45+
- name: Checkout workflow repository
46+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
47+
with:
48+
persist-credentials: false
49+
path: source
50+
repository: nextcloud/.github
51+
52+
- name: Checkout app
53+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
54+
with:
55+
persist-credentials: false
56+
path: target
57+
ref: ${{ matrix.branches }}
58+
59+
- name: Copy all workflow templates
60+
run: |
61+
echo 'SUMMARY<<EOF' >> $GITHUB_ENV
62+
draft_only=0
63+
for workflow in ./source/workflow-templates/*.yml; do
64+
echo "❓ Looking for $workflow"
65+
if [ -f "$workflow" ]; then
66+
filename=$(basename "$workflow")
67+
target_file="./target/.github/workflows/$filename"
68+
69+
# Only copy if the file exists in the target repository
70+
if [ -f "$target_file" ]; then
71+
if [ -f "./target/.github/actions-lock.txt" ]; then
72+
locked_version=$(grep " $filename" ./target/.github/actions-lock.txt | cat)
73+
else
74+
echo "# SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors" >> ./target/.github/actions-lock.txt
75+
echo "# SPDX-License""-Identifier: MIT" >> ./target/.github/actions-lock.txt
76+
locked_version=""
77+
fi
78+
locked_version=$(echo $locked_version | cut -f 1 -d " ")
79+
new_version=$(md5sum $workflow | cut -f 1 -d " ")
80+
81+
# Only update if the action changes
82+
if [[ "$locked_version" != "$new_version" ]]; then
83+
echo "ℹ️ Locked version: $locked_version"
84+
echo "ℹ️ Current version: $new_version"
85+
echo "🆙 Updating existing workflow: $filename"
86+
echo "- 🆙 Updated [$filename](https://github.com/nextcloud/.github/commits/master/workflow-templates/$filename)" >> $GITHUB_ENV
87+
88+
cp "$workflow" "$target_file"
89+
90+
# Apply patch if one exists
91+
if [ -f "$target_file.patch" ]; then
92+
echo "🩹 Applying patch"
93+
cd ./target
94+
set +e
95+
patch -p1 < ".github/workflows/$filename.patch"
96+
patch_worked=$?
97+
set -e
98+
cd -
99+
if [[ "$patch_worked" == "0" ]]; then
100+
echo " - Patch applied" >> $GITHUB_ENV
101+
else
102+
echo " - [ ] ❌ Patch failed" >> $GITHUB_ENV
103+
draft_only=1
104+
fi
105+
fi
106+
107+
if [[ "$locked_version" != "" ]]; then
108+
sed -i "s/$locked_version $filename/$new_version $filename/" ./target/.github/actions-lock.txt
109+
else
110+
echo "$new_version $filename" >> ./target/.github/actions-lock.txt
111+
fi
112+
else
113+
echo "✅ Skipping $filename: already up to date"
114+
fi
115+
else
116+
echo "⏭️ Skipping $filename: does not exist in target repository"
117+
fi
118+
fi
119+
done
120+
echo 'EOF' >> $GITHUB_ENV
121+
echo "DRAFT_ONLY=${draft_only}" >> $GITHUB_ENV
122+
123+
- name: Create Pull Request
124+
uses: peter-evans/create-pull-request@5f6978faf089d4d20b00c7766989d076bb2fc7f1 # v8.1.1
125+
with:
126+
token: ${{ secrets.COMMAND_BOT_WORKFLOWS }}
127+
commit-message: 'ci(actions): Update workflow templates from organization template repository'
128+
committer: GitHub <noreply@github.com>
129+
author: nextcloud-command <nextcloud-command@users.noreply.github.com>
130+
path: target
131+
signoff: true
132+
branch: 'automated/noid/${{ matrix.branches }}-update-workflows'
133+
title: '[${{ matrix.branches }}] ci(actions): Update workflow templates from organization template repository'
134+
draft: ${{ env.DRAFT_ONLY == 1 }}
135+
add-paths: .github/workflows/*.yml,.github/actions-lock.txt
136+
body: |
137+
Automated update of all workflow templates from [nextcloud/.github](https://github.com/nextcloud/.github)
138+
${{ env.SUMMARY }}
139+
labels: |
140+
dependencies
141+
3. to review

0 commit comments

Comments
 (0)