⬆️ Push Caller Workflow #18
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
name: ⬆️ Push Caller Workflow | |
on: | |
workflow_dispatch: | |
inputs: | |
repo_topic: | |
description: Filter by topics assigned to repositories | |
type: string | |
required: true | |
target_branch: | |
description: Branch the workflow should be pushed to | |
type: string | |
required: true | |
caller_workflow_name: | |
description: | |
type: string | |
required: true | |
env: | |
# TODO update token to one with enabled workflow permission | |
GH_TOKEN: ${{ secrets.REPO_CTRL_TOKEN }} | |
AUTOMATION-REPO: "ops-repo-automation" | |
jobs: | |
get-repos: | |
runs-on: ubuntu-latest | |
outputs: | |
repo_matrix: ${{ steps.build-matrix.outputs.matrix }} | |
steps: | |
- name: Build matrix | |
id: build-matrix | |
# TODO update list variable | |
run: | | |
repo_list=$(gh repo list ynput -L 100 --json name,repositoryTopics | jq -r '[.[] | select(.repositoryTopics != null) | select(any(.repositoryTopics[]; .name == "${{ inputs.repo_topic }}")) | .name]') | |
echo "$repo_list" | |
echo 'matrix=["ayon-addon-action-testing", "ayon-sample"]' >> $GITHUB_OUTPUT | |
Update-workflow: | |
needs: | |
- get-repos | |
runs-on: ubuntu-latest | |
strategy: | |
fail-fast: false | |
matrix: | |
repo_name: ${{ fromJson(needs.get-repos.outputs.repo_matrix) }} | |
steps: | |
- name: Test repo exists | |
run: | | |
if ! gh repo view "ynput/${{ matrix.repo_name }}" &>/dev/null; then | |
echo "::error::Repository ynput/${{ matrix.repo_name }} was not found." | |
exit 1 | |
fi | |
- name: Check for running workflows | |
id: poll-workflows | |
run: | | |
for i in {1..20}; do | |
running_workflows=$(gh run list --repo ynput/${{ matrix.repo_name }} -L 100 --status in_progress --json name | jq -r 'map(.name) | join(", ")') | |
if [[ -n "$running_workflows" ]]; then | |
echo "::warning::Repo ynput/${{ matrix.repo_name }} currently has running workflows: $running_workflows" | |
sleep 15 | |
continue | |
fi | |
break | |
done | |
running_workflows=$(gh run list --repo ynput/${{ matrix.repo_name }} --status in_progress --json name | jq -r 'map(.name) | join(", ")') | |
if [[ -n "$running_workflows" ]]; then | |
echo "::error::Repo ynput/${{ matrix.repo_name }} currently has running workflows: $running_workflows" | |
echo "::error::Repo ynput/${{ matrix.repo_name }} has been running workflows since more then 5 minutes, please check the repo" | |
exit 1 | |
fi | |
- name: ⬇️ Checkout ${{ matrix.repo_name }} at ${{ inputs.target_branch }} | |
uses: actions/checkout@v4 | |
with: | |
token: ${{ env.GH_TOKEN }} | |
repository: ynput/${{ matrix.repo_name }} | |
ref: ${{ inputs.target_branch }} | |
fetch-depth: 0 | |
- name: Get caller workflow | |
# TODO update branch | |
run: | | |
curl -O https://raw.githubusercontent.com/${{ env.AUTOMATION-REPO }}/push-caller-workflow/caller_workflows/${{ inputs.caller_workflow_name }}.yml | |
mv ${{ inputs.caller_workflow_name }}.yml ./.github/workflows/${{ inputs.caller_workflow_name }}.yml | |
- name: Push caller workflow | |
run: | | |
git config --global user.name "${{ secrets.CI_USER }}" | |
git config --global user.email "${{ secrets.CI_EMAIL }}" | |
git add ./.github/workflows/${{ inputs.caller_workflow_name }}.yml | |
git commit -m "[Automated] Add ${{ inputs.caller_workflow_name }} caller workflow" | |
git push origin ${{ inputs.target_branch }} || echo "No changes to push." |