-
Notifications
You must be signed in to change notification settings - Fork 5
137 lines (113 loc) · 4.13 KB
/
ci-patchwork-trigger.yml
File metadata and controls
137 lines (113 loc) · 4.13 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
# SPDX-License-Identifier: GPL-2.0-or-later
# Copyright (c) 2026 Andrea Cervesato <andrea.cervesato@suse.com>
#
# Poll Patchwork for new LTP patch series and dispatch a review
# workflow for each one that has not been reviewed yet.
name: "Patchwork review trigger"
on:
workflow_dispatch:
schedule:
- cron: '0 * * * *'
permissions:
actions: write
contents: read
env:
PATCHWORK_URL: https://patchwork.ozlabs.org
# Fallback lookback in seconds when no previous successful run exists
PATCHWORK_SINCE: 4500
# Maximum lookback in seconds (24h) to avoid flooding the API
PATCHWORK_MAX_SINCE: 86400
jobs:
check:
runs-on: ubuntu-latest
steps:
- name: Install pwclient
run: |
pip install 'pwclient @ git+https://github.com/getpatchwork/pwclient'
mkdir -p ~/.config
cat > ~/.pwclientrc <<EOF
[options]
default = ltp
[ltp]
backend = rest
url = $PATCHWORK_URL/api/
EOF
- name: Get last successful run timestamp
id: last_run
uses: actions/github-script@v7
with:
script: |
const runs = await github.rest.actions.listWorkflowRuns({
owner: context.repo.owner,
repo: context.repo.repo,
workflow_id: 'ci-patchwork-trigger.yml',
status: 'success',
per_page: 1,
exclude_pull_requests: true,
});
if (runs.data.workflow_runs.length > 0) {
const since = runs.data.workflow_runs[0].run_started_at;
console.log(`Last successful run: ${since}`);
core.exportVariable('PATCHWORK_SINCE_DATE', since);
} else {
console.log('No previous successful run found, using default lookback');
}
- name: Fetch new series from Patchwork
id: fetch
run: |
current_time=$(date +%s)
if [ -n "$PATCHWORK_SINCE_DATE" ]; then
since_time=$(date -u -d "$PATCHWORK_SINCE_DATE" +%s)
max_since_time=$((current_time - PATCHWORK_MAX_SINCE))
if [ "$since_time" -lt "$max_since_time" ]; then
since_time=$max_since_time
fi
else
since_time=$((current_time - PATCHWORK_SINCE))
fi
since=$(date -u -d @$since_time +"%Y-%m-%dT%H:%M:%SZ")
pwclient event-list -p ltp -c series-completed \
--since "$since" -f '%{series_id}' > series.txt
cat series.txt
- name: Filter already-reviewed series
id: filter
run: |
touch dispatch.txt
while read -r series_id; do
[ -z "$series_id" ] && continue
patch_ids=$(pwclient list -p ltp -S "$series_id" -f '%{id}')
reviewed=false
for patch_id in $patch_ids; do
context=$(pwclient check-get -p ltp "$patch_id" -f '%{context}' 2>/dev/null || true)
if echo "$context" | grep -q "copilot-review"; then
reviewed=true
break
fi
done
if [ "$reviewed" = false ]; then
echo "$series_id" >> dispatch.txt
fi
done < series.txt
echo "count=$(wc -l < dispatch.txt | tr -d ' ')" >> "$GITHUB_OUTPUT"
cat dispatch.txt
- name: Dispatch review workflows
if: steps.filter.outputs.count != '0'
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const lines = fs.readFileSync('dispatch.txt', 'utf8').trim().split('\n');
for (const line of lines) {
const series_id = line.trim();
if (!series_id) continue;
console.log(`Dispatching review for series ${series_id}`);
await github.rest.actions.createWorkflowDispatch({
owner: context.repo.owner,
repo: context.repo.repo,
ref: context.ref,
workflow_id: 'ci-copilot-review.yml',
inputs: {
SERIES_ID: series_id,
}
});
}