forked from nim-lang/packages
-
Notifications
You must be signed in to change notification settings - Fork 1
/
getmergebase.sh
executable file
·27 lines (23 loc) · 1022 Bytes
/
getmergebase.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#!/bin/bash
# CI helper script to checkout the current packages.json and
# the version at the merge base to compare to.
set -e
# Repository and branch the PR will be merged into
targetRepository="https://github.com/$GITHUB_REPOSITORY"
targetBranch="$GITHUB_BASE_REF"
# Create a branch of the current repository state because actions/checkout
# leaves us with a detached HEAD
git branch merge-branch
# Backup the current packages.json because it will get overwritten by a
# checkout
cp packages.json packages.json.bak
# Fetch the merge target branch into a branch called "base"
git fetch "$targetRepository" "$targetBranch:base"
# Determine the last common commit (the merge base)
mergeBase="$(git merge-base merge-branch base)"
echo "Comparing against packages.json at $mergeBase"
# Checkout the package list at the branching point
git checkout "$mergeBase" packages.json
# PR version becomes packages.json and merge base becomes packages_old.json
mv packages.json packages_old.json
mv packages.json.bak packages.json