ci: sync-codeberg also stamps .profile README with badges + activity
This commit is contained in:
parent
6a59d46631
commit
8c7e6a4d76
1 changed files with 74 additions and 1 deletions
|
|
@ -188,7 +188,8 @@ jobs:
|
|||
echo "All action refs are SHA-pinned."
|
||||
|
||||
# Push public to Codeberg when all checks pass — nightly mirror.
|
||||
# Requires CODECBERG_TOKEN secret in the repo settings.
|
||||
# Also updates the .profile README with latest release badges and
|
||||
# recent activity. Requires CODECBERG_TOKEN secret in the repo settings.
|
||||
sync-codeberg:
|
||||
runs-on: ubuntu-latest
|
||||
needs: [go-vet, go-test, rust-test, cross-compile, web-build, installer-integrity, no-ai-attribution, action-pins]
|
||||
|
|
@ -206,3 +207,75 @@ jobs:
|
|||
git remote add codeberg-ci "https://${{ secrets.CODECBERG_TOKEN }}@codeberg.org/Fimeg/RedFlag.git"
|
||||
git push codeberg-ci public:public
|
||||
echo "Pushed public to codeberg.org/Fimeg/RedFlag"
|
||||
|
||||
- name: Update profile README
|
||||
run: |
|
||||
set -euo pipefail
|
||||
TOKEN="${{ secrets.CODECBERG_TOKEN }}"
|
||||
|
||||
# Clone the .profile repo
|
||||
git clone "https://${TOKEN}@codeberg.org/Fimeg/.profile.git" /tmp/profile
|
||||
cd /tmp/profile
|
||||
|
||||
# Fetch latest RedFlag release tag from codeberg API
|
||||
RF_VER=$(curl -sf "https://codeberg.org/api/v1/repos/Fimeg/RedFlag/releases/latest" \
|
||||
-H "Authorization: token ${TOKEN}" | python3 -c "import sys,json; print(json.load(sys.stdin).get('tag_name','v0.2.x'))" 2>/dev/null || echo "v0.2.x")
|
||||
echo "RedFlag: $RF_VER"
|
||||
|
||||
# Fetch latest Souveraine release tag from codeberg API
|
||||
SV_VER=$(curl -sf "https://codeberg.org/api/v1/repos/Fimeg/Souveraine/releases/latest" \
|
||||
-H "Authorization: token ${TOKEN}" | python3 -c "import sys,json; print(json.load(sys.stdin).get('tag_name','dev'))" 2>/dev/null || echo "dev")
|
||||
echo "Souveraine: $SV_VER"
|
||||
|
||||
# Fetch recent activity (last 6 push/create/release events)
|
||||
curl -sf "https://codeberg.org/api/v1/users/Fimeg/events?limit=20" \
|
||||
-H "Authorization: token ${TOKEN}" | python3 -c "
|
||||
import sys, json
|
||||
events = json.load(sys.stdin)
|
||||
count = 0
|
||||
for e in events:
|
||||
if count >= 6: break
|
||||
t = e.get('type','')
|
||||
repo = e.get('repo',{}).get('name','')
|
||||
url = 'https://codeberg.org/' + repo
|
||||
if t == 'ReleaseEvent':
|
||||
tag = e.get('payload',{}).get('release',{}).get('tag_name','')
|
||||
print(f' - [**{repo}**]({url}) — released **{tag}**')
|
||||
count += 1
|
||||
elif t == 'PushEvent':
|
||||
n = len(e.get('payload',{}).get('commits',[]))
|
||||
print(f' - [**{repo}**]({url}) — {n} commit{"s" if n!=1 else ""}')
|
||||
count += 1
|
||||
elif t == 'CreateEvent':
|
||||
ref = e.get('payload',{}).get('ref','')
|
||||
print(f' - [**{repo}**]({url}) — created **{ref}**')
|
||||
count += 1
|
||||
" > /tmp/activity.md || true
|
||||
|
||||
# If no activity fetched, write placeholder
|
||||
if [ ! -s /tmp/activity.md ]; then
|
||||
echo " - _no recent activity_" > /tmp/activity.md
|
||||
fi
|
||||
echo "Activity:"
|
||||
cat /tmp/activity.md
|
||||
|
||||
# Stamp badges
|
||||
TODAY=$(date -u +%Y-%m-%d)
|
||||
sed -i "s|RedFlag-v[^ ]*-green|RedFlag-${RF_VER}-green|" README.md
|
||||
sed -i "s|Souveraine-[^ ]*-blue|Souveraine-${SV_VER}-blue|" README.md
|
||||
sed -i "s|Updated-[^ ]*-gray|Updated-${TODAY}-gray|" README.md
|
||||
|
||||
# Stamp activity section (replace between <!--ACTIVITY--> markers)
|
||||
awk '
|
||||
/<!--ACTIVITY-->/ { print; system("cat /tmp/activity.md"); inblock=1; next }
|
||||
/<!--\/ACTIVITY-->/ { inblock=0 }
|
||||
!inblock' README.md > README.tmp && mv README.tmp README.md
|
||||
|
||||
# Commit and push if changed
|
||||
git config user.name "sync-bot"
|
||||
git config user.email "ci@codeberg.org"
|
||||
git diff --quiet README.md || {
|
||||
git commit -m "sync: badges + activity for ${TODAY}"
|
||||
git push origin main
|
||||
echo "Profile README updated"
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue