-
Notifications
You must be signed in to change notification settings - Fork 0
104 lines (89 loc) · 3.69 KB
/
assign_repo_var.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
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
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
exit 0
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: Override repository variable
if: ${{ !inputs.dry_run && inputs.overwrite }}
run: |
variable_name=$(echo "${{ inputs.variable_name }}" | tr '[:lower:]' '[:upper:]')
gh variable set "$variable_name" --repo "ynput/$repo" --body "${{ inputs.variable_value }}"
echo "::notice::Variable '$variable_name' set to value '${{ inputs.variable_value }}' in repository ynput/${{ matrix.repo_name }}."
exit 0
- name: Assign new 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 }}."