Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
124 changes: 124 additions & 0 deletions .github/workflows/upstream-watch.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
# Upstream watch: open one issue per new upstream CodeGraph release that the
# fork has not integrated yet.
#
# "Integrated" means the upstream release tag is an ancestor of the fork's
# main branch (the sync merges the tag), so no state file is needed. The
# issue carries the divergence and a dry-run merge conflict list so the sync
# can be planned; the sync itself is always done by hand with the
# codegraph-vba-upstream-sync procedure, never automatically, because the
# conflicts sit where the VBA support hooks into shared code.
name: Upstream watch

on:
schedule:
- cron: '17 6 * * 1' # Mondays 06:17 UTC
workflow_dispatch: {}

permissions:
contents: read
issues: write

concurrency:
group: upstream-watch
cancel-in-progress: false

jobs:
watch:
runs-on: ubuntu-latest
env:
UPSTREAM_REPO: colbymchenry/codegraph
GH_TOKEN: ${{ github.token }}
steps:
- name: Checkout fork (full history)
uses: actions/checkout@v6
with:
fetch-depth: 0
persist-credentials: false

- name: Find the latest upstream release
id: latest
run: |
set -euo pipefail
tag="$(gh release view --repo "$UPSTREAM_REPO" --json tagName -q .tagName)"
echo "tag=$tag" >> "$GITHUB_OUTPUT"
echo "Latest upstream release: $tag"

- name: Check whether it is already integrated
id: check
env:
TAG: ${{ steps.latest.outputs.tag }}
run: |
set -euo pipefail
git remote add upstream "https://github.com/${UPSTREAM_REPO}.git"
# Namespaced and forced so a fork tag with the same name (or an
# upstream re-tag) can never block the fetch.
git fetch --quiet --no-tags --force upstream "+refs/tags/${TAG}:refs/upstream-tags/${TAG}"
status=0
git merge-base --is-ancestor "refs/upstream-tags/${TAG}" origin/main || status=$?
case "$status" in
0) echo "integrated=true" >> "$GITHUB_OUTPUT"; echo "$TAG is already integrated into main." ;;
1) echo "integrated=false" >> "$GITHUB_OUTPUT" ;;
*) echo "::error::git merge-base failed with status $status"; exit "$status" ;;
esac

- name: Open an issue for the new release
if: steps.check.outputs.integrated == 'false'
env:
TAG: ${{ steps.latest.outputs.tag }}
run: |
set -euo pipefail
title="chore(upstream): sync with upstream CodeGraph ${TAG}"
# List without --search: the search index lags behind issue creation.
existing="$(gh issue list --repo "$GITHUB_REPOSITORY" --state all --limit 1000 --json title -q '.[].title' | grep -Fx -- "$title" || true)"
if [ -n "$existing" ]; then
echo "An issue for ${TAG} already exists; nothing to do."
exit 0
fi

ref="refs/upstream-tags/${TAG}"
counts="$(git rev-list --left-right --count "origin/main...${ref}")"
read -r ahead behind <<< "$counts"
base="$(git merge-base origin/main "$ref")"
base_desc="$(git describe --tags --exact-match "$base" 2>/dev/null || git rev-parse --short "$base")"
mt=0
git merge-tree --write-tree --name-only --no-messages origin/main "$ref" > merge-tree.txt || mt=$?
case "$mt" in
0) conflicts="" ;;
1) conflicts="$(tail -n +2 merge-tree.txt)" ;;
*) echo "::error::git merge-tree failed with status $mt"; exit "$mt" ;;
esac
total="$(printf '%s' "$conflicts" | grep -c . || true)"
vba="$(printf '%s\n' "$conflicts" | grep -iE 'vba|access' || true)"

{
echo "A new upstream CodeGraph release is available and not yet integrated: [\`${TAG}\`](https://github.com/${UPSTREAM_REPO}/releases/tag/${TAG})."
echo
echo "| | |"
echo "|---|---|"
echo "| Merge base | \`${base_desc}\` |"
echo "| Fork commits not in upstream | ${ahead} |"
echo "| Upstream commits to integrate | ${behind} |"
echo "| Files that would conflict (dry run) | ${total} |"
echo
if [ -n "$vba" ]; then
echo "**VBA files in the conflict list. Review these first:**"
echo
printf '%s\n' "$vba" | sed 's/^/- `/; s/$/`/'
echo
fi
if [ "$total" -gt 0 ]; then
echo "<details><summary>Conflicting files</summary>"
echo
printf '%s\n' "$conflicts" | sed 's/^/- `/; s/$/`/'
echo
echo "</details>"
echo
fi
echo "Follow the codegraph-vba-upstream-sync procedure:"
echo "- Create an isolated sync branch and a rollback tag."
echo "- Classify every conflict, and keep the VBA hooks working."
echo "- Diff a real Access corpus before and after the merge."
echo "- Release only after CI on Node 22 is green."
} > body.md

gh issue create --repo "$GITHUB_REPOSITORY" --title "$title" --body-file body.md