Skip to content

Commit

Permalink
feat(bot): new bot
Browse files Browse the repository at this point in the history
  • Loading branch information
lseman authored Dec 29, 2023
1 parent d4b6e5c commit f346157
Showing 1 changed file with 18 additions and 95 deletions.
113 changes: 18 additions & 95 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,103 +1,26 @@
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:
check-bump:

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
- uses: actions/checkout@v4
with:
repository: lseman/gitAPy
- name: Set up Python 3.11
uses: actions/setup-python@v4
with:
python-version: 3.11
# You can test your matrix by printing the current Python version
- name: Run gitAPy
run: |
ls
export API_URL="https://api.github.com"
export TOKEN=${{ secrets.GITHUB_TOKEN }}
export API_VERSION="2022-11-28"
pip install -r requirements.txt
python gitapy.py cachy

0 comments on commit f346157

Please sign in to comment.