-
Notifications
You must be signed in to change notification settings - Fork 7
73 lines (60 loc) · 2.25 KB
/
merge-main-into-pr-and-test.yml
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
name: Merge main into PR and test build
on:
pull_request:
types: [opened, reopened, synchronize]
push:
branches:
- main
jobs:
merge_and_build:
runs-on: ubuntu-latest
steps:
- name: Get PR branch name
id: pr_branch
run: echo "::set-output name=branch::${{ github.event.pull_request.head.ref }}"
- name: Checkout code
uses: actions/checkout@v2
- name: Set up Node.js and Yarn
uses: actions/setup-node@v2
with:
node-version: '20'
- name: Install Yarn
run: npm install -g yarn
- name: Merge and check build
run: |
git config user.email "[email protected]"
git config user.name "hasura-bot"
# Get the PR branch's name from the event payload
BRANCH_NAME=${{ steps.pr_branch.outputs.branch }}
echo "🤔 Attempting to merge 'main' into '$BRANCH_NAME'..."
# Check out and pull the 'main' branch
git fetch > /dev/null 2>&1
git checkout main > /dev/null 2>&1
git pull > /dev/null 2>&1
echo "⬇️ Checked out and pulled 'main' branch."
# Check out and pull the PR's branch
git checkout $BRANCH_NAME > /dev/null 2>&1
git pull > /dev/null 2>&1
echo "⬇️ Checked out and pulled $BRANCH_NAME branch."
# Merge 'main' into the PR's branch
git merge --no-edit main > /dev/null 2>&1
echo "🔀 Merged 'main' into '$BRANCH_NAME'."
# Check if there are merge conflicts
if [ $? -eq 0 ]; then
# No merge conflicts, so we can proceed with the build
echo "🚧 Installing dependencies..."
yarn install > /dev/null 2>&1
echo "🧰 Building..."
yarn build > /dev/null 2>&1
# Check if the build was successful
if [ $? -eq 0 ]; then
# Build succeeded
echo "🚀 Merge and build succeeded, okay to merge PR 🎉."
else
echo "❌ Build failed. Please fix any issues before committing."
exit 1
fi
else
echo "🔥 Merge conflicts encountered. Resolve conflicts before committing."
exit 1
fi