1 name: Review Medusa upstream updates
2
3 on:
4 push:
5 paths:
6 - '.github/workflows/medusa-upstream-review.yml'
7 schedule:
8 - cron: "17 6 * * *"
9 workflow_dispatch:
10
11 permissions:
12 contents: write
13 pull-requests: write
14
15 concurrency:
16 group: medusa-upstream-review
17 cancel-in-progress: false
18
19 jobs:
20 propose:
21 runs-on: ubuntu-latest
22 timeout-minutes: 45
23 steps:
24 - name: Check out default branch for upstream comparison
25 uses: actions/checkout@v4
26 with:
27 ref: main
28 fetch-depth: 1
29 persist-credentials: true
30
31 - name: Fetch upstream source (no upstream code execution)
32 run: |
33 set -euo pipefail
34 git clone --depth 1 --single-branch --branch develop \
35 https://github.com/medusajs/medusa.git /tmp/medusa-upstream
36 echo "UPSTREAM_SHA=$(git -C /tmp/medusa-upstream rev-parse HEAD)" >> "$GITHUB_ENV"
37
38 - name: Prepare review branch with source changes
39 run: |
40 set -euo pipefail
41 git config user.name "github-actions[bot]"
42 git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
43 # Always branch from main, never from a feature-branch push event.
44 git checkout -B automation/medusa-upstream-review origin/main
45 # Keep local GitHub settings and all owner-specific customizations intact.
46 # These exclusions prevent upstream --delete from removing storefront,
47 # project tracking, secret-scan policy, or owner-owned security scripts.
48 rsync -a --delete \
49 --exclude='/.git/' \
50 --exclude='/.github/' \
51 --exclude='/commerce/' \
52 --exclude='/PROJECT_STATUS.md' \
53 --exclude='/SECURITY.md' \
54 --exclude='/.gitleaksignore' \
55 --exclude='/scripts/security/' \
56 /tmp/medusa-upstream/ ./
57 mkdir -p .github
58 printf '%s\n' "$UPSTREAM_SHA" > .github/medusa-upstream-reviewed-sha
59 git add -A
60 if git diff --cached --quiet; then
61 echo "HAS_CHANGES=false" >> "$GITHUB_ENV"
62 else
63 git commit -m "Review Medusa upstream develop at $UPSTREAM_SHA"
64 # Checkout of main does not fetch the automation branch. Obtain
65 # the exact remote SHA and use an explicit optimistic-concurrency
66 # lease; an unrelated concurrent update must NOT be overwritten.
67 REMOTE_SHA=$(git ls-remote --heads origin refs/heads/automation/medusa-upstream-review | awk '{print $1}')
68 if [[ -n "$REMOTE_SHA" ]]; then
69 git push --force-with-lease=refs/heads/automation/medusa-upstream-review:"$REMOTE_SHA" origin HEAD:refs/heads/automation/medusa-upstream-review
70 else
71 git push origin HEAD:refs/heads/automation/medusa-upstream-review
72 fi
73 echo "HAS_CHANGES=true" >> "$GITHUB_ENV"
74 fi
75
76 - name: Open or update review pull request
77 if: env.HAS_CHANGES == 'true'
78 env:
79 GH_TOKEN: ${{ github.token }}
80 run: |
81 set -euo pipefail
82 if gh pr list --head automation/medusa-upstream-review --base main --state open --json number --jq '.[0].number' | grep -q '[0-9]'; then
83 echo "Existing review PR updated."
84 else
85 gh pr create \
86 --base main \
87 --head automation/medusa-upstream-review \
88 --title "Review upstream Medusa develop updates" \
89 --body "Source: https://github.com/medusajs/medusa (develop). This PR is for human review only. No automatic merge. The .github directory (including upstream workflows) is intentionally excluded. Inspect changes, especially deletions and local customizations, before merging."
90 fi