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 this repository
25 uses: actions/checkout@v4
26 with:
27 fetch-depth: 1
28 persist-credentials: true
29
30 - name: Fetch upstream source (no upstream code execution)
31 run: |
32 set -euo pipefail
33 git clone --depth 1 --single-branch --branch develop \
34 https://github.com/medusajs/medusa.git /tmp/medusa-upstream
35 echo "UPSTREAM_SHA=$(git -C /tmp/medusa-upstream rev-parse HEAD)" >> "$GITHUB_ENV"
36
37 - name: Prepare review branch with source changes
38 run: |
39 set -euo pipefail
40 git config user.name "github-actions[bot]"
41 git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
42 git checkout -B automation/medusa-upstream-review
43 # Keep local GitHub configuration and workflows intact. These are
44 # security-sensitive and require separate manual review.
45 rsync -a --delete \
46 --exclude='/.git/' \
47 --exclude='/.github/' \
48 /tmp/medusa-upstream/ ./
49 mkdir -p .github
50 printf '%s\n' "$UPSTREAM_SHA" > .github/medusa-upstream-reviewed-sha
51 git add -A
52 if git diff --cached --quiet; then
53 echo "HAS_CHANGES=false" >> "$GITHUB_ENV"
54 else
55 git commit -m "Review Medusa upstream develop at $UPSTREAM_SHA"
56 git push --force-with-lease origin HEAD:refs/heads/automation/medusa-upstream-review
57 echo "HAS_CHANGES=true" >> "$GITHUB_ENV"
58 fi
59
60 - name: Open or update review pull request
61 if: env.HAS_CHANGES == 'true'
62 env:
63 GH_TOKEN: ${{ github.token }}
64 run: |
65 set -euo pipefail
66 if gh pr list --head automation/medusa-upstream-review --base main --state open --json number --jq '.[0].number' | grep -q '[0-9]'; then
67 echo "Existing review PR updated."
68 else
69 gh pr create \
70 --base main \
71 --head automation/medusa-upstream-review \
72 --title "Review upstream Medusa develop updates" \
73 --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."
74 fi