#1: Badge generator github action #10
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Generate Badges | |
| on: | |
| pull_request: | |
| jobs: | |
| generate-badge: | |
| runs-on: ubuntu-latest | |
| name: Generate Badges | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Generate build badge | |
| if: always() | |
| uses: DARMA-tasking/badge-generator@1-initial-version | |
| with: | |
| names: | | |
| vt-build-amd64-alpine-3-16-clang-cpp | |
| vt-build-amd64-ubuntu-20-04-gcc-9-cuda-12-2-0-cpp | |
| vt-build-amd64-ubuntu-20-04-gcc-10-openmpi-cpp-spack | |
| vt-build-amd64-ubuntu-22-04-gcc-12-cpp | |
| results: | | |
| success | |
| cancelled | |
| failure | |
| failure | |
| github_token: ${{ secrets.GITHUB_TOKEN }} | |
| comment-on-pr: | |
| needs: generate-badge | |
| runs-on: ubuntu-latest | |
| if: always() | |
| steps: | |
| - name: Clone wiki | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| git clone "https://x-access-token:${GITHUB_TOKEN}@github.com/${{ github.repository }}.wiki.git" wiki | |
| - name: Update or add PR comment | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| PR: ${{ github.event.pull_request.number }} | |
| REPO: ${{ github.repository }} | |
| run: | | |
| set -euo pipefail | |
| BADGE_DIR="wiki/${REPO}" | |
| PREFIX="https://github.com/${REPO}/${BADGE_DIR}/" | |
| COMMENT="" | |
| if [ -d "$BADGE_DIR" ]; then | |
| for f in "$BADGE_DIR"/*.svg; do | |
| [ -e "$f" ] || continue | |
| FILE=$(basename "$f") | |
| COMMENT+="[]()" | |
| done | |
| fi | |
| COMMENT+="<!-- BadgeGeneratorComment -->" | |
| # escape newlines for JSON | |
| JSON_BODY=$(printf '%s' "$COMMENT" | jq -Rs .) | |
| COMMENTS=$(curl -s -H "Authorization: token $GH_TOKEN" \ | |
| -H "Accept: application/vnd.github.v3+json" \ | |
| "https://api.github.com/repos/${REPO}/issues/${PR}/comments") | |
| ID=$(echo "$COMMENTS" | jq -r '.[] | select(.body|contains("<!-- BadgeGeneratorComment -->")) | .id') | |
| if [ -n "$ID" ]; then | |
| curl -s -X PATCH \ | |
| -H "Authorization: token $GH_TOKEN" \ | |
| -H "Accept: application/vnd.github.v3+json" \ | |
| -d "{\"body\":$JSON_BODY}" \ | |
| "https://api.github.com/repos/${REPO}/issues/comments/${ID}" | |
| else | |
| curl -s -X POST \ | |
| -H "Authorization: token $GH_TOKEN" \ | |
| -H "Accept: application/vnd.github.v3+json" \ | |
| -d "{\"body\":$JSON_BODY}" \ | |
| "https://api.github.com/repos/${REPO}/issues/${PR}/comments" | |
| fi |