Skip to content

Update Cachy Files with Latest Releases #6

Update Cachy Files with Latest Releases

Update Cachy Files with Latest Releases #6

Workflow file for this run

name: Update Cachy Files with Latest Releases
on:
schedule:
# * is a special character in YAML so you have to quote this string
- cron: '30 5,17 * * *'
pull_request:
types: [opened, reopened]
workflow_dispatch:
jobs:
update-cachy:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Find PKGBUILD Files, Check and Update Latest Release
run: |
echo $PWD
export ROOT_DIR=/home/runner/work
ls
touch $ROOT_DIR/dirs_to_commit.txt
while IFS= read -r dir; do
find "$dir" -name '*PKGBUILD' -not -path '*/-git/*' | while read pkgbuild; do
echo "Processing $pkgbuild"
url=$(grep -oP -m 1 'url=\K.*' "$pkgbuild")
current_release=$(grep -oP 'pkgver=\K.*' "$pkgbuild")
echo "Configured URL: $url"
echo "Current Release: $current_release"
# Extract owner and repo from URL
owner_repo=$(echo "$url" | sed "s/.*github\.com\/\([^']*\).*/\1/")
# if there is an extra " or ' at the end of the URL, remove it
owner_repo=$(echo "$owner_repo" | sed "s/['\"]$//")
echo "Owner/Repo: $owner_repo"
# Use GitHub API to get the latest release
latest_release=$(curl -s "https://api.github.com/repos/$owner_repo/releases/latest" | grep -oP '"tag_name": "\K(.*)(?=")')
echo "Latest Release: $latest_release"
# Dealing with wierd versioning
# remove "php-" from the beginning of the version
latest_release=$(echo $latest_release | sed 's/^php-//')
# Remove leading 'v' if present
latest_release_formatted=$(echo $latest_release | sed 's/^v//')
echo "Latest Release (formatted): $latest_release_formatted"
# Check if the current release is different from the latest release
if [ "$current_release" != "$latest_release_formatted" ]; then
echo "Updating PKGBUILD file with latest release"
# add dir to list of dirs to commit
$dirname >> $ROOT_DIR/dirs_to_commit.txt
# Check for PKGBUILD file in the same directory
pkgbuild_file="$(dirname "$pkgbuild")/PKGBUILD"
echo "Updating PKGBUILD file with latest release and resetting pkgrel to 1"
sed -i "s/pkgver=$current_release/pkgver=$latest_release_formatted/" "$pkgbuild_file"
sed -i "s/pkgrel=.*/pkgrel=1/" "$pkgbuild_file"
git add "$pkgbuild_file"
fi
echo "-----------------------------------"
done
done < pkgs_to_check.txt
echo $PWD
mkdir -p $ROOT_DIR/to_commit
while read line; do
cp -r $ROOT_DIR/CachyOS-PKGBUILDS/CachyOS-PKGBUILDS/$line $ROOT_DIR/to_commit
done < $ROOT_DIR/dirs_to_commit.txt
- name: Checkout Master Branch
uses: actions/checkout@v4
with:
ref: master
- name: Commit and Push Changes
run: |
export ROOT_DIR=/home/runner/work
echo "Checking if to_commit directory exists and is not empty"
# check if to_commit directory exists and is not empty
if [ -d "$ROOT_DIR/to_commit" ] && [ "$(ls -A $ROOT_DIR/to_commit)" ]; then
cp -r $ROOT_DIR/to_commit/* $ROOT_DIR/CachyOS-PKGBUILDS/CachyOS-PKGBUILDS/
cd $ROOT_DIR/CachyOS-PKGBUILDS/CachyOS-PKGBUILDS/
else
echo "Directory does not exist or is empty"
exit 0
fi
- name: Create Pull Request
uses: peter-evans/create-pull-request@v5
with:
commit-message: update .cachy files with latest releases
title: Update Packages with Latest Releases