forked from msei99/pbgui
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmaster-switch-pb7-branch.yml
More file actions
178 lines (158 loc) · 5.55 KB
/
Copy pathmaster-switch-pb7-branch.yml
File metadata and controls
178 lines (158 loc) · 5.55 KB
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
---
# Switch pb7 branch/commit on localhost
# Steps:
# 1. Fetch from origin
# 2. Check for uncommitted changes (fail if found)
# 3. Checkout specified branch
# 4. Optionally hard-reset the checked out branch to a specific commit
# 5. Otherwise hard-reset the checked out branch to the selected remote head
# 6. Restart pbgui services
- hosts: localhost
gather_facts: "{{ debug }}"
vars:
user: "{{ user }}"
pbgdir: "{{ pbgdir }}"
pbgvenv: "{{ pbgvenv }}"
pb7dir: "{{ pb7dir }}"
pb7venv: "{{ pb7venv }}"
target_branch: "{{ pb7_branch }}"
source_branch: "{{ pb7_source_branch | default(pb7_branch) }}"
target_commit: "{{ pb7_commit | default('') }}"
remote_name: "{{ pb7_remote_name | default('origin') }}"
remote_url: "{{ pb7_remote_url | default('') }}"
tasks:
- name: display facts
debug:
var: ansible_facts
tags: debug,never
- name: Ensure custom remote exists (optional)
shell: |
set -e
if [ -n "{{ remote_url }}" ]; then
if git remote get-url "{{ remote_name }}" >/dev/null 2>&1; then
git remote set-url "{{ remote_name }}" "{{ remote_url }}"
else
git remote add "{{ remote_name }}" "{{ remote_url }}"
fi
fi
args:
chdir: "{{ pb7dir }}"
when: pb7dir != ""
changed_when: false
- name: Fetch from selected remote
command: git fetch "{{ remote_name }}"
args:
chdir: "{{ pb7dir }}"
when: pb7dir != ""
changed_when: false
- name: Check for uncommitted changes (tracked files only)
shell: git diff --name-only && git diff --cached --name-only
args:
chdir: "{{ pb7dir }}"
register: git_status
changed_when: false
- name: Fail if uncommitted changes exist
fail:
msg: "Uncommitted changes detected in PB7. Please commit or stash changes before switching branches."
when: git_status.stdout != ""
- name: Check if branch exists locally
command: git show-ref --verify --quiet "refs/heads/{{ target_branch }}"
args:
chdir: "{{ pb7dir }}"
register: branch_exists
failed_when: false
changed_when: false
- name: Check if source branch exists on selected remote
command: git show-ref --verify --quiet "refs/remotes/{{ remote_name }}/{{ source_branch }}"
args:
chdir: "{{ pb7dir }}"
register: source_branch_exists
failed_when: false
changed_when: false
- name: Fail if source branch is missing on selected remote
fail:
msg: "Remote branch {{ remote_name }}/{{ source_branch }} does not exist. Please choose a valid source branch before switching PB7."
when: source_branch_exists.rc != 0
- name: Create and checkout local branch from remote if it doesn't exist
command: git checkout -b "{{ target_branch }}" --track "{{ remote_name }}/{{ source_branch }}"
args:
chdir: "{{ pb7dir }}"
when: branch_exists.rc != 0
notify: restart pb7
- name: Checkout target branch (if already exists locally)
command: git checkout "{{ target_branch }}"
args:
chdir: "{{ pb7dir }}"
when: branch_exists.rc == 0
notify: restart pb7
- name: Reset to specific commit if provided (stays on branch)
command: git reset --hard "{{ target_commit }}"
args:
chdir: "{{ pb7dir }}"
when: target_commit != ""
register: commit_reset
notify: restart pb7
- name: Reset to latest remote HEAD (only if no specific commit provided)
command: git reset --hard "{{ remote_name }}/{{ source_branch }}"
args:
chdir: "{{ pb7dir }}"
when: target_commit == ""
register: pull_result
notify: restart pb7
- name: Display checkout result
debug:
msg: |
PB7 Target Branch: {{ target_branch }}
PB7 Source Branch: {{ remote_name }}/{{ source_branch }}
PB7 Commit: {{ target_commit if target_commit != '' else 'HEAD' }}
Status: Switched successfully
tags: debug,never
handlers:
- name: Install pb7 requirements
pip:
requirements: "{{ pb7dir }}/requirements.txt"
virtualenv: "{{ pb7venv }}"
extra_args: --upgrade pip
listen: "restart pb7"
- name: Build passivbot-rust with maturin
shell: |
source ~/.profile || source ~/.bashrc || true
source "{{ pb7venv }}/bin/activate"
maturin develop --release
args:
chdir: "{{ pb7dir }}/passivbot-rust"
executable: /bin/bash
register: maturin_result
listen: "restart pb7"
- name: Write rust source stamp after maturin build
shell: |
source "{{ pb7venv }}/bin/activate"
python - <<'PY'
import sys
sys.path.insert(0, 'src')
from rust_utils import stamp_compiled_extensions, source_fingerprint
stamp_compiled_extensions(source_fingerprint())
print('Rust source stamp updated.')
PY
args:
chdir: "{{ pb7dir }}"
executable: /bin/bash
listen: "restart pb7"
- name: kill all pb7 processes
shell: |
pids="$(ps -ef | grep "{{ pb7dir }}/src/main.py" | grep -v grep | awk '{print $2}')"
if [ -n "$pids" ]; then
kill $pids
fi
args:
executable: /bin/bash
changed_when: false
listen: "restart pb7"
ignore_errors: yes
- name: Make sure PBRun ist running
shell: |
python "{{ pbgdir }}/starter.py" -s PBRun
args:
executable: /bin/bash
chdir: "{{ pbgdir }}"
listen: "restart pb7"