-
Notifications
You must be signed in to change notification settings - Fork 10
112 lines (94 loc) · 4.43 KB
/
dispatch-workflow.yml
File metadata and controls
112 lines (94 loc) · 4.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# This workflow needs to be run on demand
# It will search for all repositories containing the provided
# action and open pull requests if necessary.
# This workflow is provided via the organization template repository
#
# SPDX-FileCopyrightText: 2021-2024 Nextcloud GmbH and Nextcloud contributors
# SPDX-License-Identifier: MIT
name: Update workflow from org template
on:
workflow_dispatch:
inputs:
name:
description: 'The workflow to update (with .yml)'
required: true
default: 'node.yml'
page:
description: 'Page of the repository list to check (currently 1-3)'
required: true
type: number
default: 1
permissions:
contents: read
jobs:
repositories:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.search-repos.outputs.matrix }}
name: List repositories (page ${{ github.event.inputs.page }})
steps:
- name: Check actor permission
uses: skjnldsv/check-actor-permission@69e92a3c4711150929bca9fcf34448c5bf5526e7 # v3.0
with:
require: admin
- name: Create output matrix # zizmor: ignore[template-injection]
id: search-repos
# This is a simple curl to fetch the list of repos containing a file and extracting the repo names
run: |
REPOS=$(curl -H 'Accept: application/vnd.github.v3+json' 'https://api.github.com/orgs/${{ github.repository_owner }}/repos?per_page=100&page=${{ github.event.inputs.page }}' | jq -c 'map(.name)')
echo "matrix=$REPOS" >> $GITHUB_OUTPUT
dispatch:
runs-on: ubuntu-latest
needs: repositories
strategy:
fail-fast: false
matrix:
repositories: ${{ fromJSON(needs.repositories.outputs.matrix) }}
name: dispatch ${{ github.event.inputs.name }}
steps:
- name: Checkout target repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: false
path: target
repository: ${{ github.repository_owner }}/${{ matrix.repositories }}
- name: Check sync-workflow-templates.yml file existence
id: check_sync_workflow_templates_existence
uses: andstor/file-existence-action@558493d6c74bf472d87c84eab196434afc2fa029 # v3.1.0
with:
files: target/.github/workflows/sync-workflow-templates.yml
- name: Fail when synced # zizmor: ignore[template-injection]
if: ${{ steps.check_sync_workflow_templates_existence.outputs.files_exists == 'true' }}
run: |
echo 'Repository is syncing workflows. Please dispatch the workflow on the repository instead:'
echo 'https://github.com/${{ github.repository_owner }}/${{ matrix.repositories }}/actions/workflows/sync-workflow-templates.yml'
exit 1
- name: Check ${{ github.event.inputs.name }} file existence
id: check_file_existence
uses: andstor/file-existence-action@558493d6c74bf472d87c84eab196434afc2fa029 # v3.1.0
with:
files: target/.github/workflows/${{ github.event.inputs.name }}
- name: Checkout source repository
if: steps.check_file_existence.outputs.files_exists == 'true'
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: false
path: source
- 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
- 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 }}'
branch: 'feat/workflow-auto-update-${{ github.event.inputs.name }}'
commit-message: 'ci: update ${{ github.event.inputs.name }} workflow from template'
committer: Nextcloud bot <bot@nextcloud.com>
author: Nextcloud bot <bot@nextcloud.com>
assignees: ${{ github.actor }}
path: target
signoff: true
title: 'ci: update ${{ github.event.inputs.name }} workflow from template'
labels: dependencies
token: ${{ secrets.TEMPLATE_WORKFLOW_DISPATCH_PAT }}