Skip to content

Commit 9145a90

Browse files
committed
#1: Update test and make sure to --rebase when pushing new badge:
1 parent 35ba04b commit 9145a90

File tree

2 files changed

+60
-7
lines changed

2 files changed

+60
-7
lines changed

.github/workflows/test_action.yml

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ jobs:
3535
"vt-build-amd64-ubuntu-24-04-gcc-13-cpp",
3636
"vt-build-amd64-ubuntu-24-04-gcc-14-cpp",
3737
"vt-build-amd64-ubuntu-20-04-gcc-10-openmpi-cpp-spack"]
38-
3938
result: ["success", "failure"]
4039

4140
steps:
@@ -45,6 +44,60 @@ jobs:
4544
if: always()
4645
uses: DARMA-tasking/badge-generator@1-initial-version
4746
with:
48-
name: ${{ matrix.image }}
47+
name: ${{ matrix.image }}-${{ matrix.result }}
4948
result: ${{ matrix.result }}
5049
github_token: ${{ secrets.GITHUB_TOKEN }}
50+
51+
comment-on-pr:
52+
runs-on: ubuntu-latest
53+
needs: generate-badge
54+
if: always()
55+
steps:
56+
- uses: actions/checkout@v4
57+
- name: Update or add comment to pull request
58+
env:
59+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
60+
PR_NUMBER: ${{ github.event.pull_request.number }}
61+
REPO: ${{ github.repository }}
62+
run: |
63+
REPO_NAME=$(basename $REPO)
64+
PREFIX_STRING="https://github.com/DARMA-tasking/badge-generator/wiki/"
65+
66+
COMMENT_BODY="""
67+
68+
git clone https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/DARMA-tasking/badge-generator.wiki.git wiki
69+
70+
# List files in the directory and store in an array
71+
mapfile -t FILE_ARRAY < <(ls -1 "badge-generator/${REPO}" 2>/dev/null || echo "")
72+
73+
# Append each file to COMMENT_BODY in the specified format
74+
for FILE_NAME in "${FILE_ARRAY[@]}"; do
75+
COMMENT_BODY+="![$PREFIX_STRING$FILE_NAME]()\n"
76+
done
77+
78+
# Add identifier for comment tracking
79+
COMMENT_BODY+="<!-- BadgeGeneratorComment -->"
80+
81+
# Get existing comments
82+
COMMENTS=$(curl -s -H "Authorization: token $GITHUB_TOKEN" \
83+
-H "Accept: application/vnd.github.v3+json" \
84+
https://api.github.com/repos/$REPO/issues/$PR_NUMBER/comments)
85+
86+
# Check for existing comment with our identifier
87+
COMMENT_ID=$(echo "$COMMENTS" | jq -r '.[] | select(.body | contains("<!-- BadgeGeneratorComment -->")) | .id')
88+
89+
if [ -n "$COMMENT_ID" ]; then
90+
# Update existing comment
91+
curl -s -H "Authorization: token $GITHUB_TOKEN" \
92+
-H "Accept: application/vnd.github.v3+json" \
93+
-X PATCH \
94+
-d "{\"body\": \"$COMMENT_BODY\"}" \
95+
https://api.github.com/repos/$REPO/issues/comments/$COMMENT_ID
96+
else
97+
# Create new comment
98+
curl -s -H "Authorization: token $GITHUB_TOKEN" \
99+
-H "Accept: application/vnd.github.v3+json" \
100+
-X POST \
101+
-d "{\"body\": \"$COMMENT_BODY\"}" \
102+
https://api.github.com/repos/$REPO/issues/$PR_NUMBER/comments
103+
fi

action.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ author: 'Darma-tasking'
44

55
# Define the inputs the action will accept
66
inputs:
7-
name:
8-
description: 'The label for the badge (e.g., the build target or job name). Should be URL-friendly.'
7+
names:
8+
description: 'The labels for the badges (e.g., matrix item).'
99
required: true
10-
result:
11-
description: 'The result of a previous step (e.g., success, failure, cancelled).'
10+
results:
11+
description: 'The results of build step (success, failure or cancelled).'
1212
required: true
1313
github_token:
1414
description: 'GitHub token with permissions to write to the wiki.'
@@ -68,7 +68,7 @@ runs:
6868
# Commit only if there are changes to prevent empty commits
6969
if ! git diff --staged --quiet; then
7070
git commit -m "Update badge for: ${{ inputs.name }}"
71-
git push
71+
git push --rebase
7272
echo "Badge updated and pushed to the wiki."
7373
else
7474
echo "No changes to the badge. Commit skipped."

0 commit comments

Comments
 (0)