Skip to content

Commit ae0aa16

Browse files
Fixed job and extracted script from job (to make it easier to test)
1 parent 576d280 commit ae0aa16

File tree

2 files changed

+96
-65
lines changed

2 files changed

+96
-65
lines changed

.github/workflows/watch-upstream.yml

Lines changed: 4 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -22,73 +22,12 @@ jobs:
2222
path: tools/assembly-store-reader-mk2
2323
local_path: src/Sentry.Android.AssemblyReader/
2424
steps:
25+
- uses: actions/checkout@v4
26+
2527
- name: Check for upstream changes
2628
env:
2729
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
30+
GH_REPO: ${{ github.repository }}
2831
shell: bash
2932
run: |
30-
set -euo pipefail
31-
32-
UPSTREAM_REPO="${{ matrix.repo }}"
33-
UPSTREAM_PATH="${{ matrix.path }}"
34-
LOCAL_PATH="${{ matrix.local_path }}"
35-
UPSTREAM_URL="https://github.com/${UPSTREAM_REPO}/tree/main/${UPSTREAM_PATH}"
36-
37-
echo "Checking upstream: $UPSTREAM_REPO/$UPSTREAM_PATH"
38-
39-
# Get the latest commit SHA affecting the tracked path.
40-
LATEST_SHA=$(gh api "repos/${UPSTREAM_REPO}/commits?path=${UPSTREAM_PATH}&per_page=1" \
41-
--jq '.[0].sha')
42-
LATEST_SHORT="${LATEST_SHA:0:7}"
43-
echo "Latest upstream commit: $LATEST_SHA ($LATEST_SHORT)"
44-
45-
# Avoid creating duplicate issues: skip if any issue (open or closed) already
46-
# tracks this exact upstream commit SHA. The SHA in the title makes it unique.
47-
ISSUE_LABEL="upstream-watch"
48-
EXISTING_ISSUE=$(gh issue list \
49-
--label "$ISSUE_LABEL" \
50-
--state all \
51-
--search "\"${UPSTREAM_REPO} ${UPSTREAM_PATH} @ ${LATEST_SHORT}\"" \
52-
--json number,title \
53-
--jq '.[0].number // empty')
54-
55-
if [ -n "$EXISTING_ISSUE" ]; then
56-
echo "An issue (#${EXISTING_ISSUE}) already tracks upstream commit ${LATEST_SHORT} for ${UPSTREAM_REPO}/${UPSTREAM_PATH}. Skipping."
57-
exit 0
58-
fi
59-
60-
echo "No existing issue found for commit ${LATEST_SHORT}. Creating one..."
61-
62-
# Ensure the label exists (idempotent).
63-
gh label create "$ISSUE_LABEL" \
64-
--description "Upstream vendored code has changed — review required" \
65-
--color "E4E669" 2>/dev/null || true
66-
67-
COMMIT_URL="https://github.com/${UPSTREAM_REPO}/commit/${LATEST_SHA}"
68-
HISTORY_URL="https://github.com/${UPSTREAM_REPO}/commits/main/${UPSTREAM_PATH}"
69-
70-
gh issue create \
71-
--title "Upstream change detected: ${UPSTREAM_REPO} ${UPSTREAM_PATH} @ ${LATEST_SHORT}" \
72-
--label "$ISSUE_LABEL" \
73-
--body "## Upstream Change Detected
74-
75-
The code at [\`${UPSTREAM_REPO}/${UPSTREAM_PATH}\`](${UPSTREAM_URL}) has a new commit since our last review.
76-
77-
| | |
78-
|---|---|
79-
| **Latest commit** | [\`${LATEST_SHORT}\`](${COMMIT_URL}) |
80-
| **Path history** | [View history](${HISTORY_URL}) |
81-
82-
Our vendored copy lives in \`${LOCAL_PATH}\`. We modified the upstream code significantly,
83-
so a direct merge is unlikely to be appropriate — but the commit above may reveal logic
84-
changes worth porting.
85-
86-
### What to do
87-
88-
1. Review the [upstream commit](${COMMIT_URL}) and [path history](${HISTORY_URL}).
89-
2. If no action is needed, close this issue with a note explaining why.
90-
3. If changes should be ported, create a follow-up task and close this issue once the work is tracked.
91-
92-
> _Automatically opened by the [Watch Upstream Changes](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) workflow._"
93-
94-
echo "Issue created successfully."
33+
scripts/watch-upstream.sh "${{ matrix.repo }}" "${{ matrix.path }}" "${{ matrix.local_path }}"

scripts/watch-upstream.sh

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
#!/usr/bin/env bash
2+
# Usage: watch-upstream.sh <upstream-repo> <upstream-path> <local-path>
3+
#
4+
# Checks whether the given path in an upstream GitHub repo has a new commit
5+
# since the last time we created a tracking issue. If so, opens a GitHub issue
6+
# in this repo (identified by GH_REPO or inferred by gh from git context).
7+
#
8+
# Required env vars:
9+
# GH_TOKEN — GitHub token (set automatically in Actions; use `gh auth token` locally)
10+
#
11+
# Optional env vars (set automatically in GitHub Actions):
12+
# GH_REPO — target repo for issue creation, e.g. getsentry/sentry-dotnet
13+
# GITHUB_SERVER_URL — e.g. https://github.com (defaults to https://github.com)
14+
# GITHUB_RUN_ID — included in the issue footer when present
15+
16+
set -euo pipefail
17+
18+
if [ $# -ne 3 ]; then
19+
echo "Usage: $0 <upstream-repo> <upstream-path> <local-path>" >&2
20+
exit 1
21+
fi
22+
23+
UPSTREAM_REPO="$1"
24+
UPSTREAM_PATH="$2"
25+
LOCAL_PATH="$3"
26+
UPSTREAM_URL="https://github.com/${UPSTREAM_REPO}/tree/main/${UPSTREAM_PATH}"
27+
GITHUB_SERVER_URL="${GITHUB_SERVER_URL:-https://github.com}"
28+
29+
echo "Checking upstream: ${UPSTREAM_REPO}/${UPSTREAM_PATH}"
30+
31+
# Get the latest commit SHA affecting the tracked path.
32+
LATEST_SHA=$(gh api "repos/${UPSTREAM_REPO}/commits?path=${UPSTREAM_PATH}&per_page=1" \
33+
--jq '.[0].sha')
34+
LATEST_SHORT="${LATEST_SHA:0:7}"
35+
echo "Latest upstream commit: ${LATEST_SHA} (${LATEST_SHORT})"
36+
37+
# Avoid creating duplicate issues: skip if any issue (open or closed) already
38+
# tracks this exact upstream commit SHA. The SHA in the title makes it unique.
39+
ISSUE_LABEL="upstream-watch"
40+
EXISTING_ISSUE=$(gh issue list \
41+
--label "$ISSUE_LABEL" \
42+
--state all \
43+
--search "\"${UPSTREAM_REPO} ${UPSTREAM_PATH} @ ${LATEST_SHORT}\"" \
44+
--json number,title \
45+
--jq '.[0].number // empty')
46+
47+
if [ -n "$EXISTING_ISSUE" ]; then
48+
echo "An issue (#${EXISTING_ISSUE}) already tracks upstream commit ${LATEST_SHORT} for ${UPSTREAM_REPO}/${UPSTREAM_PATH}. Skipping."
49+
exit 0
50+
fi
51+
52+
echo "No existing issue found for commit ${LATEST_SHORT}. Creating one..."
53+
54+
# Ensure the label exists (idempotent).
55+
gh label create "$ISSUE_LABEL" \
56+
--description "Upstream vendored code has changed — review required" \
57+
--color "E4E669" 2>/dev/null || true
58+
59+
COMMIT_URL="https://github.com/${UPSTREAM_REPO}/commit/${LATEST_SHA}"
60+
HISTORY_URL="https://github.com/${UPSTREAM_REPO}/commits/main/${UPSTREAM_PATH}"
61+
62+
if [ -n "${GITHUB_RUN_ID:-}" ] && [ -n "${GITHUB_REPOSITORY:-}" ]; then
63+
FOOTER="> _Automatically opened by the [Watch Upstream Changes](${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}) workflow._"
64+
else
65+
FOOTER="> _Manually triggered via watch-upstream.sh._"
66+
fi
67+
68+
gh issue create \
69+
--title "Upstream change detected: ${UPSTREAM_REPO} ${UPSTREAM_PATH} @ ${LATEST_SHORT}" \
70+
--label "$ISSUE_LABEL" \
71+
--body "## Upstream Change Detected
72+
73+
The code at [\`${UPSTREAM_REPO}/${UPSTREAM_PATH}\`](${UPSTREAM_URL}) has a new commit since our last review.
74+
75+
| | |
76+
|---|---|
77+
| **Latest commit** | [\`${LATEST_SHORT}\`](${COMMIT_URL}) |
78+
| **Path history** | [View history](${HISTORY_URL}) |
79+
80+
Our vendored copy lives in \`${LOCAL_PATH}\`. We modified the upstream code significantly,
81+
so a direct merge is unlikely to be appropriate — but the commit above may reveal logic
82+
changes worth porting.
83+
84+
### What to do
85+
86+
1. Review the [upstream commit](${COMMIT_URL}) and [path history](${HISTORY_URL}).
87+
2. If no action is needed, close this issue with a note explaining why.
88+
3. If changes should be ported, create a follow-up task and close this issue once the work is tracked.
89+
90+
${FOOTER}"
91+
92+
echo "Issue created successfully."

0 commit comments

Comments
 (0)