Skip to content

Commit ffa6075

Browse files
committed
feat: allow org workflows dispatch
Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
1 parent fce6261 commit ffa6075

2 files changed

Lines changed: 54 additions & 0 deletions

File tree

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# This workflow needs to be run on demand
2+
# It will update all workflow templates in all repositories of the organization
3+
# This workflow is provided via the organization template repository
4+
#
5+
# SPDX-FileCopyrightText: 2021-2024 Nextcloud GmbH and Nextcloud contributors
6+
# SPDX-License-Identifier: MIT
7+
name: Update workflows for all repositories
8+
9+
on:
10+
workflow_dispatch:
11+
permissions:
12+
contents: read
13+
jobs:
14+
get-repos:
15+
runs-on: ubuntu-latest
16+
name: Get all repositories in the organization
17+
outputs:
18+
repositories: ${{ steps.get-repos.outputs.repositories }}
19+
steps:
20+
- name: Check actor permission
21+
uses: skjnldsv/check-actor-permission@69e92a3c4711150929bca9fcf34448c5bf5526e7 # v3.0
22+
with:
23+
require: admin
24+
25+
- name: Get all repositories
26+
id: get-repos
27+
env:
28+
GH_TOKEN: ${{ secrets.TEMPLATE_WORKFLOW_DISPATCH_PAT }}
29+
run: |
30+
repositories=$(gh api \
31+
--paginate \
32+
--jq '[.[] | {name: .name, branch: .default_branch}]' \
33+
orgs/${{ github.repository_owner }}/repos \
34+
| jq -sc 'add')
35+
echo "repositories=$repositories" >> $GITHUB_OUTPUT
36+
37+
dispatch:
38+
runs-on: ubuntu-latest
39+
needs: get-repos
40+
name: Update all workflows in ${{ matrix.repository.name }}
41+
strategy:
42+
fail-fast: false
43+
matrix:
44+
repository: ${{ fromJson(needs.get-repos.outputs.repositories) }}
45+
steps:
46+
- name: Dispatch update workflow
47+
env:
48+
GH_TOKEN: ${{ secrets.TEMPLATE_WORKFLOW_DISPATCH_PAT }}
49+
run: |
50+
gh workflow run dispatch-workflow-repo.yml \
51+
--repo ${{ github.repository }} \
52+
--field repository=${{ matrix.repository.name }} \
53+
--field branch=${{ matrix.repository.branch }}

.github/workflows/dispatch-workflow-repo.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ jobs:
3131

3232
steps:
3333
- name: Check actor permission
34+
if: github.actor != 'nextcloud-command' # allow matrix call from org dispatch
3435
uses: skjnldsv/check-actor-permission@69e92a3c4711150929bca9fcf34448c5bf5526e7 # v3.0
3536
with:
3637
require: admin

0 commit comments

Comments
 (0)