Skip to content

✏️ Assign repo var #7

✏️ Assign repo var

✏️ Assign repo var #7

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:
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