|
| 1 | +name: Check Upstream Updates |
| 2 | + |
| 3 | +on: |
| 4 | + schedule: |
| 5 | + - cron: '0 */6 * * *' # Every 6 hours |
| 6 | + workflow_dispatch: |
| 7 | + inputs: |
| 8 | + package_filter: |
| 9 | + description: 'Package name filter (regex)' |
| 10 | + type: string |
| 11 | + default: '' |
| 12 | + dry_run: |
| 13 | + description: 'Dry run (no PRs created)' |
| 14 | + type: boolean |
| 15 | + default: false |
| 16 | + |
| 17 | +concurrency: |
| 18 | + group: update-checker |
| 19 | + cancel-in-progress: true |
| 20 | + |
| 21 | +jobs: |
| 22 | + check-updates: |
| 23 | + runs-on: ubuntu-latest |
| 24 | + permissions: |
| 25 | + contents: write |
| 26 | + pull-requests: write |
| 27 | + steps: |
| 28 | + - name: Checkout repository |
| 29 | + uses: actions/checkout@v4 |
| 30 | + with: |
| 31 | + fetch-depth: 0 |
| 32 | + |
| 33 | + - name: Download sbuild-meta |
| 34 | + run: | |
| 35 | + curl -fsSL "https://github.com/pkgforge/sbuilder/releases/download/latest/sbuild-meta-x86_64-linux" \ |
| 36 | + -o /usr/local/bin/sbuild-meta || { |
| 37 | + echo "::warning::Failed to download sbuild-meta, skipping update check" |
| 38 | + exit 0 |
| 39 | + } |
| 40 | + chmod +x /usr/local/bin/sbuild-meta |
| 41 | + sbuild-meta --version |
| 42 | +
|
| 43 | + - name: Check for upstream updates |
| 44 | + id: check |
| 45 | + run: | |
| 46 | + sbuild-meta check-updates \ |
| 47 | + --recipes ./binaries ./packages \ |
| 48 | + --output /tmp/updates.json \ |
| 49 | + --parallel 10 \ |
| 50 | + --timeout 30 |
| 51 | +
|
| 52 | + # Count updates |
| 53 | + if [ -f /tmp/updates.json ]; then |
| 54 | + UPDATE_COUNT=$(jq 'length' /tmp/updates.json) |
| 55 | + else |
| 56 | + UPDATE_COUNT=0 |
| 57 | + fi |
| 58 | + echo "update_count=${UPDATE_COUNT}" >> $GITHUB_OUTPUT |
| 59 | +
|
| 60 | + if [ "$UPDATE_COUNT" -gt 0 ]; then |
| 61 | + echo "::notice::Found ${UPDATE_COUNT} packages with upstream updates" |
| 62 | + jq -r '.[] | "\(.pkg): \(.current_version) -> \(.upstream_version)"' /tmp/updates.json |
| 63 | + else |
| 64 | + echo "::notice::No updates found" |
| 65 | + fi |
| 66 | +
|
| 67 | + - name: Create update PRs |
| 68 | + if: steps.check.outputs.update_count > 0 && inputs.dry_run != true |
| 69 | + env: |
| 70 | + GH_TOKEN: ${{ github.token }} |
| 71 | + run: | |
| 72 | + git config user.name "github-actions[bot]" |
| 73 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 74 | +
|
| 75 | + jq -c '.[]' /tmp/updates.json | while read -r pkg_data; do |
| 76 | + pkg_name=$(echo "$pkg_data" | jq -r '.pkg') |
| 77 | + pkg_id=$(echo "$pkg_data" | jq -r '.pkg_id') |
| 78 | + recipe_path=$(echo "$pkg_data" | jq -r '.recipe_path') |
| 79 | + old_ver=$(echo "$pkg_data" | jq -r '.current_version') |
| 80 | + new_ver=$(echo "$pkg_data" | jq -r '.upstream_version') |
| 81 | +
|
| 82 | + # Sanitize version for branch name |
| 83 | + safe_ver=$(echo "$new_ver" | tr -cs '[:alnum:].-' '-' | sed 's/-$//') |
| 84 | + branch="bot/update-${pkg_name}-${safe_ver}" |
| 85 | +
|
| 86 | + # Check if PR already exists |
| 87 | + if gh pr list --head "$branch" --json number | jq -e 'length > 0' > /dev/null 2>&1; then |
| 88 | + echo "::notice::PR already exists for $pkg_name $new_ver, skipping" |
| 89 | + continue |
| 90 | + fi |
| 91 | +
|
| 92 | + # Check if branch exists remotely |
| 93 | + if git ls-remote --heads origin "$branch" | grep -q "$branch"; then |
| 94 | + echo "::notice::Branch $branch already exists, skipping" |
| 95 | + continue |
| 96 | + fi |
| 97 | +
|
| 98 | + echo "::group::Creating PR for $pkg_name" |
| 99 | +
|
| 100 | + # Create branch from main |
| 101 | + git checkout main |
| 102 | + git pull origin main |
| 103 | + git checkout -b "$branch" |
| 104 | +
|
| 105 | + # Update version in recipe |
| 106 | + if [ -f "$recipe_path" ]; then |
| 107 | + # Check if version field exists |
| 108 | + if grep -q "^version:" "$recipe_path"; then |
| 109 | + # Update existing version |
| 110 | + sed -i "s/^version:.*/version: \"${new_ver}\"/" "$recipe_path" |
| 111 | + else |
| 112 | + # Add version field after pkg_id |
| 113 | + sed -i "/^pkg_id:/a version: \"${new_ver}\"" "$recipe_path" |
| 114 | + fi |
| 115 | +
|
| 116 | + git add "$recipe_path" |
| 117 | + git commit -m "chore(bot): update ${pkg_name} to ${new_ver} |
| 118 | +
|
| 119 | +Automated update detected via pkgver script. |
| 120 | + |
| 121 | +- Package: ${pkg_name} |
| 122 | +- Previous: ${old_ver} |
| 123 | +- Updated: ${new_ver}" |
| 124 | + |
| 125 | + git push origin "$branch" |
| 126 | + |
| 127 | + gh pr create \ |
| 128 | + --title "[bot] Update ${pkg_name}: ${old_ver} -> ${new_ver}" \ |
| 129 | + --body "## Automated Update |
| 130 | + |
| 131 | +This PR updates **${pkg_name}** to version **${new_ver}**. |
| 132 | + |
| 133 | +| Field | Value | |
| 134 | +|-------|-------| |
| 135 | +| Package | \`${pkg_name}\` | |
| 136 | +| Package ID | \`${pkg_id}\` | |
| 137 | +| Previous Version | \`${old_ver}\` | |
| 138 | +| New Version | \`${new_ver}\` | |
| 139 | +| Recipe | \`${recipe_path}\` | |
| 140 | + |
| 141 | +### What to do |
| 142 | + |
| 143 | +1. Review the changes |
| 144 | +2. Merge if the update looks correct |
| 145 | +3. The build will be triggered automatically |
| 146 | + |
| 147 | +--- |
| 148 | +*This PR was created automatically by the update checker bot.*" \ |
| 149 | + --label "bot,update" \ |
| 150 | + --head "$branch" \ |
| 151 | + --base main |
| 152 | + |
| 153 | + echo "::notice::Created PR for $pkg_name" |
| 154 | + else |
| 155 | + echo "::warning::Recipe file not found: $recipe_path" |
| 156 | + fi |
| 157 | + |
| 158 | + echo "::endgroup::" |
| 159 | + |
| 160 | + # Return to main for next iteration |
| 161 | + git checkout main |
| 162 | + |
| 163 | + # Rate limiting - avoid hitting GitHub API limits |
| 164 | + sleep 2 |
| 165 | + done |
| 166 | + |
| 167 | + - name: Upload updates report |
| 168 | + if: always() && steps.check.outputs.update_count > 0 |
| 169 | + uses: actions/upload-artifact@v4 |
| 170 | + with: |
| 171 | + name: updates-report |
| 172 | + path: /tmp/updates.json |
| 173 | + retention-days: 7 |
0 commit comments