Skip to content

Commit ac7c70c

Browse files
committed
#1: Allow for multiple names and results
1 parent d313d56 commit ac7c70c

File tree

2 files changed

+37
-57
lines changed

2 files changed

+37
-57
lines changed

.github/workflows/test_action.yml

Lines changed: 12 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,12 @@
1-
name: Generate Badge
1+
name: Generate Badges
22

33
on:
44
pull_request:
55

66
jobs:
77
generate-badge:
88
runs-on: ubuntu-latest
9-
name: Generate Badge
10-
strategy:
11-
matrix:
12-
image: ["vt-build-amd64-alpine-3-16-clang-cpp",
13-
"vt-build-amd64-ubuntu-20-04-clang-10-cpp",
14-
"vt-build-amd64-ubuntu-20-04-clang-9-cpp",
15-
"vt-build-amd64-ubuntu-20-04-gcc-10-cpp",
16-
"vt-build-amd64-ubuntu-20-04-gcc-10-openmpi-cpp",
17-
"vt-build-amd64-ubuntu-20-04-gcc-9-cpp",
18-
"vt-build-amd64-ubuntu-20-04-gcc-9-cuda-11-4-3-cpp",
19-
"vt-build-amd64-ubuntu-20-04-gcc-9-cuda-12-2-0-cpp",
20-
"vt-build-amd64-ubuntu-20-04-icpx-cpp",
21-
"vt-build-amd64-ubuntu-22-04-clang-11-cpp",
22-
"vt-build-amd64-ubuntu-22-04-clang-12-cpp",
23-
"vt-build-amd64-ubuntu-22-04-clang-13-cpp",
24-
"vt-build-amd64-ubuntu-22-04-clang-14-cpp",
25-
"vt-build-amd64-ubuntu-22-04-clang-15-cpp",
26-
"vt-build-amd64-ubuntu-22-04-gcc-11-cpp",
27-
"vt-build-amd64-ubuntu-22-04-gcc-12-cpp",
28-
"vt-build-amd64-ubuntu-22-04-gcc-12-vtk-cpp",
29-
"vt-build-amd64-ubuntu-22-04-gcc-12-zoltan-cpp",
30-
"vt-build-amd64-ubuntu-24-04-clang-16-cpp",
31-
"vt-build-amd64-ubuntu-24-04-clang-16-vtk-cpp",
32-
"vt-build-amd64-ubuntu-24-04-clang-16-zoltan-cpp",
33-
"vt-build-amd64-ubuntu-24-04-clang-17-cpp",
34-
"vt-build-amd64-ubuntu-24-04-clang-18-cpp",
35-
"vt-build-amd64-ubuntu-24-04-gcc-13-cpp",
36-
"vt-build-amd64-ubuntu-24-04-gcc-14-cpp",
37-
"vt-build-amd64-ubuntu-20-04-gcc-10-openmpi-cpp-spack"]
38-
result: ["success", "failure"]
9+
name: Generate Badges
3910

4011
steps:
4112
- uses: actions/checkout@v4
@@ -44,8 +15,16 @@ jobs:
4415
if: always()
4516
uses: DARMA-tasking/badge-generator@1-initial-version
4617
with:
47-
name: ${{ matrix.image }}-${{ matrix.result }}
48-
result: ${{ matrix.result }}
18+
names: |
19+
vt-build-amd64-alpine-3-16-clang-cpp
20+
vt-build-amd64-ubuntu-20-04-gcc-9-cuda-12-2-0-cpp
21+
vt-build-amd64-ubuntu-20-04-gcc-10-openmpi-cpp-spack
22+
vt-build-amd64-ubuntu-22-04-gcc-12-cpp
23+
results: |
24+
success
25+
cancelled
26+
failure
27+
failure
4928
github_token: ${{ secrets.GITHUB_TOKEN }}
5029

5130
comment-on-pr:

action.yml

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,14 @@ inputs:
1313
github_token:
1414
description: 'GitHub token with permissions to write to the wiki.'
1515
required: true
16+
push:
17+
description: 'Whether to push to wiki repository or not'
18+
default: false
1619

1720
# Define the execution logic for the action
1821
runs:
1922
using: 'composite'
2023
steps:
21-
- name: Determine Badge Color
22-
id: set_color
23-
shell: bash
24-
run: |
25-
case "${{ inputs.result }}" in
26-
success)
27-
echo "COLOR=green" >> $GITHUB_ENV
28-
;;
29-
failure)
30-
echo "COLOR=red" >> $GITHUB_ENV
31-
;;
32-
esac
33-
3424
- name: Clone Wiki Repository
3525
shell: bash
3626
run: |
@@ -39,22 +29,33 @@ runs:
3929
- name: Generate and Save Badge
4030
shell: bash
4131
run: |
42-
set -x
32+
set -euo pipefail
33+
readarray -t NAMES <<< "${{ inputs.names }}"
34+
readarray -t RESULTS <<< "${{ inputs.results }}"
35+
36+
[ "${#NAMES[@]}" -eq "${#RESULTS[@]}" ] || { echo "names and results lengths differ" >&2; exit 1; }
37+
38+
mkdir -p "wiki/${GITHUB_REPOSITORY}"
39+
40+
for i in "${!NAMES[@]}"; do
41+
NAME=${NAMES[$i]}
42+
RESULT=${RESULTS[$i]}
4343
44-
# Make sure we encode spaces and dashes
45-
# Shields.io URL format: https://img.shields.io/badge/<LABEL>-<MESSAGE>-<COLOR>
46-
# Any - in <MESSAGE> or <LABEL> must be escaped to %2D (URL encoding), otherwise Shields.io treats it as a delimiter.
47-
ENCODED_NAME=$(echo "${{ inputs.name }}" | sed -e 's/-/--/g')
48-
echo "ENCODED_NAME: $ENCODED_NAME"
44+
case "$RESULT" in
45+
success) COLOR=green ;;
46+
failure) COLOR=red ;;
47+
cancelled) COLOR=gray ;;
48+
*) COLOR=gray ;;
49+
esac
4950
50-
BADGE_URL="https://img.shields.io/badge/${ENCODED_NAME}-${{ inputs.result }}-${{ env.COLOR }}.svg"
51-
echo "BADGE_URL: $BADGE_URL"
51+
ENCODED_NAME=$(echo "$NAME" | sed 's/-/--/g')
52+
BADGE_URL="https://img.shields.io/badge/${ENCODED_NAME}-${RESULT}-${COLOR}.svg"
5253
53-
# Download the badge using curl
54-
mkdir -p wiki/${GITHUB_REPOSITORY}
55-
curl -s -o "wiki/${GITHUB_REPOSITORY}/${{ inputs.name }}-badge.svg" "${BADGE_URL}"
54+
curl -s -o "wiki/${GITHUB_REPOSITORY}/${NAME}-badge.svg" "$BADGE_URL"
55+
done
5656
5757
- name: Commit and Push to Wiki
58+
if: ${{ inputs.push }}
5859
shell: bash
5960
run: |
6061
cd wiki

0 commit comments

Comments
 (0)