Files
hyprarch-repo/.github/workflows/update-repo.yml
2026-03-23 15:53:48 +01:00

145 lines
5.4 KiB
YAML

name: Update Arch Repository
on:
push:
paths:
- 'x86_64/*.pkg.tar.zst'
workflow_dispatch:
jobs:
update-db:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup tools
run: sudo apt-get update && sudo apt-get install -y libarchive-tools gpg
- name: Import GPG Key
run: |
# Ensure you have added GPG_PRIVATE_KEY to your GitHub Secrets!
echo "${{ secrets.GPG_PRIVATE_KEY }}" | gpg --import --batch
- name: Update Repository Database
run: |
cd x86_64
# Remove old DB and sig files for a clean build
rm -f hyprarch-repo.db* hyprarch-repo.files*
mkdir -p db_temp
for pkg in *.pkg.tar.zst; do
# 1. Sign the package file
gpg --detach-sign --batch --no-armor --local-user 236328A7F2C2001E "$pkg"
# 2. Extract specific metadata (Strict Cleaning)
pkgname=$(bsdtar -xOf "$pkg" .PKGINFO | grep "^pkgname =" | cut -d' ' -f3)
pkgver=$(bsdtar -xOf "$pkg" .PKGINFO | grep "^pkgver =" | cut -d' ' -f3)
pkgdesc=$(bsdtar -xOf "$pkg" .PKGINFO | grep "^pkgdesc =" | cut -d' ' -f3- | sed "s/['\"]//g")
mkdir -p "db_temp/$pkgname-$pkgver"
# Manually construct the 'desc' file to avoid "unknown key" errors
{
echo "%NAME%"
echo "$pkgname"
echo ""
echo "%VERSION%"
echo "$pkgver"
echo ""
echo "%DESC%"
echo "$pkgdesc"
echo ""
echo "%FILENAME%"
echo "$pkg"
echo ""
echo "%CSIZE%"
echo "$(stat -c%s "$pkg")"
echo ""
echo "%ISIZE%"
echo "$(bsdtar -xOf "$pkg" .PKGINFO | grep "^size =" | cut -d' ' -f3)"
echo ""
echo "%PGPSIG%"
gpg --detach-sign --stdout --no-armor --local-user 236328A7F2C2001E "$pkg" | base64 | tr -d '\n'
echo ""
} > "db_temp/$pkgname-$pkgver/desc"
done
# 3. Compress the metadata into a real Arch DB
cd db_temp
tar -c * | gzip -9 > ../hyprarch-repo.db.tar.gz
cd ..
# 4. Sign the database itself
gpg --detach-sign --batch --no-armor --local-user 236328A7F2C2001E hyprarch-repo.db.tar.gz
# 5. Finalize files
cp hyprarch-repo.db.tar.gz hyprarch-repo.db
cp hyprarch-repo.db.tar.gz.sig hyprarch-repo.db.sig
cp hyprarch-repo.db.tar.gz hyprarch-repo.files
rm -rf db_temp
- name: Generate Subfolder Index
run: |
cd x86_64
echo "<html><head><title>Index of /x86_64/</title></head><body style='font-family: monospace;'>" > index.html
echo "<h1>Index of /x86_64/</h1><hr><pre>" >> index.html
echo "<a href='../'>../</a>" >> index.html
for file in *; do
if [[ "$file" != "index.html" ]]; then
size=$(du -sh "$file" | cut -f1)
date=$(date -r "$file" '+%d-%b-%Y %H:%M')
printf "<a href='%s'>%s</a>%-$(($(printf '%s' "$file" | wc -c) > 50 ? 1 : 50 - $(printf '%s' "$file" | wc -c)))s %s %8s\n" "$file" "$file" "" "$date" "$size" >> index.html
fi
done
echo "</pre><hr></body></html>" >> index.html
- name: Generate Root Landing Page
run: |
echo '<!DOCTYPE html>
<html>
<head>
<title>HyprArch Repository</title>
<style>
body { font-family: sans-serif; margin: 40px; line-height: 1.6; background: #2e3440; color: #eceff4; }
a { color: #88c0d0; text-decoration: none; }
a:hover { text-decoration: underline; }
.container { max-width: 800px; margin: auto; background: #3b4252; padding: 20px; border-radius: 8px; }
h1 { border-bottom: 2px solid #4c566a; padding-bottom: 10px; }
pre { background: #2e3440; padding: 15px; border-radius: 5px; color: #ebcb8b; }
</style>
</head>
<body>
<div class="container">
<h1>🚀 HyprArch Custom Repository</h1>
<p>To use this repository, add the following to your <code>/etc/pacman.conf</code>:</p>
<pre>[hyprarch-repo]
SigLevel = Required DatabaseOptional
Server = https://hyprarch-repo.stuple.net/$arch</pre>
<h2>📦 Available Packages</h2>
<ul>
<li><a href="./x86_64/">Browse x86_64 Packages</a></li>
</ul>
<hr>
<p><small>Automated by GitHub Actions</small></p>
</div>
</body>
</html>' > index.html
- name: Commit and Push changes
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git add .
if ! git diff-index --quiet HEAD; then
git commit -m "Final Fix: Clean Metadata and GPG Signed DB"
git push
else
echo "Nothing to change."
fi