-
Notifications
You must be signed in to change notification settings - Fork 12
161 lines (138 loc) · 5.56 KB
/
upstream-tracker.yml
File metadata and controls
161 lines (138 loc) · 5.56 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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
name: Upstream Async-Profiler Change Tracker
on:
schedule:
- cron: '0 3 * * *' # Daily at 3 AM UTC
workflow_dispatch:
inputs:
force_report:
description: 'Generate report even if no changes detected'
type: boolean
default: false
permissions:
contents: write
issues: write
jobs:
track-upstream:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Setup git
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
- name: Clone upstream async-profiler
id: clone-upstream
continue-on-error: true
run: |
git clone --depth 50 https://github.com/async-profiler/async-profiler.git /tmp/async-profiler
cd /tmp/async-profiler
git fetch origin master
UPSTREAM_HEAD=$(git rev-parse origin/master)
echo "UPSTREAM_HEAD=${UPSTREAM_HEAD}" >> $GITHUB_ENV
echo "Upstream HEAD: ${UPSTREAM_HEAD}"
- name: Handle clone failure
if: steps.clone-upstream.outcome == 'failure'
run: |
echo "::warning::Failed to clone upstream repository. Will retry on next run."
exit 0
- name: Get last checked commit
if: steps.clone-upstream.outcome == 'success'
id: get-last-commit
run: |
# Try to get the last commit from gh-pages branch
STATE_FILE="upstream-tracker-state.txt"
# Fetch gh-pages branch
if git fetch origin gh-pages:gh-pages 2>/dev/null; then
# Check if state file exists in gh-pages
if git show gh-pages:"$STATE_FILE" 2>/dev/null > /tmp/state.txt; then
LAST_COMMIT=$(cat /tmp/state.txt | tr -d '[:space:]')
# Validate that LAST_COMMIT is a valid commit SHA (40 hex characters)
if ! echo "$LAST_COMMIT" | grep -qE '^[0-9a-f]{40}$'; then
echo "Invalid commit SHA in state file: ${LAST_COMMIT}"
echo "First run detected, using current HEAD as baseline"
LAST_COMMIT="${UPSTREAM_HEAD}"
else
echo "Last checked commit from gh-pages: ${LAST_COMMIT}"
fi
else
echo "No state file in gh-pages, first run detected"
LAST_COMMIT="${UPSTREAM_HEAD}"
fi
else
echo "gh-pages branch not found, first run detected"
LAST_COMMIT="${UPSTREAM_HEAD}"
fi
echo "last_commit=${LAST_COMMIT}" >> $GITHUB_OUTPUT
echo "Last checked commit: ${LAST_COMMIT}"
- name: Generate tracked files list
if: steps.clone-upstream.outcome == 'success'
id: tracked-files
run: |
./utils/generate_tracked_files.sh \
ddprof-lib/src/main/cpp \
/tmp/async-profiler/src \
> /tmp/tracked_files.txt
echo "Tracking $(wc -l < /tmp/tracked_files.txt) files"
cat /tmp/tracked_files.txt
- name: Track upstream changes
if: steps.clone-upstream.outcome == 'success'
id: track-changes
run: |
./utils/track_upstream_changes.sh \
/tmp/async-profiler \
"${{ steps.get-last-commit.outputs.last_commit }}" \
"${{ env.UPSTREAM_HEAD }}" \
/tmp/tracked_files.txt \
/tmp/change_report.md \
/tmp/change_report.json
if [ -f /tmp/change_report.json ]; then
echo "has_changes=true" >> $GITHUB_OUTPUT
echo "Changes detected!"
else
echo "has_changes=false" >> $GITHUB_OUTPUT
echo "No changes detected"
fi
- name: Create GitHub Issue
if: steps.track-changes.outputs.has_changes == 'true' && steps.clone-upstream.outcome == 'success'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# Verify report file exists before creating issue
if [ ! -f /tmp/change_report.md ]; then
echo "Error: Report file not found, skipping issue creation"
exit 0
fi
ISSUE_TITLE="Upstream async-profiler changes detected ($(date +%Y-%m-%d))"
gh issue create \
--title "$ISSUE_TITLE" \
--body-file /tmp/change_report.md \
--label "upstream-tracking,needs-review" \
--repo ${{ github.repository }}
- name: Update last checked commit
if: success() && steps.clone-upstream.outcome == 'success'
run: |
# Update state file in gh-pages branch
STATE_FILE="upstream-tracker-state.txt"
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
# Fetch or create gh-pages branch
if git fetch origin gh-pages:gh-pages 2>/dev/null; then
git checkout gh-pages
else
echo "Creating new gh-pages branch"
git checkout --orphan gh-pages
git rm -rf . 2>/dev/null || true
fi
# Update state file
echo "${UPSTREAM_HEAD}" > "$STATE_FILE"
git add "$STATE_FILE"
if git diff --staged --quiet; then
echo "No changes to state file"
else
git commit -m "Update upstream tracker state to ${UPSTREAM_HEAD:0:7}"
git push origin gh-pages
echo "Updated last checked commit to ${UPSTREAM_HEAD}"
fi
# Return to main branch
git checkout main