Skip to content

Commit d19cb75

Browse files
authored
Fix release-gitflow not handling package.json conflicts correctly (#5403)
`version` must be kept from the master branch - all other fields should prefer develop. Without this, pnpm will be given a possibly corrupted pnpm-lock.yaml file to repair, which it will be loosening some dependencies and possibly breaking the develop branch post-merge
1 parent 86eec8a commit d19cb75

2 files changed

Lines changed: 38 additions & 4 deletions

File tree

.github/workflows/release-gitflow.yml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,7 @@ jobs:
5353
git config --global user.name "RiotRobot"
5454
5555
- name: Merge to develop
56-
run: |
57-
git checkout develop
58-
git merge -X ours master
59-
pnpm install --lockfile-only --fix-lockfile --frozen-lockfile=false --ignore-scripts
56+
run: .action-repo/scripts/release/merge-master-to-develop.sh
6057

6158
- name: Reset dependencies
6259
if: inputs.dependencies
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/bin/bash
2+
3+
set -ex
4+
5+
git checkout develop
6+
git merge origin/master --no-commit --no-ff || true
7+
8+
CONFLICTS=$(git diff --name-only --diff-filter=U)
9+
10+
if [ -n "$CONFLICTS" ]; then
11+
if echo "$CONFLICTS" | grep -q 'package.json'; then
12+
# Merge package.json in a way where we prefer all changes from `develop`
13+
# except for the `version` field which we take from `master`.
14+
git show HEAD:package.json > package.ours.json # develop
15+
git show FETCH_HEAD:package.json > package.theirs.json # master
16+
17+
jq -s '(.[0].version) as $masterVersion | (reduce .[] as $item ({}; . * $item)) | .version = $masterVersion' package.theirs.json package.ours.json > package.json
18+
rm package.ours.json package.theirs.json
19+
git add package.json
20+
fi
21+
22+
# Reset lockfile to ours (develop) to clear raw text syntax errors
23+
if echo "$CONFLICTS" | grep -q 'pnpm-lock.yaml'; then
24+
git checkout --ours pnpm-lock.yaml
25+
fi
26+
27+
# Fallback for any other files
28+
git checkout --ours . 2>/dev/null || true
29+
fi
30+
31+
# Rebuild lockfile based on the unified package.json
32+
pnpm install --lockfile-only --ignore-scripts --frozen-lockfile=false
33+
34+
# Commit and push
35+
git add .
36+
git commit --no-edit
37+
git push origin develop

0 commit comments

Comments
 (0)