1+ name : " Generate-Badge"
2+ description : " Creates dynamic and customizable README badges using shields.io/endpoint"
3+ branding :
4+ icon : " shield"
5+ color : " blue"
6+ inputs :
7+ token :
8+ description : " Used for authentication"
9+ required : true
10+ filename :
11+ description : " The filename to use in the wiki for storing the JSON badge data"
12+ required : true
13+ label :
14+ description : " The left text, or the empty string to omit the left side of the badge"
15+ required : true
16+ message :
17+ description : " The right text"
18+ required : true
19+ color :
20+ description : " The right color"
21+ required : false
22+ default : " "
23+ labelColor :
24+ description : " The left color"
25+ required : false
26+ default : " "
27+ namedLogo :
28+ description : " Logo supported by Shields"
29+ required : false
30+ default : " "
31+ logoSvg :
32+ description : " An SVG string containing a custom logo"
33+ required : false
34+ default : " "
35+ style :
36+ description : " The default template to use"
37+ required : false
38+ default : " "
39+ wikiCommitUsername :
40+ description : " Override for the wiki commit username"
41+ required : false
42+ default : " "
43+ wikiCommitEmail :
44+ description : " Override for the wiki commit email"
45+ required : false
46+ default : " "
47+ wikiCommitMessage :
48+ description : " Override for the wiki commit message"
49+ required : false
50+ default : " "
51+ repository :
52+ description : " The repository to store files"
53+ required : false
54+ default : " ${{ github.repository }}"
55+ ref :
56+ description : " The branch to store files"
57+ required : false
58+ default : " badges"
59+ runs :
60+ using : " composite"
61+ steps :
62+ - name : Output number of badges
63+ id : number_of_badges
64+ run : |
65+ declare -a BAB_INPUTS_FILENAME_ARRAY=${{ inputs.filename }}
66+ echo "value=$(echo ${#BAB_INPUTS_FILENAME_ARRAY[@]})" >> $GITHUB_OUTPUT
67+ shell : bash
68+ - name : Check out repo
69+ uses : actions/checkout@v3
70+ if : inputs.wikiCommitUsername == '' || inputs.wikiCommitEmail == '' || inputs.wikiCommitMessage == ''
71+ with :
72+ token : ${{ inputs.token }}
73+ - name : Output wiki commit details
74+ id : wiki_commit
75+ run : |
76+ if [[ -n "${{ inputs.wikiCommitUsername }}" ]]; then
77+ WIKI_COMMIT_USERNAME="${{ inputs.wikiCommitUsername }}"
78+ else
79+ WIKI_COMMIT_USERNAME=$(git log -n 1 --pretty=format:%an)
80+ fi
81+ echo "username=$WIKI_COMMIT_USERNAME" >> $GITHUB_OUTPUT
82+
83+ if [[ -n "${{ inputs.wikiCommitEmail }}" ]]; then
84+ WIKI_COMMIT_EMAIL="${{ inputs.wikiCommitEmail }}"
85+ else
86+ WIKI_COMMIT_EMAIL=$(git log -n 1 --pretty=format:%ae)
87+ fi
88+ echo "email=$WIKI_COMMIT_EMAIL" >> $GITHUB_OUTPUT
89+
90+ if [[ -n "${{ inputs.wikiCommitMessage }}" ]]; then
91+ WIKI_COMMIT_MESSAGE="${{ inputs.wikiCommitMessage }}"
92+ else
93+ WIKI_COMMIT_MESSAGE=https://github.com/${{ github.repository }}/commit/$(git log -n 1 --pretty=format:"%H")
94+ fi
95+ echo "message=$WIKI_COMMIT_MESSAGE" >> $GITHUB_OUTPUT
96+ shell : bash
97+ - name : Check out wiki
98+ uses : actions/checkout@v3
99+ with :
100+ token : ${{ inputs.token }}
101+ repository : " ${{ inputs.repository }}"
102+ ref : " refs/heads/${{ inputs.ref }}"
103+ path : wiki
104+ - name : Update wiki
105+ run : |
106+ cd ./wiki
107+
108+ if [[ ${{ steps.number_of_badges.outputs.value }} -eq 1 ]]; then
109+ BAB_INPUTS_FILENAME="${{ inputs.filename }}"
110+ BAB_INPUTS_LABEL="${{ inputs.label }}"
111+ BAB_INPUTS_MESSAGE="${{ inputs.message }}"
112+ BAB_INPUTS_COLOR="${{ inputs.color }}"
113+ BAB_INPUTS_LABELCOLOR="${{ inputs.labelColor }}"
114+ BAB_INPUTS_NAMEDLOGO="${{ inputs.namedLogo }}"
115+ BAB_INPUTS_LOGOSVG="${{ inputs.logoSvg }}"
116+ BAB_INPUTS_STYLE="${{ inputs.style }}"
117+ else
118+ declare -a BAB_INPUTS_FILENAME_ARRAY=${{ inputs.filename }}
119+ declare -a BAB_INPUTS_LABEL_ARRAY=${{ inputs.label }}
120+ declare -a BAB_INPUTS_MESSAGE_ARRAY=${{ inputs.message }}
121+ declare -a BAB_INPUTS_COLOR_ARRAY=${{ inputs.color }}
122+ declare -a BAB_INPUTS_LABELCOLOR_ARRAY=${{ inputs.labelColor }}
123+ declare -a BAB_INPUTS_NAMEDLOGO_ARRAY=${{ inputs.namedLogo }}
124+ declare -a BAB_INPUTS_LOGOSVG_ARRAY=${{ inputs.logoSvg }}
125+ declare -a BAB_INPUTS_STYLE_ARRAY=${{ inputs.style }}
126+ fi
127+
128+ for i in {1..${{ steps.number_of_badges.outputs.value }}}; do
129+ BADGE_JSON="{\"schemaVersion\":1"
130+
131+ if [[ ${{ steps.number_of_badges.outputs.value }} -ne 1 ]]; then
132+ BAB_INPUTS_FILENAME=${BAB_INPUTS_FILENAME_ARRAY[i-1]}
133+ BAB_INPUTS_LABEL=${BAB_INPUTS_LABEL_ARRAY[i-1]}
134+ BAB_INPUTS_MESSAGE=${BAB_INPUTS_MESSAGE_ARRAY[i-1]}
135+ BAB_INPUTS_COLOR=${BAB_INPUTS_COLOR_ARRAY[i-1]}
136+ BAB_INPUTS_LABELCOLOR=${BAB_INPUTS_LABELCOLOR_ARRAY[i-1]}
137+ BAB_INPUTS_NAMEDLOGO=${BAB_INPUTS_NAMEDLOGO_ARRAY[i-1]}
138+ BAB_INPUTS_LOGOSVG=${BAB_INPUTS_LOGOSVG_ARRAY[i-1]}
139+ BAB_INPUTS_STYLE=${BAB_INPUTS_STYLE_ARRAY[i-1]}
140+ fi
141+
142+ BADGE_JSON="$BADGE_JSON,\"label\":\"$BAB_INPUTS_LABEL\""
143+ BADGE_JSON="$BADGE_JSON,\"message\":\"$BAB_INPUTS_MESSAGE\""
144+
145+ declare -A OPTIONAL_PARAMETERS_ARRAY
146+ OPTIONAL_PARAMETERS_ARRAY["color"]=$BAB_INPUTS_COLOR
147+ OPTIONAL_PARAMETERS_ARRAY["labelColor"]=$BAB_INPUTS_LABELCOLOR
148+ OPTIONAL_PARAMETERS_ARRAY["namedLogo"]=$BAB_INPUTS_NAMEDLOGO
149+ OPTIONAL_PARAMETERS_ARRAY["logoSvg"]=$(echo $BAB_INPUTS_LOGOSVG | sed -e 's/"/\\"/g')
150+ OPTIONAL_PARAMETERS_ARRAY["style"]=$BAB_INPUTS_STYLE
151+
152+ for key in ${!OPTIONAL_PARAMETERS_ARRAY[@]}; do
153+ if [[ -n "${OPTIONAL_PARAMETERS_ARRAY[${key}]}" ]]; then
154+ BADGE_JSON="$BADGE_JSON,\"$key\":\"${OPTIONAL_PARAMETERS_ARRAY[${key}]}\""
155+ fi
156+ done
157+ BADGE_JSON="$BADGE_JSON}"
158+
159+ echo $BADGE_JSON > "$BAB_INPUTS_FILENAME.md"
160+ done
161+
162+ git pull
163+ if [[ -n $(git status --porcelain) ]]; then
164+ git config user.name "${{ steps.wiki_commit.outputs.username }}"
165+ git config user.email "${{ steps.wiki_commit.outputs.email }}"
166+ git add -A
167+ git commit -m "${{ steps.wiki_commit.outputs.message }}"
168+ git push
169+ fi
170+
171+ cd ..
172+ shell : bash
0 commit comments