-
Notifications
You must be signed in to change notification settings - Fork 7
130 lines (113 loc) · 4.3 KB
/
build_node_ui.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
name: Build and Commit node-ui
on:
workflow_dispatch:
push:
branches:
- master # Explicitly set to master
paths:
- 'node-ui/**'
pull_request:
types:
- closed
jobs:
build_node_ui:
if: github.event.pull_request.merged == true || github.event_name == 'push' || github.event_name == 'workflow_dispatch'
runs-on: ubuntu-latest
env:
HUSKY: 0 # Disable Husky globally for this job
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0 # Fetch all history for all branches and tags
# Check if there are changes in the node-ui folder (excluding build)
- name: Check for changes in node-ui (excluding build folder)
id: check_changes
run: |
echo "CHANGES_DETECTED=false" >> $GITHUB_ENV
git fetch --unshallow || true
# For workflow_dispatch, consider all files as changed
if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
echo "Workflow manually triggered. Considering all files as changed."
echo "CHANGES_DETECTED=true" >> $GITHUB_ENV
else
# Check for changes in the node-ui folder (excluding the build directory)
changes=$(git diff --name-only HEAD~1 HEAD -- 'node-ui' ':!node-ui/build')
if [ -n "$changes" ]; then
echo "Changes detected in node-ui."
echo "CHANGES_DETECTED=true" >> $GITHUB_ENV
else
echo "No changes in node-ui (excluding build folder)."
fi
fi
# Conditional steps, executed only if changes were detected
- name: Set up Node.js
if: env.CHANGES_DETECTED == 'true'
uses: actions/setup-node@v3
with:
node-version: '20'
- name: Install pnpm
if: env.CHANGES_DETECTED == 'true'
run: npm install -g pnpm
- name: Install frontend dependencies with pnpm
if: env.CHANGES_DETECTED == 'true'
run: pnpm install --prefix ./node-ui
# Set up Git credentials for committing
- name: Set up Git user
if: env.CHANGES_DETECTED == 'true'
run: |
git config --global user.name "GitHub Actions"
git config --global user.email "[email protected]"
- name: Build node ui
if: env.CHANGES_DETECTED == 'true'
run: |
cd $GITHUB_WORKSPACE/node-ui
pnpm build
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Commit and push changes
if: env.CHANGES_DETECTED == 'true'
run: |
cd $GITHUB_WORKSPACE
git add ./node-ui/build
git commit -m "Automated build of node-ui" || echo "No changes to commit"
# Retry loop
max_attempts=5
attempt=1
while [ $attempt -le $max_attempts ]; do
echo "Attempt $attempt to push changes..."
git fetch origin master
git rebase origin/master
if git push origin HEAD:master; then
echo "Successfully pushed changes."
break
else
echo "Push failed. Retrying in 5 seconds..."
sleep 5
attempt=$((attempt + 1))
fi
done
if [ $attempt -gt $max_attempts ]; then
echo "Failed to push changes after $max_attempts attempts."
exit 1
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Clone target repository
if: env.CHANGES_DETECTED == 'true'
run: |
cd $GITHUB_WORKSPACE
git clone https://github.com/calimero-network/admin-dashboard.git
- name: Copy entire node-ui to target repo
if: env.CHANGES_DETECTED == 'true'
run: |
cp -r $GITHUB_WORKSPACE/node-ui/src/* $GITHUB_WORKSPACE/admin-dashboard/src/
- name: Push changes to admin-dashboard repo
if: env.CHANGES_DETECTED == 'true'
run: |
cd $GITHUB_WORKSPACE/admin-dashboard
git add -A
git commit -m "Automated push of node-ui changes (excluding build)" || echo "No changes to commit"
git push https://${{ secrets.PUSH_TOKEN }}@github.com/calimero-network/admin-dashboard.git master
env:
PUSH_TOKEN: ${{ secrets.PUSH_TOKEN }}