Skip to content

Commit

Permalink
chore: build package updates
Browse files Browse the repository at this point in the history
  • Loading branch information
ook37 committed Jan 8, 2025
1 parent 2f4d8a7 commit d942967
Show file tree
Hide file tree
Showing 7 changed files with 129 additions and 3 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/nushell-bin.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name: nushell-bin
'on':
- workflow_dispatch
workflow_call: {}
workflow_dispatch: {}
jobs:
build:
runs-on: ubuntu-latest
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/pacstall.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name: pacstall
'on':
- workflow_dispatch
workflow_call: {}
workflow_dispatch: {}
jobs:
build:
runs-on: ubuntu-latest
Expand Down
31 changes: 31 additions & 0 deletions .github/workflows/trigger.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Trigger Workflows

on:
workflow_dispatch:
push:
branches:
- master

jobs:
parse-log:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Get Commit Description
id: get-commit-info
run: |
updates_matrix="$(git log -1 --pretty=%b | awk '/^Update/,0 { if ($0 ~ /^ /) { sub(/:$/, "", $1); print $1 } }' | jq -R -s -c 'split("\n") | map(select(. != ""))')"
echo "updated='${updates_matrix}'" >> $GITHUB_ENV
trigger-actions:
needs: parse-log
if: env.updated != '[]'
runs-on: ubuntu-latest
strategy:
matrix:
package: ${{ fromJson(env.updated) }}
steps:
- name: Build Package
uses: .github/workflows/${{ matrix.package }}.yml
46 changes: 46 additions & 0 deletions .github/workflows/watchdog.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Watchdog

permissions:
contents: write
pull-requests: write

on:
schedule:
- cron: "0 */3 * * *"
workflow_dispatch:

jobs:
update-check:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
ref: master

- name: Check for updates from API
id: update-json
run: |
needed=0
updates="$(./scripts/checker.sh packages.json updates.json)"
if [[ "${updates}" == "No PPR updates found." ]]; then
echo "No PPR updates found."
echo "needed=0" >> $GITHUB_ENV
exit 0
else
echo "needed=1" >> $GITHUB_ENV
echo "pr_body='${updates}'" >> $GITHUB_ENV
fi
- name: Create Pull Request
if: env.needed == '1'
uses: peter-evans/create-pull-request@v7
with:
token: ${{ secrets.GITHUB_TOKEN }}
add-paths: updates.json
base: master
branch: watchdog
title: "Bump timestamps from API"
body: "${{ env.pr_body }}"
update-branch: true
5 changes: 4 additions & 1 deletion manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,10 @@ class LiteralString(str): pass

workflow_template = {
"name": f"{package_name}",
"on": ["workflow_dispatch"],
"on": {
"workflow_call": {},
"workflow_dispatch": {}
},
"jobs": {
"build": {
"runs-on": "ubuntu-latest",
Expand Down
43 changes: 43 additions & 0 deletions scripts/checker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/usr/bin/env bash
# ____ __ ____
# / __ \____ ___________/ /_____ _/ / /
# / /_/ / __ `/ ___/ ___/ __/ __ `/ / /
# / ____/ /_/ / /__(__ ) /_/ /_/ / / /
# /_/ \__,_/\___/____/\__/\__,_/_/_/
#
# Copyright (C) 2020-present
#
# This file is part of Pacstall
#
# Pacstall is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, version 3 of the License
#
# Pacstall is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Pacstall. If not, see <https://www.gnu.org/licenses/>.

function check_updates() {
local pkgfile="${1}" updfile="${2}" packages details updated stored
mapfile -t packages < <(jq -r 'keys[]' "${pkgfile}")
for i in "${packages[@]}"; do
updated="$(curl -fsSL https://pacstall.dev/api/packages/${i} | jq -r '.lastUpdatedAt')"
stored="$(jq -r --arg pkg ${i} '.[$pkg] // "1970-01-01T00:00:00Z"' ${updfile})"
if [[ "${updated}" > "${stored}" ]]; then
jq --arg pkg "${i}" --arg time "${updated}" '.[$pkg] = $time' "${updfile}" > tmp.json && mv tmp.json "${updfile}"
details+=("${i}: ${stored} -> ${updated}")
fi
done
if [[ -z ${details[*]} ]]; then
echo "No PPR updates found."
else
echo -e "### Auto-generated by CI. DO NOT EDIT ###\nUpdate $(date -u +"%Y-%m-%dT%H:%M:%SZ"):"
printf ' %s\n' "${details[@]}"
fi
}

check_updates "${1}" "${2}"
1 change: 1 addition & 0 deletions updates.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}

0 comments on commit d942967

Please sign in to comment.