-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild-inside-container.sh
More file actions
127 lines (111 loc) · 4.11 KB
/
build-inside-container.sh
File metadata and controls
127 lines (111 loc) · 4.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#!/usr/bin/env bash
set -e
# Container setup
pacman -Syu --disable-download-timeout --needed --noconfirm \
archlinux-keyring \
base-devel \
git \
reflector \
wget \
rust \
go \
tree
# Update mirrors with retry (after reflector is installed)
echo "🔄 Updating mirror list..."
for i in {1..5}; do
echo " Attempt $i/5..."
if reflector --latest 10 --protocol http,https --sort rate --save /etc/pacman.d/mirrorlist 2>/dev/null; then
echo "✅ Mirror list updated successfully"
break
fi
if [ $i -eq 5 ]; then
echo "⚠️ Failed to update mirrors after 5 attempts, using existing mirrorlist"
else
sleep $((i * 5))
fi
done
GID=$(id -g)
# git refuses to run if the files are not owned by the user running git
# needed for pkginfo VCS stamping in makepkg
chown -R $UID:$GID /workspace/yay
chown -R $UID:$GID /workspace/pacman-repo-builder
chown -R $UID:$GID /workspace/repo
# Build and install build-pacman-repo
cd /workspace/pacman-repo-builder
sed -i "s/alpm = \"[^\"]*\"/alpm = \"*\"/" Cargo.toml
cargo update -p alpm --aggressive
cargo build --release || (cargo fix --lib -p pacman-repo-builder && cargo build --release)
install -Dm755 target/release/build-pacman-repo /usr/local/bin/build-pacman-repo
# Patch makepkg
cd /workspace/repo
build-pacman-repo patch-makepkg --replace --unsafe-ignore-unknown-changes
sed -i "s/COMPRESSZST=.*/COMPRESSZST=(zstd -c -T0 --ultra -20 -)/" /etc/makepkg.conf
sed -i "s/OPTIONS=.*/OPTIONS=(strip docs !libtool !staticlibs emptydirs zipman purge !debug lto)/" /etc/makepkg.conf
# Install yay as root
cd /workspace/yay
# Ensure .git is present for VCS stamping
if [ ! -d .git ]; then
echo "ERROR: .git directory missing in /workspace/yay. VCS stamping will fail."
exit 10
fi
makepkg -si --noconfirm
# Setup yay wrapper
cd /workspace/repo
chmod +x yay-noninteractive
# Prepare sources and update SRCINFO
for dir in pkgbuilds/*/; do
if grep -q "^pkgver()" "$dir/PKGBUILD" 2>/dev/null; then
echo "📥 Fetching sources for $(basename "$dir")..."
(cd "$dir" && makepkg -od --nobuild --noconfirm) || true
fi
done
echo "🔄 Updating .SRCINFO files..."
build-pacman-repo sync-srcinfo --update
echo "📄 Current .SRCINFO files:"
find pkgbuilds -name ".SRCINFO" -exec cat {} \;
for dir in pkgbuilds/*/; do
if [ -f "$dir/PKGBUILD" ]; then
echo "🧹 Cleaning sources for $(basename "$dir")..."
(cd "$dir" && makepkg -odc --noconfirm) || true
fi
done
# Check for outdated packages
echo ""
echo "🔍 Debug: Existing packages in repo directory:"
ls -1 /workspace/github-pages/archlinux/*.pkg.tar.zst 2>/dev/null | xargs -I{} basename {} || echo " (none)"
echo ""
echo "🔍 Debug: Running outdated check with full details:"
build-pacman-repo outdated --details lossy-yaml || true
echo ""
OUTDATED=$(build-pacman-repo outdated --details pkgname)
if [ -z "$OUTDATED" ]; then
echo "✅ All packages are up-to-date, nothing to build"
echo "has_outdated=false" >> /workspace/.github-output
else
echo "📦 Outdated packages to build:"
echo "$OUTDATED"
echo "has_outdated=true" >> /workspace/.github-output
# Convert newline-separated package names to comma-separated list for commit message
PACKAGE_LIST=$(echo "$OUTDATED" | tr '\n' ',' | sed 's/,$//')
echo "packages=$PACKAGE_LIST" >> /workspace/.github-output
chmod ugo+r /workspace/.github-output
# Build if outdated
test -d /workspace/github-pages/archlinux || (echo "cannot find the gh pages repo, exiting" && exit 1)
build-pacman-repo build || (echo "build-pacman-repo failed" && tree -lah pkgbuilds/ -I "src|pkg|.git|.cache" && exit 2)
# Verify packages
REPO_DIR="/workspace/github-pages/archlinux"
echo ""
echo ""
echo "📦 Packages in repository:"
ls -lah "$REPO_DIR/"*.pkg.tar.zst 2>/dev/null || echo " (none found)"
PKG_COUNT=$(find "$REPO_DIR" -maxdepth 1 -name "*.pkg.tar.zst" | wc -l)
if [ "$PKG_COUNT" -eq 0 ]; then
echo "ERROR: No packages found in repository"
exit 3
fi
echo "✅ Found $PKG_COUNT package(s):"
find "$REPO_DIR" -maxdepth 1 -name "*.pkg.tar.zst" | while read -r pkg; do
size_mb=$(du -m "$pkg" | cut -f1)
echo "$(basename "$pkg") - ${size_mb}MB"
done
fi