Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: build package updates #11

Merged
merged 3 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .github/workflows/nushell-bin.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
name: nushell-bin
'on':
- workflow_dispatch
repository_dispatch:
types:
- nushell-bin
workflow_dispatch: {}
jobs:
build:
runs-on: ubuntu-latest
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/pacstall.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
name: pacstall
'on':
- workflow_dispatch
repository_dispatch:
types:
- pacstall
workflow_dispatch: {}
jobs:
build:
runs-on: ubuntu-latest
Expand Down
32 changes: 32 additions & 0 deletions .github/workflows/trigger.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Trigger Workflows

on:
workflow_dispatch:
push:
branches:
- master

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

- name: Build Matrix
id: parse-log
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
echo "${updates_matrix}"

- name: Trigger Workflows
if: env.updated != '[]'
run: |
for package in $(echo ${{ env.updated }} | jq -r '.[]'); do
curl -X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
-d "{\"event_type\": \"${package}\"}" \
https://api.github.com/repos/${{ github.repository }}/dispatches
done
48 changes: 48 additions & 0 deletions .github/workflows/watchdog.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Watchdog

permissions:
contents: write
pull-requests: write

on:
schedule:
- cron: "0 */6 * * *"
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<<EOF" >> $GITHUB_ENV
echo "${updates}" >> $GITHUB_ENV
echo "EOF" >> $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
9 changes: 8 additions & 1 deletion manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,14 @@ class LiteralString(str): pass

workflow_template = {
"name": f"{package_name}",
"on": ["workflow_dispatch"],
"on": {
"repository_dispatch": {
"types": [
f"{package_name}"
]
},
"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 @@
{}