feat(ci): Build per architecture #1
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: | ||
workflow_call: | ||
inputs: | ||
packages: | ||
description: List of packages to build | ||
type: string | ||
default: '[]' | ||
defaults: | ||
run: | ||
shell: bash | ||
jobs: | ||
determine_architectures: | ||
runs-on: ubuntu-latest | ||
outputs: | ||
architectures: ${{ steps.extract-architectures.outputs.architectures }} | ||
steps: | ||
- name: Check out code | ||
uses: actions/checkout@v4 | ||
- name: Update system and install dependencies | ||
run: | | ||
sed -i 's/#\[multilib\]/\[multilib\]/' /etc/pacman.conf | ||
pacman-key --init | ||
pacman -Syu --noconfirm | ||
pacman -S --noconfirm --needed fd | ||
- name: Extract architectures | ||
id: extract-architectures | ||
run: | | ||
for file in $(fd --type f -- PKGBUILD) | ||
do | ||
source $file | ||
echo ${arch[@]} | ||
if [ $arch != 'any' ] | ||
then | ||
echo "archictectures=${arch[@]}" >> $GITHUB_OUTPUT | ||
else | ||
echo "architectures=('x86_64')" >> $GITHUB_OUTPUT | ||
fi | ||
done | ||
build: | ||
name: Build | ||
runs-on: ubuntu-latest | ||
container: archlinux:base-devel | ||
needs: determine_architectures | ||
if: ${{ inputs.packages != '[]' && inputs.packages != '[""]' && inputs.packages != '' }} | ||
strategy: | ||
matrix: | ||
package: ${{ fromJson(inputs.packages) }} | ||
arch: ${{ fromJson(needs.determine_architectures.outputs.architectures) }} | ||
fail-fast: false | ||
steps: | ||
- name: Test | ||
run: | | ||
echo ${{ matrix.package }} | ||
- uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: '0' | ||
- name: Update system and install dependencies | ||
run: | | ||
sed -i 's/#\[multilib\]/\[multilib\]/' /etc/pacman.conf | ||
pacman-key --init | ||
pacman -Syu --noconfirm | ||
pacman -S --noconfirm --needed git fd jq namcap eza | ||
- name: Create user to run makepkg | ||
run: | | ||
useradd -m dev | ||
echo "dev ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/01_dev | ||
- name: chown for dev | ||
run: | | ||
chown -R dev: . | ||
- name: Handle PGP keys | ||
run: | | ||
cd ${{ matrix.package }} | ||
source PKGBUILD | ||
for key in ${validpgpkeys} | ||
do | ||
runuser -u dev -- gpg --recv-keys ${key} | ||
done | ||
- name: Install yay | ||
run: | | ||
runuser -u dev -- git clone https://aur.archlinux.org/yay.git | ||
cd yay | ||
runuser -u dev -- makepkg -csri --noconfirm | ||
- name: Install package dependencies from AUR | ||
run: | | ||
cd ${{ matrix.package }} | ||
pacman -Ssq > pkglist | ||
source PKGBUILD | ||
echo ${depends[@]} ${makedepends[@]} ${checkdepends[@]} | ||
packages=() | ||
pacman_took_care_of_it=() | ||
for dep in ${depends[@]} ${makedepends[@]} ${checkdepends[@]} | ||
do | ||
# We do this first because yay and pacman function differently with | ||
# version constraints | ||
if pacman -S --noconfirm --asdeps "${dep}" | ||
then | ||
pacman_took_care_of_it+=("${dep}") | ||
echo "pacman installed: ${dep}" | ||
else | ||
packages+=("${dep}") | ||
echo "Queueing for yay: ${dep}" | ||
fi | ||
done | ||
echo "pacman installed these: ${pacman_took_care_of_it[@]}" | ||
echo "yay will install these: ${packages[@]}" | ||
runuser -u dev -- yay -S --noconfirm --asdeps "${packages[@]}" | ||
- name: Build and install package | ||
run: | | ||
cd ${{ matrix.package }} | ||
runuser -u dev -- makepkg -csri --noconfirm | ||
- name: Grab built package's filename | ||
run: | | ||
cd ${{ matrix.package }} | ||
source PKGBUILD | ||
counter=0 | ||
for single_package in ${pkgname} | ||
do | ||
counter=$((counter+1)) | ||
echo "filename_${counter}=$(eza ${single_package}*.pkg.tar.zst -I *-debug-*.pkg.tar.zst)" >> $GITHUB_ENV | ||
done | ||
echo "Found ${counter} artifacts" | ||
if eza *-debug-*.pkg.tar.zst | ||
then | ||
echo "filename_debug=$(eza *-debug-*.pkg.tar.zst)" >> $GITHUB_ENV | ||
fi | ||
- name: Upload artifact | ||
if: env.filename_1 | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: ${{ env.filename_1 }} | ||
path: | | ||
${{ matrix.package }}/${{ env.filename_1 }} | ||
- name: 'Upload artifact #2' | ||
if: env.filename_2 | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: ${{ env.filename_2 }} | ||
path: | | ||
${{ matrix.package }}/${{ env.filename_2 }} | ||
- name: Upload debug artifacts | ||
if: env.filename_debug | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: ${{ env.filename_debug }} | ||
path: | | ||
${{ matrix.package }}/${{ env.filename_debug }} |