Update workflow from org template #150
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 | |
default: '1' | |
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 | |
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@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 | |
with: | |
path: target | |
repository: ${{ github.repository_owner }}/${{ matrix.repositories }} | |
- name: Check ${{ github.event.inputs.name }} file existence | |
id: check_file_existence | |
uses: andstor/file-existence-action@076e0072799f4942c8bc574a82233e1e4d13e9d6 # v3.0.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@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 | |
with: | |
path: source | |
- name: Copy workflow | |
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@c5a7806660adbe173f04e3e038b0ccdcd758773c # v6.1.0 | |
with: | |
body: 'Automated update of the ${{ github.event.inputs.name }} workflow from https://github.com/${{ github.repository }}' | |
branch: 'feat/workflow-auto-update-${{ github.event.inputs.name }}' | |
commit-message: 'chore(CI): Updating ${{ github.event.inputs.name }} workflow from template' | |
committer: Nextcloud bot <[email protected]> | |
author: Nextcloud bot <[email protected]> | |
path: target | |
signoff: true | |
title: 'chore(CI): Updating ${{ github.event.inputs.name }} workflow from template' | |
labels: dependencies | |
token: ${{ secrets.TEMPLATE_WORKFLOW_DISPATCH_PAT }} |