Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
philnewm committed Nov 25, 2024
2 parents 47fba93 + 68185fc commit bb93272
Show file tree
Hide file tree
Showing 9 changed files with 331 additions and 65 deletions.
95 changes: 95 additions & 0 deletions .github/workflows/assign_repo_var.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
name: ✏️ Assign repo var

on:
workflow_dispatch:
inputs:
variable_name:
description: "Variable name"
type: string
required: true
variable_value:
description: "Value to assign to the variable"
type: string
required: true
repo_topic:
description: Repository group to batch process
type: string
required: true
default: "addon"
overwrite:
description: "Overwrite repo variable in case it already exists"
type: boolean
required: false
default: false
dry_run:
description: Run workflow without assigning variables (Dry Run)
type: boolean
default: false

env:
GH_TOKEN: ${{ secrets.YNPUT_BOT_TOKEN }}

jobs:
get-repos:
runs-on: ubuntu-latest
outputs:
repo_matrix: ${{ steps.build-matrix.outputs.matrix }}

steps:
- name: Build matrix
id: build-matrix
# TODO switch to actual addons topic
run: |
repo_list=$(gh repo list ynput -L 100 --json name,repositoryTopics | jq -c '[.[] | select(.repositoryTopics != null) | select(any(.repositoryTopics[]; .name == "${{ inputs.repo_topic }}")) | .name]')
echo "$repo_list"
echo 'matrix=["ayon-addon-action-testing", "ops-repo-automation", "ayon-maya"]' >> $GITHUB_OUTPUT
- name: Debug repo list
run: |
echo "${{ fromJson(steps.build-matrix.outputs.matrix) }}"
- name: Debug dry run value
run: |
echo ${{ inputs.dry_run }}
set-repo-var:
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: Query repository variable
if: ${{ !inputs.overwrite }}
id: skip_job
run: |
variable_name=$(echo "${{ inputs.variable_name }}" | tr '[:lower:]' '[:upper:]')
if gh variable get "$variable_name" --repo "ynput/${{ matrix.repo_name }}" &>/dev/null; then
echo "::warning::Variable '$variable_name' already exists in repository ynput/${{ matrix.repo_name }}, skipping."
echo "skip=true" >> $GITHUB_OUTPUT
fi
- name: Log dry-run
if: ${{ inputs.dry_run && !steps.skip_job.outputs.skip }}
run: |
variable_name=$(echo "${{ inputs.variable_name }}" | tr '[:lower:]' '[:upper:]')
echo "::notice::Variable '$variable_name' would be set to value '${{ inputs.variable_value }}' in repository ynput/${{ matrix.repo_name }}."
- name: Assign repository variable
if: ${{ !inputs.dry_run && !steps.skip_job.outputs.skip }}
run: |
variable_name=$(echo "${{ inputs.variable_name }}" | tr '[:lower:]' '[:upper:]')
gh variable set "$variable_name" --repo "ynput/${{ matrix.repo_name }}" --body "${{ inputs.variable_value }}"
echo "::notice::Variable '$variable_name' set to value '${{ inputs.variable_value }}' in repository ynput/${{ matrix.repo_name }}."
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ on:
token:
required: true

env:
GH_TOKEN: ${{ secrets.token }}

jobs:
auto-assign-pr:
runs-on: ubuntu-latest
Expand Down
141 changes: 141 additions & 0 deletions .github/workflows/push_caller_workflow.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
name: ⬆️ Push Caller Workflow

on:
workflow_dispatch:
inputs:
repo_topic:
description: "Filter by topics assigned to repositories"
type: string
required: true
default: "testing"
target_branch:
description: "Branch the workflow should be pushed to"
type: string
required: true
default: "develop"
caller_workflow_name:
description: "Caller workflow name without file extension"
type: string
required: true
dry_run:
description: Run workflow without pushing changes (Dry Run)
type: boolean
default: false


env:
GH_TOKEN: ${{ secrets.WORKFLOW_UPDATE_TOKEN }}
AUTOMATION-REPO: "ops-repo-automation"

jobs:
get-repos:
runs-on: ubuntu-latest
outputs:
repo_matrix: ${{ steps.build-matrix.outputs.matrix }}

