Skip to content

✏️ Assign repo var #10

✏️ Assign repo var

✏️ Assign repo var #10

Workflow file for this run

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:
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 ${{ inputs.overwrite }}; then
gh variable set "$variable_name" --repo "ynput/$repo" --body "${{ inputs.varibale_value }}"
echo "::notice::Variable '$variable_name' set in repository $repo."
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