build #534
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: build | |
on: | |
push: | |
workflow_dispatch: | |
schedule: | |
- cron: '45 15 * * *' | |
jobs: | |
build-packages: | |
runs-on: ubuntu-latest | |
container: | |
image: archlinux:base-devel | |
permissions: | |
contents: write | |
actions: write | |
steps: | |
- name: Create user | |
run: | | |
chmod -R a+rw . | |
useradd arch -m -d /home/arch | |
echo "arch ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers | |
sudo --set-home --user=arch mkdir -p ~arch/.cache/paru ~arch/.cache/ccache | |
- name: Cache packages | |
uses: actions/cache/restore@v3 | |
id: packages-cache | |
with: | |
key: packages | |
path: | | |
/var/cache/pacman | |
/home/arch/.cache/paru | |
- name: Upgrade system | |
run: | | |
pacman-key --init | |
pacman -Sy --needed --noconfirm archlinux-keyring | |
pacman -Syu --noconfirm --needed reflector git ccache github-cli pacman-contrib | |
- name: Add unofficial user repositories | |
run: | | |
cat << _EOF >> /etc/pacman.conf | |
[archlinuxcn] | |
Server = https://repo.archlinuxcn.org/\$arch | |
_EOF | |
pacman -Sy --noconfirm && pacman -S --noconfirm archlinuxcn-keyring | |
pacman -Syu --noconfirm | |
- name: Update mirrorlist | |
run: | | |
reflector --protocol https --latest 10 --save /etc/pacman.d/mirrorlist || exit 0 | |
- name: Enable ccache for makepkg | |
run: | | |
sed -i 's/!ccache/ccache/g' /etc/makepkg.conf | |
echo 'MAKEFLAGS="-j$(nproc --all)"' >> /etc/makepkg.conf | |
- uses: actions/cache/restore@v3 | |
id: ccache-restore | |
with: | |
path: /home/arch/.cache/ccache | |
key: arch-ccache | |
- uses: actions/checkout@v3 | |
- name: Setup git safe directory | |
run: | | |
git config --global --add safe.directory '*' | |
sudo --set-home --user=arch git config --global --add safe.directory '*' | |
chown -R arch . # DANGER | |
- name: Install aur helper | |
run: | | |
sudo pacman -S --noconfirm paru && exit 0 | |
sudo --set-home --user=arch -i -- << _EOF | |
set -e | |
git clone https://aur.archlinux.org/paru.git | |
pushd paru | |
makepkg --noconfirm --rmdeps -si | |
popd | |
rm -rf paru | |
_EOF | |
- name: Build packages | |
run: | | |
sudo --set-home --user=arch paru -Su --noconfirm --skipreview ${{ vars.PRE_INSTALL }} | |
for dir in *${{ github.event_name == 'schedule' && '-git' || '' }}/; do | |
echo ::group::$dir | |
pushd $dir | |
sudo --set-home --user=arch paru -U --noconfirm --skipreview | |
popd | |
echo ::endgroup:: | |
done | |
- name: Clear GitHub action cache | |
env: | |
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
gh extension install actions/gh-actions-cache | |
if ${{ steps.ccache-restore.outputs.cache-hit == 'true' }}; then | |
gh actions-cache delete arch-ccache --confirm | |
fi | |
if ${{ steps.packages-cache.outputs.cache-hit == 'true' }}; then | |
gh actions-cache delete packages --confirm | |
fi | |
- name: Clean cache | |
run: | | |
paccache -rvvv -k 1 | |
shopt -s nullglob | |
aurs=$(pacman -Qmq) || exit 0 | |
for fn in /home/arch/.cache/paru/clone/*; do | |
if [ $(comm -12 <(grep 'pkgname' "$fn"/.SRCINFO | cut -d \ -f 3 | sort) <(echo "$aurs") | wc -l) -eq 0 ]; then | |
echo removing "$fn" | |
rm -rf "$fn" | |
fi | |
done | |
- name: Save package cache | |
if: always() | |
uses: actions/cache/save@v3 | |
with: | |
key: packages | |
path: | | |
/var/cache/pacman | |
/home/arch/.cache/paru | |
- uses: actions/cache/save@v3 | |
if: always() | |
with: | |
path: /home/arch/.cache/ccache | |
key: arch-ccache | |
- uses: softprops/action-gh-release@v1 | |
if: ${{ github.ref_name == 'master' }} | |
with: | |
tag_name: latest | |
files: | | |
*/*.pkg.tar.zst |