steps:
- name: Query caller workflow exists
id: query-caller-workflow
run: |
caller_workflow_files=$(gh api repos/ynput/ops-repo-automation/contents/caller_workflows --jq '.[].name' | sed 's/\.yml$//')
input_name="${{ inputs.caller_workflow_name }}"
if echo "$caller_workflow_files" | grep -qw "$input_name"; then
echo "::notice::File $input_name exists in the caller workflow directory."
exit 0
fi
echo "::error::File $input_name does not exist in the directory."
exit 1
- name: Build matrix
id: build-matrix
run: |
repo_list=$(gh repo list ynput -L 100 --json name,repositoryTopics | jq -c '[.[] | select(.repositoryTopics != null) | select(any(.repositoryTopics[]; .name == "${{ inputs.repo_topic }}")) | .name]')
echo "$repo_list"
echo "matrix=$repo_list" >> $GITHUB_OUTPUT
- name: Debug repo list
run: |
echo "${{ steps.build-matrix.outputs.matrix }}"
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
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
run: |
curl -O https://raw.githubusercontent.com/ynput/${{ env.AUTOMATION-REPO }}/develop/caller_workflows/${{ inputs.caller_workflow_name }}.yml
mkdir -p .github/workflows
mv ${{ inputs.caller_workflow_name }}.yml ./.github/workflows/${{ inputs.caller_workflow_name }}.yml
- name: Check for changes
id: check_changes
run: |
if [[ `git status --porcelain` ]]; then
echo "push_required=true" >> $GITHUB_OUTPUT
else
echo "No changes to push."
echo "push_required=false" >> $GITHUB_OUTPUT
echo "::warning::No changes found, not pushing to ${{ matrix.repo_name }} at ${{ inputs.target_branch }}"
fi
- name: Dry-Run log push
if: ${{ inputs.dry_run && steps.check_changes.outputs.push_required == 'true' }}
run: |
echo "::notice::[DRY RUN] Changes would have been pushed to ${{ matrix.repo_name }} at ${{ inputs.target_branch }}"
- name: Push changes
if: ${{ ! inputs.dry_run && steps.check_changes.outputs.push_required == 'true' }}
run: |
echo "::notice::Pushing changes to ${{ matrix.repo_name }} at ${{ inputs.target_branch }}"
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] Update ${{ inputs.caller_workflow_name }} caller workflow"
git push origin ${{ inputs.target_branch }}
62 changes: 0 additions & 62 deletions .github/workflows/repo_var_assign.yml

This file was deleted.

7 changes: 6 additions & 1 deletion .github/workflows/reset_test_repo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,18 @@ jobs:
echo "$(gh secret list --repo ${{ env.TARGET_REPO }})"
- name: Set repo description and topic
run: |
gh repo edit "${{ env.TARGET_REPO }}" --description "Repository for automated action testing"
gh repo edit "${{ env.TARGET_REPO }}" --add-topic testing
- name: Set repo variables
run: |
gh variable set PATCH_BUMP_LABEL --body "bugfix" --repo ${{ env.TARGET_REPO }}
gh variable set MINOR_BUMP_LABEL --body "feature, enhancement" --repo ${{ env.TARGET_REPO }}
gh variable set MAIN_BRANCH --body "main" --repo ${{ env.TARGET_REPO }}
gh variable set PROJECT_NAME --body ${{ env.TARGET_REPO_PROJECT_NAME }} --repo ${{ env.TARGET_REPO }}
gh variable set CHANGELOG_ORDER --body "feature,enhancement,bugfix,refactor,docs,test,pr" --repo ${{ env.TARGET_REPO }}
gh variable set CHANGELOG_ORDER --body "feature(🎉),enhancement(💚),bugfix(🐛),refactor,docs,test,pr" --repo ${{ env.TARGET_REPO }}
echo "$(gh variable list --repo ${{ env.TARGET_REPO }})"
Expand Down
49 changes: 49 additions & 0 deletions .github/workflows/validate_pr_labels.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: Validate PR labels
on:
workflow_call:
inputs:
repo:
type: string
required: true
pull_request_number:
type: number
required: true
query_prefix:
type: string
required: true
default: "type: "

secrets:
token:
required: true

env:
GH_TOKEN: ${{ secrets.token }}

jobs:
validate-pr-labels:
runs-on: ubuntu-latest

steps:
- name: Query PR Labels
id: query_labels
run: |
pr_labels=$(gh pr view ${{ inputs.pull_request_number }} --json labels --jq '.labels[].name' --repo "${{ inputs.repo }}")
if echo "$pr_labels" | grep -q '^${{ inputs.query_prefix }}'; then
echo "label_found=true" >> $GITHUB_OUTPUT
else
echo "label_found=false" >> $GITHUB_OUTPUT
fi
- name: Act on label absence
if: ${{ steps.query_labels.outputs.label_found == 'false' }}
run: |
echo "::error::No label with prefix '${{ inputs.query_prefix }}' found on this PR."
exit 1
- name: Act on label presence
if: ${{ steps.query_labels.outputs.label_found == 'true' }}
run: |
echo "::notice::Label with prefix '${{ inputs.query_prefix }}' found on this PR."
exit 0
17 changes: 17 additions & 0 deletions ayon_repo_groups.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"testing": [
"ayon-addon-action-testing"
],
"addon": [
"ayon-maya",
"ayon-blender",
"ayon-usd",
"ayon-photoshop",
"ayon-sample"
],
"exclude": [
"ayon-backend",
"ayon-frontend",
"ynput-cloud-frontend"
]
}
Loading

0 comments on commit bb93272

Please sign in to comment.