From d942967633b194ff2e9fbff25b5b210411b23c3a Mon Sep 17 00:00:00 2001 From: ook37 Date: Wed, 8 Jan 2025 15:56:58 -0500 Subject: [PATCH] chore: build package updates --- .github/workflows/nushell-bin.yml | 3 +- .github/workflows/pacstall.yml | 3 +- .github/workflows/trigger.yml | 31 +++++++++++++++++++++ .github/workflows/watchdog.yml | 46 +++++++++++++++++++++++++++++++ manager.py | 5 +++- scripts/checker.sh | 43 +++++++++++++++++++++++++++++ updates.json | 1 + 7 files changed, 129 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/trigger.yml create mode 100644 .github/workflows/watchdog.yml create mode 100755 scripts/checker.sh create mode 100644 updates.json diff --git a/.github/workflows/nushell-bin.yml b/.github/workflows/nushell-bin.yml index 8fa1723..fe01a26 100644 --- a/.github/workflows/nushell-bin.yml +++ b/.github/workflows/nushell-bin.yml @@ -1,6 +1,7 @@ name: nushell-bin 'on': -- workflow_dispatch + workflow_call: {} + workflow_dispatch: {} jobs: build: runs-on: ubuntu-latest diff --git a/.github/workflows/pacstall.yml b/.github/workflows/pacstall.yml index 3758f29..76abf46 100644 --- a/.github/workflows/pacstall.yml +++ b/.github/workflows/pacstall.yml @@ -1,6 +1,7 @@ name: pacstall 'on': -- workflow_dispatch + workflow_call: {} + workflow_dispatch: {} jobs: build: runs-on: ubuntu-latest diff --git a/.github/workflows/trigger.yml b/.github/workflows/trigger.yml new file mode 100644 index 0000000..a904f3e --- /dev/null +++ b/.github/workflows/trigger.yml @@ -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 diff --git a/.github/workflows/watchdog.yml b/.github/workflows/watchdog.yml new file mode 100644 index 0000000..db92bec --- /dev/null +++ b/.github/workflows/watchdog.yml @@ -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 diff --git a/manager.py b/manager.py index 5c53064..b0f6571 100755 --- a/manager.py +++ b/manager.py @@ -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", diff --git a/scripts/checker.sh b/scripts/checker.sh new file mode 100755 index 0000000..adbf68b --- /dev/null +++ b/scripts/checker.sh @@ -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 . + +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}" diff --git a/updates.json b/updates.json new file mode 100644 index 0000000..0967ef4 --- /dev/null +++ b/updates.json @@ -0,0 +1 @@ +{}