Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/joshjohanning/organization-readme-badge-generator
An action to generate organization readme badges
https://github.com/joshjohanning/organization-readme-badge-generator
actions github org-readme
Last synced: 29 days ago
JSON representation
An action to generate organization readme badges
- Host: GitHub
- URL: https://github.com/joshjohanning/organization-readme-badge-generator
- Owner: joshjohanning
- License: mit
- Created: 2024-05-21T17:25:10.000Z (7 months ago)
- Default Branch: main
- Last Pushed: 2024-08-13T22:07:17.000Z (4 months ago)
- Last Synced: 2024-10-14T09:47:40.064Z (2 months ago)
- Topics: actions, github, org-readme
- Language: JavaScript
- Homepage:
- Size: 871 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# organization-readme-badge-generator
An action to create markdown badges for your GitHub organization's README.md file using Shields.io.
## Example
> # my-org-name
>
> ![Total repositories](https://img.shields.io/static/v1?label=Total%20repositories&message=341&color=blue) ![Open PRs in last 30 days](https://img.shields.io/static/v1?label=Open%20PRs%20in%20last%2030%20days&message=29&color=blue) ![Merged PRs in last 30 days](https://img.shields.io/static/v1?label=Merged%20PRs%20in%20last%2030%20days&message=2&color=blue)_Live example in my [`joshjohanning-org` org public README](https://github.com/joshjohanning-org#joshjohanning-org)_
## Usage
### Prerequisite
The action runs and generates an output with the markdown badges. There is a sample script provided that runs after the action to inserts the markdown in between two markers in the `profile/README.md` file ([example](https://github.com/joshjohanning-org/.github/blob/main/profile/README.md?plain=1)) and commit the changes if the file has changed.
```md
# my-org-name
```
### Example Workflow
```yml
name: update-organization-readme-badgeson:
schedule:
- cron: '0 7 * * *' # runs daily at 07:00
workflow_dispatch:permissions:
contents: writejobs:
generate-badges:
runs-on: ubuntu-lateststeps:
- uses: actions/checkout@v4- uses: actions/create-github-app-token@v1
id: app-token
with:
app-id: ${{ vars.APP_ID }}
private-key: ${{ secrets.PRIVATE_KEY }}
owner: ${{ github.repository_owner }}- name: organization-readme-badge-generator
id: organization-readme-badge-generator
uses: joshjohanning/organization-readme-badge-generator@v1
with:
organization: ${{ github.repository_owner }}
token: ${{ steps.app-token.outputs.token }} # recommend to use a GitHub App and not a PAT
- name: write to job summary
run: |
echo "${{ steps.organization-readme-badge-generator.outputs.badges }}" >> $GITHUB_STEP_SUMMARY- name: add to readme
run: |
readme=profile/README.md
# get SHA256 before
beforeHash=$(sha256sum $readme | awk '{ print $1 }')
# Define start and end markers
startMarker=""
endMarker=""
replacement="${{ steps.organization-readme-badge-generator.outputs.badges }}"
# Escape special characters in the replacement text
replacementEscaped=$(printf '%s\n' "$replacement" | perl -pe 's/([\\\/\$\(\)@])/\\$1/g')
# Use perl to replace the text between the markers
perl -i -pe "BEGIN{undef $/;} s/\Q$startMarker\E.*?\Q$endMarker\E/$startMarker\n$replacementEscaped\n$endMarker/smg" $readme
# get SHA256 after
afterHash=$(sha256sum $readme | awk '{ print $1 }')
# Compare the hashes and commit if required
if [ "$afterHash" = "$beforeHash" ]; then
echo "The hashes are equal - exiting script"
exit 0
else
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
git add $readme
git commit -m "docs: update organization readme badges"
git push
fi
```