[neon/ubuntu-core] /: Add auto-commit script for CI-generated models
Antoine Gonzalez
null at kde.org
Wed Oct 2 14:28:25 BST 2024
Git commit 2ebf9e4e3e97d8f77fbd2275580bf45e9a93d7d0 by Antoine Gonzalez.
Committed on 02/10/2024 at 13:22.
Pushed by ervin into branch 'master'.
Add auto-commit script for CI-generated models
M +1 -1 README.md
A +46 -0 update-models.sh
https://invent.kde.org/neon/ubuntu-core/-/commit/2ebf9e4e3e97d8f77fbd2275580bf45e9a93d7d0
diff --git a/README.md b/README.md
index fce2b3d..ea46b6a 100644
--- a/README.md
+++ b/README.md
@@ -16,7 +16,7 @@ Go to https://invent.kde.org/neon/ubuntu-core/-/pipelines/new. On this page, sel
Your branch needs to be protected, and its name needs to match the `models.*` pattern for the job to run.
-Once the job is complete, it will upload both `dangerous` and `signed` versions of the model as pipeline artefacts. You can then download them, test them locally, and commit then.
+Once the job is complete, it will upload both `dangerous` and `signed` versions of the model as pipeline artefacts. You can then run `update-models.sh` to automatically download and commit the new models to your current branch.
### dangerous vs signed
diff --git a/update-models.sh b/update-models.sh
new file mode 100755
index 0000000..5d4070b
--- /dev/null
+++ b/update-models.sh
@@ -0,0 +1,46 @@
+#!/bin/sh
+
+# 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.
+
+BASE_URL="https://invent.kde.org/api/v4/projects/17308"
+SCRIPT_PATH=`readlink -f $0`
+SCRIPT_DIR=`dirname $SCRIPT_PATH`
+DL_DIR=`mktemp -t -d model_artifactsXXX`
+REF=`git branch --show-current`
+
+cleanup() {
+ rm -rf "$DL_DIR"
+}
+
+failure() {
+ echo "$1"
+ cleanup
+ exit 1
+}
+
+# Fetch Pipeline ID
+
+pipeline_id=`curl -s -f "$BASE_URL/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="$BASE_URL/pipelines/$pipeline_id/jobs?scope[]=success"
+echo "Using pipeline #$pipeline_id - job url: $job_url"
+
+# Fetch Job ID
+
+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="$BASE_URL/jobs/$job_id/artifacts"
+echo "Using job #$job_id - artifacts url: $artifacts_url"
+
+# Fetch Job Artefact, Unpack & Commit
+
+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 -v "$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"
+
+cleanup
+echo "Commit done, you may verify it before pushing"
More information about the Neon-commits
mailing list