|
35 | 35 | "vt-build-amd64-ubuntu-24-04-gcc-13-cpp", |
36 | 36 | "vt-build-amd64-ubuntu-24-04-gcc-14-cpp", |
37 | 37 | "vt-build-amd64-ubuntu-20-04-gcc-10-openmpi-cpp-spack"] |
38 | | - |
39 | 38 | result: ["success", "failure"] |
40 | 39 |
|
41 | 40 | steps: |
|
45 | 44 | if: always() |
46 | 45 | uses: DARMA-tasking/badge-generator@1-initial-version |
47 | 46 | with: |
48 | | - name: ${{ matrix.image }} |
| 47 | + name: ${{ matrix.image }}-${{ matrix.result }} |
49 | 48 | result: ${{ matrix.result }} |
50 | 49 | 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 |
0 commit comments