Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions .github/workflows/test_action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
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
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 }}

- name: Update or add PR comment
uses: DARMA-tasking/comment-on-pr@master
with:
repo_owner: ${{ github.event.repository.owner.login }}
repo_name: ${{ github.event.repository.name }}
pr_number: ${{ github.event.pull_request.number }}
comment_title: "Generated badges"
comment_content: |
[![](https://github.com/DARMA-tasking/badge-generator/wiki/DARMA-tasking/badge-generator/vt-build-amd64-alpine-3-16-clang-cpp-badge.svg)]()
[![](https://github.com/DARMA-tasking/badge-generator/wiki/DARMA-tasking/badge-generator/vt-build-amd64-ubuntu-20-04-gcc-9-cuda-12-2-0-cpp-badge.svg)]()
[![](https://github.com/DARMA-tasking/badge-generator/wiki/DARMA-tasking/badge-generator/vt-build-amd64-ubuntu-20-04-gcc-10-openmpi-cpp-spack-badge.svg)]()
[![](https://github.com/DARMA-tasking/badge-generator/wiki/DARMA-tasking/badge-generator/vt-build-amd64-ubuntu-22-04-gcc-12-cpp-badge.svg)]()
github_token: ${{ secrets.GITHUB_TOKEN }}
53 changes: 45 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,47 @@
# DARMA-tasking template repository
# Generate and Commit Badge to Wiki

Template repository with base configuration.
Generates a status badge using [Shields.io](https://shields.io) and commits it to a repository’s **Wiki**.

Included workflows:
* [*check-pr-fixes-issue*](https://github.com/DARMA-tasking/check-pr-fixes-issue) - checking if PR description contains phrase "Fixes #issue", and if PR title, description and branch mention the same issue number
* [*find-unsigned-commits*](https://github.com/DARMA-tasking/find-unsigned-commits) - checking if there are any unsigned commits in PR
* [*find-trailing-whitespace*](https://github.com/DARMA-tasking/find-trailing-whitespace) - checking if there are any trailing whitespaces in files
* [*check-commit-format*](https://github.com/DARMA-tasking/check-commit-format) - checking if commit message is properly formatted - either starts with "*Merge ...*" or fullfils template: "*#issue_number: short commit description*"
* [*action-git-diff-check*](https://github.com/joel-coffman/action-git-diff-check) - checking if changes introduce conflict markers or whitespace errors
---

## Inputs

| Name | Required | Description |
|----------------|----------|------------------------------------------------------------------------|
| `name` | Yes | Label for the badge (e.g., matrix item) |
| `result` | Yes | Result of a previous step (`success` or `failure`). |
| `github_token` | Yes | GitHub token with **read/write access to the Wiki**. |

---


## Example

```
- name: Generate build badge
uses: DARMA-tasking/badge-generator@master
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 }}
```

This will generate and commit to [wiki](https://github.com/DARMA-tasking/badge-generator.wiki.git) four badges:

[![](https://github.com/DARMA-tasking/badge-generator/wiki/DARMA-tasking/badge-generator/vt-build-amd64-alpine-3-16-clang-cpp-badge.svg)]() <br>
[![](https://github.com/DARMA-tasking/badge-generator/wiki/DARMA-tasking/badge-generator/vt-build-amd64-ubuntu-20-04-gcc-9-cuda-12-2-0-cpp-badge.svg)]() <br>
[![](https://github.com/DARMA-tasking/badge-generator/wiki/DARMA-tasking/badge-generator/vt-build-amd64-ubuntu-20-04-gcc-10-openmpi-cpp-spack-badge.svg)]() <br>
[![](https://github.com/DARMA-tasking/badge-generator/wiki/DARMA-tasking/badge-generator/vt-build-amd64-ubuntu-22-04-gcc-12-cpp-badge.svg)]() <br>

Then we can reference those badges using the link:
`https://github.com/DARMA-tasking/badge-generator/wiki/DARMA-tasking/{repository}/{workflow_name}-badge.svg`

(**NOTE:** `github_token` has to be a token that grants **wiki** read/write permissions to `badge-generator` repository)
76 changes: 76 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
name: 'Generate and Commit Badge to Wiki'
description: 'Generates a status badge using shields.io and commits it to the repository wiki.'
author: 'Darma-tasking'

# Define the inputs the action will accept
inputs:
names:
description: 'The labels for the badges (e.g., matrix item).'
required: true
results:
description: 'The results of build step (success, failure or cancelled).'
required: true
github_token:
description: 'GitHub token with permissions to write to the wiki.'
required: true

# Define the execution logic for the action
runs:
using: 'composite'
steps:
- name: Clone Wiki Repository
shell: bash
run: |
git clone https://x-access-token:${{ inputs.github_token }}@github.com/DARMA-tasking/badge-generator.wiki.git wiki

- name: Generate and Save Badge
shell: bash
run: |
set -euo pipefail
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JacobDomagala For the future: this script is long enough to put in an .sh file. Should be easier to get shellcheck feedback this way too.

readarray -t NAMES < <(printf '%s\n' "${{ inputs.names }}" | sed '/^[[:space:]]*$/d')
readarray -t RESULTS < <(printf '%s\n' "${{ inputs.results }}" | sed '/^[[:space:]]*$/d')


[ "${#NAMES[@]}" -eq "${#RESULTS[@]}" ] || { echo "names and results lengths differ" >&2; exit 1; }

mkdir -p "wiki/${GITHUB_REPOSITORY}"

for i in "${!NAMES[@]}"; do
NAME=${NAMES[$i]}
RESULT=${RESULTS[$i]}

case "$RESULT" in
success) COLOR=green ;;
failure) COLOR=red ;;
cancelled) COLOR=blue ;;
*) COLOR=blue ;;
esac

ENCODED_NAME=$(echo "$NAME" | sed 's/-/--/g')
echo "NAME: $NAME"
BADGE_URL="https://img.shields.io/badge/${ENCODED_NAME}-${RESULT}-${COLOR}.svg"
echo "BADGE_URL: $BADGE_URL"

curl -s -o "wiki/${GITHUB_REPOSITORY}/${NAME}-badge.svg" "$BADGE_URL"
done

- name: Commit and Push to Wiki
shell: bash
run: |
cd wiki

# Configure git user for the commit
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"

git add .

# Commit only if there are changes to prevent empty commits
if ! git diff --staged --quiet; then
git commit -m "Update badge for: ${{ inputs.name }}"
git fetch && git rebase origin/master
git push --force-with-lease
echo "Badge updated and pushed to the wiki."
else
echo "No changes to the badge. Commit skipped."
fi