Monitor Upstream Releases #10
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Monitor Upstream Releases | |
| on: | |
| schedule: | |
| # Run daily at 00:00 UTC | |
| - cron: '0 0 * * *' | |
| workflow_dispatch: | |
| inputs: | |
| package: | |
| description: 'Specific package to check (leave empty for all)' | |
| required: false | |
| type: string | |
| force: | |
| description: 'Force update even if version unchanged' | |
| required: false | |
| type: boolean | |
| default: false | |
| permissions: | |
| contents: write | |
| jobs: | |
| detect-updates: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Configure Git | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| - name: Install dependencies | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y curl jq | |
| - name: Discover packages | |
| id: discover | |
| run: | | |
| if [[ -n "${{ github.event.inputs.package }}" ]]; then | |
| echo "packages=${{ github.event.inputs.package }}" >> "${GITHUB_OUTPUT}" | |
| else | |
| packages=$(find pkgs -mindepth 1 -maxdepth 1 -type d -exec basename {} \; | sort | jq -R -s -c 'split("\n")[:-1]') | |
| echo "packages=${packages}" >> "${GITHUB_OUTPUT}" | |
| fi | |
| - name: Check for updates | |
| run: | | |
| set -euo pipefail | |
| packages='${{ steps.discover.outputs.packages }}' | |
| force_flag="" | |
| if [[ "${{ github.event.inputs.force }}" == "true" ]]; then | |
| force_flag="--force" | |
| fi | |
| updated_packages=() | |
| if [[ "${packages}" == *"["* ]]; then | |
| # JSON array from discovery | |
| for pkg in $(echo "${packages}" | jq -r '.[]'); do | |
| echo "Checking ${pkg}..." | |
| if scripts/update-package.sh "${pkg}" ${force_flag}; then | |
| if git diff --quiet "pkgs/${pkg}/PKGBUILD" "pkgs/${pkg}/.SRCINFO" 2>/dev/null; then | |
| echo "No changes detected for ${pkg}" | |
| else | |
| echo "Updates detected for ${pkg}" | |
| updated_packages+=("${pkg}") | |
| fi | |
| else | |
| echo "Failed to check ${pkg}" >&2 | |
| fi | |
| done | |
| else | |
| # Single package from manual input | |
| pkg="${packages}" | |
| echo "Checking ${pkg}..." | |
| if scripts/update-package.sh "${pkg}" ${force_flag}; then | |
| if git diff --quiet "pkgs/${pkg}/PKGBUILD" "pkgs/${pkg}/.SRCINFO" 2>/dev/null; then | |
| echo "No changes detected for ${pkg}" | |
| else | |
| echo "Updates detected for ${pkg}" | |
| updated_packages+=("${pkg}") | |
| fi | |
| else | |
| echo "Failed to check ${pkg}" >&2 | |
| exit 1 | |
| fi | |
| fi | |
| if [[ ${#updated_packages[@]} -eq 0 ]]; then | |
| echo "No package updates to commit" | |
| exit 0 | |
| fi | |
| # Regenerate README with updated package versions | |
| echo "Regenerating README files..." | |
| bash scripts/build-readme.sh | |
| # Commit updates | |
| for pkg in "${updated_packages[@]}"; do | |
| git add "pkgs/${pkg}/PKGBUILD" "pkgs/${pkg}/.SRCINFO" | |
| # Extract version from PKGBUILD | |
| new_version=$(awk -F'= *' '$1=="pkgver"{print $2; exit}' "pkgs/${pkg}/PKGBUILD") | |
| # Commit package updates and README | |
| git add README.md README.zh.md docs/readme.en.md 2>/dev/null || true | |
| git commit -m "ci: update ${pkg} to ${new_version} | |
| Automated upstream version detection via monitor-upstream workflow. | |
| Co-Authored-By: github-actions[bot] <github-actions[bot]@users.noreply.github.com>" | |
| done | |
| # Pull before push to avoid conflicts | |
| git pull --rebase origin main || { | |
| echo "Failed to rebase, attempting merge" >&2 | |
| git rebase --abort | |
| git pull --no-rebase origin main | |
| } | |
| git push origin main | |
| echo "Successfully committed updates for: ${updated_packages[*]}" | |
| - name: Upload logs | |
| if: always() | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: monitor-logs-${{ github.run_id }} | |
| path: | | |
| *.log | |
| retention-days: 30 | |
| if-no-files-found: ignore |