Skip to content

Commit 5403216

Browse files
GHCR
1 parent c886424 commit 5403216

2 files changed

Lines changed: 50 additions & 1 deletion

File tree

.github/workflows/ghcr-badges.yml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
name: GHCR Badges
2+
3+
on:
4+
schedule:
5+
- cron: '0 * * * *'
6+
workflow_dispatch:
7+
8+
jobs:
9+
compute:
10+
runs-on: ubuntu-latest
11+
permissions:
12+
contents: write
13+
packages: read
14+
steps:
15+
- name: Checkout
16+
uses: actions/checkout@v4
17+
18+
- name: Fetch GHCR stats
19+
id: fetch
20+
env:
21+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
22+
run: |
23+
set -euo pipefail
24+
OWNER=stuartasiimwe7
25+
REPO=Cloud-Security-Monitoring-API
26+
PKG=$(echo "$REPO" | tr '[:upper:]' '[:lower:]')
27+
# Fetch versions
28+
URL="https://api.github.com/users/${OWNER}/packages/container/${PKG}/versions?per_page=100"
29+
JSON=$(curl -sS -H "Authorization: Bearer ${GH_TOKEN}" -H "Accept: application/vnd.github+json" "$URL")
30+
# Sum pulls and capture latest tag name if present
31+
PULLS=$(echo "$JSON" | jq '[.[].metadata.container.download_count] | add // 0')
32+
LATEST=$(echo "$JSON" | jq -r '.[0].metadata.container.tags[0] // "latest"')
33+
TAGS=$(echo "$JSON" | jq '[.[].metadata.container.tags] | flatten | unique | length')
34+
mkdir -p .github/badges
35+
printf '{"schemaVersion":1,"label":"ghcr pulls","message":"%s","color":"blue"}\n' "$PULLS" > .github/badges/ghcr-pulls.json
36+
printf '{"schemaVersion":1,"label":"latest tag","message":"%s","color":"green"}\n' "$LATEST" > .github/badges/ghcr-latest.json
37+
printf '{"schemaVersion":1,"label":"tags","message":"%s","color":"informational"}\n' "$TAGS" > .github/badges/ghcr-tags.json
38+
39+
- name: Commit badge JSON
40+
run: |
41+
set -e
42+
if [[ -n $(git status --porcelain .github/badges) ]]; then
43+
git config user.name "github-actions"
44+
git config user.email "github-actions@users.noreply.github.com"
45+
git add .github/badges/*.json
46+
git commit -m "chore(badges): update GHCR badge JSON"
47+
git push
48+
fi
49+

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## Overview [![CI](https://github.com/stuartasiimwe7/cloud-security-monitoring-api/actions/workflows/ci.yml/badge.svg)](https://github.com/stuartasiimwe7/cloud-security-monitoring-api/actions/workflows/ci.yml) [![CD](https://github.com/stuartasiimwe7/cloud-security-monitoring-api/actions/workflows/cd.yml/badge.svg)](https://github.com/stuartasiimwe7/cloud-security-monitoring-api/actions/workflows/cd.yml)
1+
## Overview [![CI](https://github.com/stuartasiimwe7/cloud-security-monitoring-api/actions/workflows/ci.yml/badge.svg)](https://github.com/stuartasiimwe7/cloud-security-monitoring-api/actions/workflows/ci.yml) [![CD](https://github.com/stuartasiimwe7/cloud-security-monitoring-api/actions/workflows/cd.yml/badge.svg)](https://github.com/stuartasiimwe7/cloud-security-monitoring-api/actions/workflows/cd.yml) ![Downloads](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/stuartasiimwe7/Cloud-Security-Monitoring-API/main/.github/badges/ghcr-pulls.json) ![Latest](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/stuartasiimwe7/Cloud-Security-Monitoring-API/main/.github/badges/ghcr-latest.json) ![Tags](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/stuartasiimwe7/Cloud-Security-Monitoring-API/main/.github/badges/ghcr-tags.json)
22
Cloud environments generate high-volume, high-velocity activity logs (for example, AWS CloudTrail) across many accounts and regions.
33

44
Security teams struggle to normalise, store, and query these events quickly for incident response, compliance, and threat detection.

0 commit comments

Comments
 (0)