-
Notifications
You must be signed in to change notification settings - Fork 1
141 lines (119 loc) · 4.38 KB
/
Copy pathmonitor-upstream.yml
File metadata and controls
141 lines (119 loc) · 4.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
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" 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"
# 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.
.SRCINFO will be generated by build-and-publish 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