Debian Codegraph @

download_vendor

raw
1 #!/usr/bin/env bash
2 # Simple script to download the artifacts from the GitLab CI runner
3 # - Prerequisites: `curl` `unzip`
4 # - Optionally: set `MZNARCH` variable to select
5 # - Run as `./download_vendor` or `bash download_vendor`
6 # - Rerun to update vendor packages (remove `./vendor` directory to force redownload)
7
8 set -e # abort if any command fails
9
10 BRANCH="master" # branch of the vendor repository
11
12 if [ -z ${MZNARCH+x} ]; then
13 if [[ "$OSTYPE" == "linux-gnu"* ]]; then
14 MZNARCH="linux"
15 elif [[ "$OSTYPE" == "darwin"* ]]; then
16 MZNARCH="osx"
17 elif [[ "$OSTYPE" == "cygwin" ]]; then
18 MZNARCH="win64"
19 elif [[ "$OSTYPE" == "msys" ]]; then
20 MZNARCH="win64"
21 elif [[ "$OSTYPE" == "win32" ]]; then
22 MZNARCH="win64"
23 else
24 echo "Unable to determine operating system"
25 exit 1
26 fi
27 fi
28
29 JOB="vendor:${MZNARCH}"
30
31 # -- Download JSON file with newest dependencies version
32 curl --silent -o "_newversion.json" --location "https://gitlab.com/api/v4/projects/minizinc%2Fminizinc-vendor/pipelines?ref=${BRANCH}&per_page=1&page=1"
33 echo $JOB >> _newversion.json
34 # --- Compare with current downloaded version (if exists)
35 if [ ! -f "vendor/version.json" ] || ! cmp --silent "vendor/version.json" "_newversion.json"; then
36 echo -n "Updating depencencies..."
37 # --- Remove old version of the dependencies
38 rm -rf vendor/
39 # --- Download new version of dependencies
40 curl --silent -o "artifact.zip" --location "https://gitlab.com/api/v4/projects/minizinc%2Fminizinc-vendor/jobs/artifacts/${BRANCH}/download?job=${JOB}"
41 # --- Extract new version of dependencies
42 unzip -q "artifact.zip"
43 # --- Update version of dependencies
44 mv "_newversion.json" "vendor/version.json"
45 rm "artifact.zip"
46 echo " COMPLETE"
47 else
48 # --- Nothing to do
49 # --- Clear temporary file
50 rm "_newversion.json"
51 echo "Dependencies already up-to-date"
52 fi