update-artifacts.sh 973 Bytes
Newer Older
mrodzis's avatar
mrodzis committed
1
2
#!/bin/bash

3
4
5
dist_dir=$(grep distDir quasar.conf.js | cut -d "'" -f2)
project_id=10921

mrodzis's avatar
mrodzis committed
6
# get the latest 'deploy' artifact which contains the former states/environments
7
jobs=$(curl --header "PRIVATE-TOKEN: $API_TOKEN" "https://gitlab.gwdg.de/api/v4/projects/${project_id}/jobs?scope=success" | jq 'sort_by(.finished_at) | reverse')
mrodzis's avatar
mrodzis committed
8
latest_deploy_job_id=$(echo $jobs | jq '.[] | select(.stage == "deploy").id' | sed -n 1p)
9
10

curl --output old-artifact.zip --header "PRIVATE-TOKEN: $API_TOKEN" "https://gitlab.gwdg.de/api/v4/projects/10921/jobs/${latest_deploy_job_id}/artifacts"
mrodzis's avatar
mrodzis committed
11
12
13

# add current data to artifact
unzip -u old-artifact.zip
14

15
if [[ $CONTINUE_BUILD == "true" || ($CI_COMMIT_BRANCH != "main" && $CI_COMMIT_BRANCH != "develop") ]]; then
16
17
    mkdir -p public/{${CI_COMMIT_SHORT_SHA},${CI_COMMIT_REF_SLUG}}
    echo public/${CI_COMMIT_SHORT_SHA} public/${CI_COMMIT_REF_SLUG} | xargs -n 1 cp --remove-destination --recursive ${dist_dir}/*
18

19
20
    [ $? -eq 0 ] && exit 0
fi