Skip to content

Upstream Async-Profiler Change Tracker #23

Upstream Async-Profiler Change Tracker

Upstream Async-Profiler Change Tracker #23

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