Skip to content

Commit

Permalink
refactor(ci): Modularize workflows
Browse files Browse the repository at this point in the history
Signed-off-by: txtsd <[email protected]>
  • Loading branch information
txtsd committed Oct 22, 2023
1 parent 8b7072f commit 36d0682
Show file tree
Hide file tree
Showing 3 changed files with 157 additions and 76 deletions.
85 changes: 85 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
name: Build

on:
workflow_call:
inputs:
packages:
description: List of packages to build
type: string
default: '[]'

jobs:
build:
name: Build
runs-on: ubuntu-latest
container: archlinux:base-devel
if: inputs.packages != '[]' && inputs.packages != '[""]'
strategy:
matrix:
package: ${{ fromJson(inputs.packages) }}
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: |
pacman-key --init
pacman -Syu --noconfirm
pacman -S --noconfirm --needed git fd jq namcap
- 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: Initialize gpg keyring
run: |
runuser -u dev -- gpg --list-keys
- 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=()
for dep in ${depends[@]} ${makedepends[@]} ${checkdepends[@]}
do
count=0
while IFS="" read -r p || [ -n "$p" ]
do
if [ $p == $dep ]
then
count=$((count+1))
fi
done < pkglist
if [ $count -eq 0 ]
then
packages+=("${dep}")
echo "Added $dep"
fi
done
echo ${packages[@]}
runuser -u dev -- yay -S --noconfirm --asdeps ${packages[@]}
- name: Build and install package
run: |
cd ${{ matrix.package }}
runuser -u dev -- makepkg -csri --noconfirm
68 changes: 68 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
name: Changes detected!

on:
push:
branches:
- main
paths-ignore:
- 'README.md'
- 'LICENSE'
- 'refre.sh'
- 'renovate.json'
pull_request:
types:
- opened
- reopened
- synchronized
paths-ignore:
- 'README.md'
- 'LICENSE'
- 'refre.sh'
- 'renovate.json'
workflow_dispatch:

defaults:
run:
shell: bash

jobs:
find_changes:
name: Find Changes
runs-on: ubuntu-latest
container: archlinux:base-devel
timeout-minutes: 5

outputs:
list: ${{ steps.changes.outputs.changed_pkgs }}

steps:
- name: Update system and install dependencies
run: |
pacman-key --init
pacman -Syu --noconfirm git jq
- name: Find Changes
id: changes
run: |
if [ ${{ github.event_name }} == 'push' ]
then
CHANGED_DIRS=$(git diff --name-only ${{ github.event.before }} ${{ github.event.after }} | grep PKGBUILD | cut -d / -f 1)
elif [ ${github.event_name} == 'pull_request' ]
then
CHANGED_DIRS=$(git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }} | cut -d / -f 1)
fi
# Remove .github from CHANGED_DIRS
FINAL_CHANGED_DIRS=()
for dir in $(echo $CHANGED_DIRS | sed "s|.github||")
do
FINAL_CHANGED_DIRS+=('$dir')
done
# Set output
echo "changed_pkgs=$(jq -cn '$ARGS.positional' --args "${FINAL_CHANGED_DIRS[@]}")" >> $GITHUB_OUTPUT
build:
name: Build
needs: find_changes
uses: ./.github/workflows/build.yml
with:
packages: needs.find_changes.outputs.list
80 changes: 4 additions & 76 deletions .github/workflows/schedule.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
name: Schedule

on:
push:
branches:
- main
schedule:
- cron: '0 0,6,12,18 * * *'
workflow_dispatch:
Expand Down Expand Up @@ -59,76 +57,6 @@ jobs:
build:
name: Build
needs: release_check
runs-on: ubuntu-latest
container: archlinux:base-devel
if: needs.release_check.outputs.list != '[]'
strategy:
matrix:
package: ${{ fromJson(needs.release_check.outputs.list) }}
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: |
pacman-key --init
pacman -Syu --noconfirm
pacman -S --noconfirm --needed git fd jq namcap
- 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: Initialize gpg keyring
run: |
runuser -u dev -- gpg --list-keys
- 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=()
for dep in ${depends[@]} ${makedepends[@]} ${checkdepends[@]}
do
count=0
while IFS="" read -r p || [ -n "$p" ]
do
if [ $p == $dep ]
then
count=$((count+1))
fi
done < pkglist
if [ $count -eq 0 ]
then
packages+=("${dep}")
echo "Added $dep"
fi
done
echo ${packages[@]}
runuser -u dev -- yay -S --noconfirm --asdeps ${packages[@]}
- name: Build and install package
run: |
cd ${{ matrix.package }}
runuser -u dev -- makepkg -csri --noconfirm
uses: ./.github/workflows/build.yml
with:
packages: needs.release_check.outputs.list

0 comments on commit 36d0682

Please sign in to comment.