-
Notifications
You must be signed in to change notification settings - Fork 0
79 lines (63 loc) · 2.31 KB
/
repo_variable.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
name: 📥 Assign repo var
on:
workflow_dispatch:
inputs:
variable_name:
description: "Variable name"
type: string
required: true
varibale_value:
description: "Value the to assign to the variable"
type: string
required: true
repo_list:
description: "Repo names as comma seperated strings"
type: string
required: true
overwrite:
description: "Overwrite repo variable"
type: boolean
required: false
default: false
env:
GH_TOKEN: ${{ secrets.REPO_CTRL_TOKEN }}
jobs:
variable-present:
if: ${{ !inputs.overwrite }}
runs-on: ubuntu-latest
steps:
- name: Assign new variable if not present
run: |
IFS=', ' read -r -a repos <<< "${{ inputs.repo_list }}"
variable_name=$(echo "${{ inputs.variable_name }}" | tr '[:lower:]' '[:upper:]')
for repo in "${repos[@]}"; do
repo=$(echo "$repo" | xargs)
echo "repo: ynput/$repo"
echo "$(gh repo view "ynput/$repo")"
if ! gh repo view "ynput/$repo" &>/dev/null; then
echo "::warning::Repository $repo was not found."
continue
fi
if gh variable get "$variable_name" --repo "ynput/$repo" &>/dev/null; then
echo "::warning::Variable '$variable_name' already exists in repository $repo."
continue
fi
gh variable set "$variable_name" --repo "ynput/$repo" --body "${{ inputs.varibale_value }}"
echo "::notice::Variable '$variable_name' set in repository $repo."
done
variable-overwite:
runs-on: ubuntu-latest
if: ${{ inputs.overwrite }}
steps:
- name: Assign new variable even if already present
run: |
IFS=', ' read -r -a repos <<< "${{ inputs.repo_list }}"
variable_name=$(echo "${{ inputs.variable_name }}" | tr '[:lower:]' '[:upper:]')
for repo in "${repos[@]}"; do
repo=$(echo "$repo" | xargs)
if ! gh repo view "ynput/$repo" &>/dev/null; then
echo "::warning::Repository $repo was not found."
continue
fi
gh variable set "$variable_name" --repo "ynput/$repo" --body "${{ inputs.varibale_value }}"
done