[neon/ubuntu-core/models.add-model-autocommit-script] /: Improve error handling

Antoine Gonzalez null at kde.org
Wed Oct 2 09:47:40 BST 2024


Git commit 69d26133a46b3c65562f0f69712b2775cd962ad7 by Antoine Gonzalez.
Committed on 02/10/2024 at 08:47.
Pushed by daspood into branch 'models.add-model-autocommit-script'.

Improve error handling

M  +31   -25   update-models.sh

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

diff --git a/update-models.sh b/update-models.sh
index fcc9284..b566734 100755
--- a/update-models.sh
+++ b/update-models.sh
@@ -3,46 +3,52 @@
 # The goal of this script is to download, unpack and commit the `.model` files generated by the CI.
 # It will find the latest pipeline associated with the current local branch and try to fetch artifacts from it.
 
+SCRIPT_PATH=`readlink -f $0`
+SCRIPT_DIR=`dirname $SCRIPT_PATH`
+REF=`git branch --show-current`
+
 # Fetch Pipeline ID
 
-ref=`git branch --show-current`
-pipeline_id=`curl "https://invent.kde.org/api/v4/projects/17308/pipelines" | jq "[.[] | select(.ref == \"$ref\")][0].id"`
-if [ -z "$pipeline_id" ]; then
-    echo "Pipeline not found, make sure you have manually triggered a pipeline for this branch"
-    exit 1
-else
+if pipeline_id=`curl -s -f "https://invent.kde.org/api/v4/projects/17308/pipelines" | jq -e "[.[] | select(.ref == \"$REF\")][0].id"`
+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"
+    exit 1
 fi
 
 # Fetch Job ID
 
-job_id=`curl "$job_url" | jq '.[] | select(.name == "neon_core_models") | .id'`
-if [ -z "$job_id" ]; then
-    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
-else
+if job_id=`curl -s -f "$job_url" | jq -e '.[] | select(.name == "neon_core_models") | .id'`
+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 Job Artefact
+# Fetch Job Artefact, Unpack & Commit
+
+curl -s --location --output "$SCRIPT_DIR/Signed_models.zip" "$artifacts_url"
+unzip "$SCRIPT_DIR/Signed_models.zip" -d "$SCRIPT_DIR/Signed_models"
+success=$?
 
-if [ -z "`curl $artifacts_url | jq '.message'`" ]; then
-    rm -f /tmp/Signed_models.zip
-    curl --location --output /tmp/Signed_models.zip "$artifacts_url"
+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 "Got the following error while fetching job artifacts:"
-    curl "$artifacts_url" | jq
-    exit 1
+    echo "Failed to download artifacts:"
+    cat "$SCRIPT_DIR/Signed_models.zip" ; echo
 fi
 
-# Git unpack and commit
+# Cleanup
 
-rm -rf /tmp/Signed_models
-unzip /tmp/Signed_models.zip -d /tmp/Signed_models
-mv /tmp/Signed_models/*.model ./
-git add -f ./*.model
-git commit -m "Update models"
+rm -f "$SCRIPT_DIR/Signed_models.zip"
+rm -rf "$SCRIPT_DIR/Signed_models"
 
-echo "Commit done, you may verify it before pushing it"
+exit $success
\ No newline at end of file


More information about the Neon-commits mailing list