diff --git a/.github/workflows/nushell-bin.yml b/.github/workflows/nushell-bin.yml index 8fa1723..4230daf 100644 --- a/.github/workflows/nushell-bin.yml +++ b/.github/workflows/nushell-bin.yml @@ -1,6 +1,9 @@ name: nushell-bin 'on': -- workflow_dispatch + repository_dispatch: + types: + - nushell-bin + workflow_dispatch: {} jobs: build: runs-on: ubuntu-latest diff --git a/.github/workflows/pacstall.yml b/.github/workflows/pacstall.yml index 3758f29..6be8d8c 100644 --- a/.github/workflows/pacstall.yml +++ b/.github/workflows/pacstall.yml @@ -1,6 +1,9 @@ name: pacstall 'on': -- workflow_dispatch + repository_dispatch: + types: + - pacstall + 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..19b23ae --- /dev/null +++ b/.github/workflows/trigger.yml @@ -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 diff --git a/.github/workflows/watchdog.yml b/.github/workflows/watchdog.yml new file mode 100644 index 0000000..891a67e --- /dev/null +++ b/.github/workflows/watchdog.yml @@ -0,0 +1,48 @@ +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<> $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 diff --git a/manager.py b/manager.py index 5c53064..d12a793 100755 --- a/manager.py +++ b/manager.py @@ -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", 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 @@ +{}