Skip to content

Commit b7f31e1

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

File tree

2 files changed

+60
-7
lines changed

2 files changed

+60
-7
lines changed

.github/workflows/test_action.yml

Lines changed: 54 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,59 @@ 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+
PREFIX_STRING="https://github.com/DARMA-tasking/badge-generator/wiki/"
64+
65+
COMMENT_BODY="""
66+
67+
git clone https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/DARMA-tasking/badge-generator.wiki.git wiki
68+
69+
# List files in the directory and store in an array
70+
mapfile -t FILE_ARRAY < <(ls -1 "badge-generator/${REPO}" 2>/dev/null || echo "")
71+
72+
# Append each file to COMMENT_BODY in the specified format
73+
for FILE_NAME in "${FILE_ARRAY[@]}"; do
74+
COMMENT_BODY+="![$PREFIX_STRING$FILE_NAME]()\n"
75+
done
76+
77+
# Add identifier for comment tracking
78+
COMMENT_BODY+="<!-- BadgeGeneratorComment -->"
79+
80+
# Get existing comments
81+
COMMENTS=$(curl -s -H "Authorization: token $GITHUB_TOKEN" \
82+
-H "Accept: application/vnd.github.v3+json" \
83+
https://api.github.com/repos/$REPO/issues/$PR_NUMBER/comments)
84+
85+
# Check for existing comment with our identifier
86+
COMMENT_ID=$(echo "$COMMENTS" | jq -r '.[] | select(.body | contains("<!-- BadgeGeneratorComment -->")) | .id')
87+
88+
if [ -n "$COMMENT_ID" ]; then
89+
# Update existing comment
90+
curl -s -H "Authorization: token $GITHUB_TOKEN" \
91+
-H "Accept: application/vnd.github.v3+json" \
92+
-X PATCH \
93+
-d "{\"body\": \"$COMMENT_BODY\"}" \
94+
https://api.github.com/repos/$REPO/issues/comments/$COMMENT_ID
95+
else
96+
# Create new comment
97+
curl -s -H "Authorization: token $GITHUB_TOKEN" \
98+
-H "Accept: application/vnd.github.v3+json" \
99+
-X POST \
100+
-d "{\"body\": \"$COMMENT_BODY\"}" \
101+
https://api.github.com/repos/$REPO/issues/$PR_NUMBER/comments
102+
fi

action.yml

Lines changed: 6 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,8 @@ 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 rebase origin/master
72+
git push --force-with-lease
7273
echo "Badge updated and pushed to the wiki."
7374
else
7475
echo "No changes to the badge. Commit skipped."

0 commit comments

Comments
 (0)