|
| 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 |
0 commit comments