Skip to content

Update workflow from org template #118

Update workflow from org template

Update workflow from org template #118

# This workflow needs to be run on demand
# It will search for all repositories containing the provided
# action and open pull requests if necessary.
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@e591dbfe838300c007028e1219ca82cc26e8d7c5 # v2.1
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) }}
steps:
- name: Checkout target repository
uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2
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@20b4d2e596410855db8f9ca21e96fbe18e12930b # v2
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@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2
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@284f54f989303d2699d373481a0cfa13ad5a6666 # v4
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: Updating ${{ github.event.inputs.name }} workflow from template
committer: Nextcloud bot <[email protected]>
author: Nextcloud bot <[email protected]>
path: target
signoff: true
title: Updating ${{ github.event.inputs.name }} workflow from template
labels: dependencies
token: ${{ secrets.TEMPLATE_WORKFLOW_DISPATCH_PAT }}