Skip to content

Commit 15f75e7

Browse files
committed
ci(workflows): Add sync workflow
Signed-off-by: Joas Schilling <coding@schilljs.com>
1 parent 3cc2250 commit 15f75e7

3 files changed

Lines changed: 167 additions & 6 deletions

File tree

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

.github/workflows/update-nextcloud-ocp.yml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ name: Update nextcloud/ocp
1111
on:
1212
workflow_dispatch:
1313
schedule:
14-
- cron: "5 2 * * 0"
14+
- cron: "5 2 * * *"
1515

1616
permissions:
1717
contents: read
@@ -28,13 +28,12 @@ jobs:
2828
- ${{ github.event.repository.default_branch }}
2929
- 'stable33'
3030
- 'stable32'
31-
- 'stable31'
3231

3332
name: update-nextcloud-ocp-${{ matrix.branches }}
3433

3534
steps:
3635
- id: checkout
37-
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
36+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
3837
with:
3938
persist-credentials: false
4039
ref: ${{ matrix.branches }}
@@ -66,7 +65,7 @@ jobs:
6665
- name: Composer update nextcloud/ocp # zizmor: ignore[template-injection]
6766
id: update_branch
6867
if: ${{ steps.checkout.outcome == 'success' && matrix.branches != 'main' }}
69-
run: composer require --dev 'nextcloud/ocp:dev-${{ matrix.branches }}'
68+
run: composer bin nextcloud-ocp require --dev 'nextcloud/ocp:dev-${{ matrix.branches }}'
7069

7170
- name: Raise on issue on failure
7271
uses: dacbd/create-issue-action@cdb57ab6ff8862aa09fee2be6ba77a59581921c2 # v2.0.0
@@ -112,9 +111,9 @@ jobs:
112111

113112
- name: Create Pull Request
114113
if: steps.checkout.outcome == 'success'
115-
uses: peter-evans/create-pull-request@84ae59a2cdc2258d6fa0732dd66352dddae2a412 # v7.0.9
114+
uses: peter-evans/create-pull-request@c0f553fe549906ede9cf27b5156039d195d2ece0 # v8.1.0
116115
with:
117-
token: ${{ secrets.COMMAND_BOT_PAT }}
116+
token: ${{ secrets.COMMAND_BOT_PAT }} # zizmor: ignore[secrets-outside-env]
118117
commit-message: 'chore(dev-deps): Bump nextcloud/ocp package'
119118
committer: GitHub <noreply@github.com>
120119
author: nextcloud-command <nextcloud-command@users.noreply.github.com>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
diff --git a/.github/workflows/update-nextcloud-ocp.yml b/.github/workflows/update-nextcloud-ocp.yml
2+
index 873bf119..760faece 100644
3+
--- a/.github/workflows/update-nextcloud-ocp.yml
4+
+++ b/.github/workflows/update-nextcloud-ocp.yml
5+
@@ -11,7 +11,7 @@ name: Update nextcloud/ocp
6+
on:
7+
workflow_dispatch:
8+
schedule:
9+
- - cron: "5 2 * * 0"
10+
+ - cron: "5 2 * * *"
11+
12+
permissions:
13+
contents: read
14+
@@ -65,7 +65,7 @@ jobs:
15+
- name: Composer update nextcloud/ocp # zizmor: ignore[template-injection]
16+
id: update_branch
17+
if: ${{ steps.checkout.outcome == 'success' && matrix.branches != 'main' }}
18+
- run: composer require --dev 'nextcloud/ocp:dev-${{ matrix.branches }}'
19+
+ run: composer bin nextcloud-ocp require --dev 'nextcloud/ocp:dev-${{ matrix.branches }}'
20+
21+
- name: Raise on issue on failure
22+
uses: dacbd/create-issue-action@cdb57ab6ff8862aa09fee2be6ba77a59581921c2 # v2.0.0

0 commit comments

Comments
 (0)