|
| 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