Skip to content

Commit a54e16b

Browse files
committed
feat: add a manual update-all util script
1 parent 160906a commit a54e16b

3 files changed

Lines changed: 58 additions & 3 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
utility_scripts/tmp/

template/.gitea/workflows/create_update_pr.yml.jinja

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,8 @@ jobs:
3535
git checkout -b $branch
3636

3737
echo "Running copier update..."
38-
copier update --trust --defaults --conflict inline 2>&1 | tee copier.log
39-
status=${PIPESTATUS[0]}
40-
output="$(cat copier.log)"
38+
copier update --trust --defaults --conflict inline 2>&1 | tee ../copier.log
39+
output="$(cat ../copier.log)"
4140
echo $output
4241
msg="$(printf '%s\n' "$output" | head -n 1)"
4342

utility_scripts/manual_update.sh

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#!/bin/bash
2+
# HOW TO USE:
3+
# - Get an access token from gitea with repository:write permissions
4+
# - Have an ssh key loaded for gitea
5+
# - Be in a python environment with copier available
6+
# - run './manual_update.sh <token>'
7+
# clean up the tmp dir when finished: it is not automatically deleted for help in debugging
8+
9+
TMP_DIR="./tmp"
10+
if [ -d "$TMP_DIR" ]; then
11+
echo "Directory '$TMP_DIR' already exists. Exiting."
12+
exit 1
13+
fi
14+
mkdir "$TMP_DIR"
15+
16+
REPOS=("addams_bec" "csaxs_bec" "debye_bec" "microxas_bec" "phoenix_bec" "pxi_bec" "pxii_bec" "pxiii_bec" "sim_bec" "superxas_bec" "tomcat_bec" "xtreme_bec" "xil_bec" "pearl_bec" "iss_bec" "detector_group_bec")
17+
BASE_URL="git@gitea.psi.ch:bec"
18+
19+
process_repo() {
20+
local repo_dir="$1"
21+
local token="$2"
22+
echo "Processing: $repo_dir"
23+
24+
branch="chore/update-template-$(python -m uuid)"
25+
echo "switching to branch $branch"
26+
git checkout -b $branch
27+
28+
echo "Running copier update..."
29+
copier update --trust --defaults --conflict inline 2>&1 | tee ../copier.log
30+
output="$(cat ../copier.log)"
31+
echo $output
32+
msg="$(printf '%s\n' "$output" | head -n 1)"
33+
34+
if ! grep -q "make_commit: true" .copier-answers.yml ; then
35+
echo "Autocommit not made, committing..."
36+
git add -A
37+
git commit -a -m "$msg"
38+
fi
39+
40+
git push -u origin $branch
41+
curl -X POST "https://gitea.psi.ch/api/v1/repos/bec/$repo_dir/pulls" \
42+
-H "Authorization: token $token" \
43+
-H "Content-Type: application/json" \
44+
-d "{
45+
\"title\": \"Template: $(echo $msg)\",
46+
\"body\": \"Manually triggered update from util script.\",
47+
\"head\": \"$(echo $branch)\",
48+
\"base\": \"main\"
49+
}"
50+
}
51+
52+
for name in "${REPOS[@]}"; do
53+
git clone "${BASE_URL}/${name}.git" "${TMP_DIR}/${name}"
54+
(cd "${TMP_DIR}/${name}" && process_repo "$name" "$1")
55+
done

0 commit comments

Comments
 (0)