Skip to content

Update Packages

Update Packages #46

name: Update Packages
on:
schedule:
- cron: '0 2 * * *' # Run at 2 AM UTC daily
workflow_dispatch: # Allow manual trigger
jobs:
update-packages:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- name: Checkout Repository
uses: actions/checkout@v4
with:
ref: dev
- name: Set up environment variables
id: env
run: |
echo "WORKSPACE=${GITHUB_WORKSPACE}" >> $GITHUB_ENV
echo "CACHE_KEY=$(date +'%Y-%m')" >> $GITHUB_ENV
- name: Create Cache Directory
run: |
sudo mkdir -p /tmp/pacman-cache
sudo chmod 777 /tmp/pacman-cache
- name: Cache Pacman packages
uses: actions/cache@v4
with:
path: /tmp/pacman-cache
key: pacman-${{ env.CACHE_KEY }}
restore-keys: |
pacman-
- name: Set up Docker
run: |
docker run --privileged --name arch-container -d \
-v ${{ env.WORKSPACE }}:/workdir \
-v /tmp/pacman-cache:/var/cache/pacman/pkg \
archlinux:latest sleep infinity
- name: Initialize Container
run: |
docker exec arch-container bash -c "
set -euo pipefail
cd /workdir
# Update package database
pacman -Sy --noconfirm
# Install required packages
pacman -S --noconfirm --needed curl jq
"
- name: Check for Package Updates
id: check-updates
run: |
docker exec arch-container bash -c "
set -euo pipefail
cd /workdir
# Create temporary files in workspace
touch current-packages.txt updates.txt
# Get current packages
grep -v '^#' packages.x86_64 | grep -v '^$' > current-packages.txt
# Initialize pacman
pacman -Sy
# Process each package
while read -r pkg; do
if pacman -Si \"\$pkg\" >/dev/null 2>&1; then
current_ver=\$(pacman -Si \"\$pkg\" | grep Version | head -n1 | awk '{print \$3}')
echo \"\$pkg \$current_ver\" >> updates.txt
else
echo \"Warning: Package \$pkg not found in repositories\"
fi
done < current-packages.txt
# Check if we have updates
if [ -s updates.txt ]; then
echo 'updates_available=true' >> \$GITHUB_OUTPUT
echo 'Found updates:'
cat updates.txt
else
echo 'updates_available=false' >> \$GITHUB_OUTPUT
echo 'No updates found'
fi
"
- name: Create Pull Request
if: steps.check-updates.outputs.updates_available == 'true'
uses: peter-evans/create-pull-request@v7
with:
token: ${{ secrets.GITHUB_TOKEN }}
commit-message: "chore: update package versions"
title: "📦 Automatic Package Updates"
body: |
🔄 Automatic package update
The following packages have been updated to their latest version:
```
$(cat updates.txt)
```
This PR was automatically generated by the update-packages workflow.
branch: package-updates
base: dev
labels: |
automated
dependencies
draft: false
- name: Clean Up
if: always()
run: |
docker stop arch-container || true
docker rm arch-container || true
sudo rm -rf /tmp/pacman-cache/*