-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate_setup
executable file
·52 lines (47 loc) · 2.48 KB
/
update_setup
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
#!/bin/bash
# update_setup version 1.0
# This script will update all necessary files for personal projects from ThomasYeoLab/project_setup
# This script is automatically updated and called in pre-push hook
# For manual updates with out push, simply use:
# wget -q https://raw.githubusercontent.com/ThomasYeoLab/project_setup/main/update_setup -O update_setup.new
# And manually replace this file
repo_dir=$(git rev-parse --show-toplevel)
# Update scripts in update list
script_list=(workflows/pull_request_checks.yml workflows/pr_checks.sh hooks/pre-commit)
for script in $script_list; do
script_dir=$(dirname "$script")
if [ ! -d "${repo_dir}/setup/${script_dir}" ]; then
mkdir -p ${repo_dir}/setup/${script_dir}
fi
if [ ! -e "${repo_dir}/setup/${script}" ]; then
wget -q https://raw.githubusercontent.com/ThomasYeoLab/project_setup/main/${script} -O ${repo_dir}/setup/${script}
git add ${repo_dir}/setup/${script}
git commit -m "Automatic commit: Add setup/${script}" --no-verify
echo "setup/${script} is added."
else
wget -q https://raw.githubusercontent.com/ThomasYeoLab/project_setup/main/${script} -O ${repo_dir}/setup/${script}.new
if diff ${repo_dir}/setup/${script} ${repo_dir}/setup/${script}.new >/dev/null; then
rm ${repo_dir}/setup/${script}.new
else
rm ${repo_dir}/setup/${script}
mv ${repo_dir}/setup/${script}.new ${repo_dir}/setup/${script}
git add ${repo_dir}/setup/${script}
git commit -m "Automatic commit: Update setup/${script}" --no-verify
echo "setup/${script} is updated."
fi
fi
done
# Copy workflows files (symbolic link does not work for workflows)
if [ ! -d "${repo_dir}/.github/workflows" ]; then
mkdir -p ${repo_dir}/.github/workflows
fi
if [ -e "${repo_dir}/.github/workflows/pull_request_checks.yml" ]; then
rm ${repo_dir}/.github/workflows/pull_request_checks.yml
cp ${repo_dir}/setup/workflows/pull_request_checks.yml ${repo_dir}/.github/workflows/pull_request_checks.yml
git add ${repo_dir}/.github/workflows/pull_request_checks.yml
git commit -m "Automatic commit: Update .github/workflows/pull_request_checks.yml" --no-verify
else
cp ${repo_dir}/setup/workflows/pull_request_checks.yml ${repo_dir}/.github/workflows/pull_request_checks.yml
git add ${repo_dir}/.github/workflows/pull_request_checks.yml
git commit -m "Automatic commit: Add .github/workflows/pull_request_checks.yml" --no-verify
fi