[neon/ubuntu-core/models.add-model-autocommit-script] /: Refactor script

Antoine Gonzalez null at kde.org
Wed Oct 2 10:39:55 BST 2024


Git commit ba70f8995400b8fdf14253ca243b00f916b0a346 by Antoine Gonzalez.
Committed on 02/10/2024 at 09:38.
Pushed by daspood into branch 'models.add-model-autocommit-script'.

Refactor script

M  +27   -42   update-models.sh

https://invent.kde.org/neon/ubuntu-core/-/commit/ba70f8995400b8fdf14253ca243b00f916b0a346

diff --git a/update-models.sh b/update-models.sh
index 583f2d2..3f352a8 100755
--- a/update-models.sh
+++ b/update-models.sh
@@ -5,56 +5,41 @@
 
 SCRIPT_PATH=`readlink -f $0`
 SCRIPT_DIR=`dirname $SCRIPT_PATH`
+DL_DIR=`mktemp -d model_artifactsXXX`
 REF=`git branch --show-current`
 
-# Fetch Pipeline ID
-
-pipeline_id=`curl -s -f "https://invent.kde.org/api/v4/projects/17308/pipelines" | jq -e "[.[] | select(.ref == \"$REF\")][0].id"`
-success=$?
+cleanup() {
+    rm -rf "$DL_DIR"
+}
 
-if [ $success -eq 0 ]
-then
-    job_url="https://invent.kde.org/api/v4/projects/17308/pipelines/$pipeline_id/jobs?scope[]=success"
-    echo "Using pipeline #$pipeline_id - job url: $job_url"
-else
-    echo "Pipeline not found, make sure you have manually triggered a pipeline for this branch"
+failure() {
+    echo "$1"
+    cleanup
     exit 1
-fi
-
-# Fetch Job ID
-
-job_id=`curl -s -f "$job_url" | jq -e '.[] | select(.name == "neon_core_models") | .id'`
-success=$?
+}
 
-if [ $success -eq 0 ]
-then
-    artifacts_url="https://invent.kde.org/api/v4/projects/17308/jobs/$job_id/artifacts"
-    echo "Using job #$job_id - artifacts url: $artifacts_url"
-else
-    echo "Job not found, make sure you have manually started the 'neon_core_models' job in the pipeline #$pipeline_id and it succeeded"
-    exit 1
-fi
+# Fetch Pipeline ID
 
-# Fetch Job Artefact, Unpack & Commit
+pipeline_id=`curl -s -f "https://invent.kde.org/api/v4/projects/17308/pipelines" | jq -e "[.[] | select(.ref == \"$REF\")][0].id"` \
+  || failure "Pipeline not found, make sure you have manually triggered a pipeline for this branch"
+job_url="https://invent.kde.org/api/v4/projects/17308/pipelines/$pipeline_id/jobs?scope[]=success"
+echo "Using pipeline #$pipeline_id - job url: $job_url"
 
-curl -s --location --output "$SCRIPT_DIR/Signed_models.zip" "$artifacts_url"
-unzip -qq "$SCRIPT_DIR/Signed_models.zip" -d "$SCRIPT_DIR/Signed_models"
-success=$?
+# Fetch Job ID
 
-if [ $success -eq 0 ]
-then
-    mv "$SCRIPT_DIR"/Signed_models/*.model ./
-    git add -f ./*.model
-    git commit -m "Update models"
-    echo "Commit done, you may verify it before pushing it"
-else
-    echo "Failed to download artifacts:"
-    cat "$SCRIPT_DIR/Signed_models.zip" ; echo
-fi
+job_id=`curl -s -f "$job_url" | jq -e '.[] | select(.name == "neon_core_models") | .id'` \
+  || failure "Job not found, make sure you have manually started the 'neon_core_models' job in the pipeline #$pipeline_id and it succeeded"
+artifacts_url="https://invent.kde.org/api/v4/projects/17308/jobs/$job_id/artifacts"
+echo "Using job #$job_id - artifacts url: $artifacts_url"
 
-# Cleanup
+# Fetch Job Artefact, Unpack & Commit
 
-rm -f "$SCRIPT_DIR/Signed_models.zip"
-rm -rf "$SCRIPT_DIR/Signed_models"
+curl -s --location --output "$DL_DIR/Signed_models.zip" "$artifacts_url"
+unzip -qq "$DL_DIR/Signed_models.zip" -d "$DL_DIR/Signed_models" 2> /dev/null \
+  || failure "`echo "Failed to download artifacts:" ; cat "$DL_DIR/Signed_models.zip" ; echo`"
+mv "$DL_DIR"/Signed_models/*.model "$SCRIPT_DIR"/
+git add -f "$SCRIPT_DIR"/*.model
+git commit -m "Update models"
 
-exit $success
\ No newline at end of file
+cleanup
+echo "Commit done, you may verify it before pushing it"


More information about the Neon-commits mailing list