[neon/ubuntu-core/models.add-model-autocommit-script] /: Add script to auto-commit model files
Antoine Gonzalez
null at kde.org
Tue Oct 1 15:52:24 BST 2024
Git commit f91778e6d545d650020f3cdf3b7c68a7db96fb23 by Antoine Gonzalez.
Committed on 01/10/2024 at 14:52.
Pushed by daspood into branch 'models.add-model-autocommit-script'.
Add script to auto-commit model files
M +1 -1 README.md
A +48 -0 update-models.sh
https://invent.kde.org/neon/ubuntu-core/-/commit/f91778e6d545d650020f3cdf3b7c68a7db96fb23
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..fcc9284
--- /dev/null
+++ b/update-models.sh
@@ -0,0 +1,48 @@
+#!/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.
+
+# 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
+ 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"
+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
+ artifacts_url="https://invent.kde.org/api/v4/projects/17308/jobs/$job_id/artifacts"
+ echo "Using job #$job_id - artifacts url: $artifacts_url"
+fi
+
+# Fetch Job Artefact
+
+if [ -z "`curl $artifacts_url | jq '.message'`" ]; then
+ rm -f /tmp/Signed_models.zip
+ curl --location --output /tmp/Signed_models.zip "$artifacts_url"
+else
+ echo "Got the following error while fetching job artifacts:"
+ curl "$artifacts_url" | jq
+ exit 1
+fi
+
+# Git unpack and commit
+
+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"
+
+echo "Commit done, you may verify it before pushing it"
More information about the Neon-commits
mailing list