✏️ Assign repo var #1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"]' >> $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 }} | |
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." | |
exit 0 | |
fi | |
- 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 }} | |
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 }}." |