generated from DARMA-tasking/template-repository
-
Notifications
You must be signed in to change notification settings - Fork 0
#1: Badge generator github action #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
20674bf
#1: Create action.yml
JacobDomagala a252de1
#1: Encode dashes as %2D for the badge
JacobDomagala 1be720c
#1: Cleanup action.yml file
JacobDomagala f114ff3
#1: Improve README
JacobDomagala c186316
#1: Encode single dash as double dash
JacobDomagala 6ff8056
#1: Use GITHUB_REPOSITORY for per-repo directories
JacobDomagala 35ba04b
#1: Add test for generating badges
JacobDomagala d313d56
#1: Update test and make sure to --rebase when pushing new badge:
JacobDomagala 4f7be37
#1: Allow for multiple names and results
JacobDomagala 5318057
#1: Fix tests
JacobDomagala 05a26ee
#1: Use DARMA-tasking/comment-on-pr for test
JacobDomagala 47d0865
#1: Cleanup README and remove push input
JacobDomagala File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| 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: | | ||
| []() | ||
| []() | ||
| []() | ||
| []() | ||
| github_token: ${{ secrets.GITHUB_TOKEN }} |
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
| 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: | ||
|
|
||
| []() <br> | ||
| []() <br> | ||
| []() <br> | ||
| []() <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) |
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
| 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 | ||
| 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 | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.