summaryrefslogtreecommitdiffstats
path: root/scripts/ci/checkout-oe.sh
blob: ed74595feab5664c0fe39b4fc5bfb9367c61bda1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/env bash

set -euo pipefail

set -x

REMOTE_SOURCE=${REMOTE_SOURCE:-https://github.com/advancedtelematic}
MANIFEST=${MANIFEST:-master}
CURRENT_PROJECT=${CURRENT_PROJECT:-}

# list of projects to pin to one version in the format:
# "project:rev;project2:rev2..."
PIN_LIST=${PIN_LIST:-}

#CURRENT_REV=$(git rev-parse HEAD)
LOCAL_REPO=$PWD

mkdir -p updater-repo

cd updater-repo

# it seems like it's always required now, even if repo is only used to fetch
git config --global user.email "meta-updater-ci@example.org"
git config --global user.name "meta-updater-ci"

if [ -d .repo/manifests ]; then
    git -C .repo/manifests reset --hard
fi

repo init -m "${MANIFEST}.xml" -u "$REMOTE_SOURCE/updater-repo"

# patch manifest:
# - add a new "ats" remote that points to "$REMOTE_SOURCE"
# - change projects that contain "advancedtelematic" to use the ats remote
MANIFEST_FILE=".repo/manifests/${MANIFEST}.xml"
xmlstarlet ed --omit-decl -L \
    -s "/manifest" -t elem -n "remote" -v "" \
    -i "/manifest/remote[last()]" -t attr -n "name" -v "ats" \
    -i "/manifest/remote[last()]" -t attr -n "fetch" -v "$REMOTE_SOURCE" \
    -d "/manifest/project[contains(@name, 'advancedtelematic')]/@remote" \
    -i "/manifest/project[contains(@name, 'advancedtelematic')]" -t attr -n "remote" -v "ats" \
    "$MANIFEST_FILE"

# hack: sed on `advancedtelematic/` names, to remove this unwanted prefix
sed -i 's#name="advancedtelematic/#name="#g' "$MANIFEST_FILE"

# pin projects from the list
(
IFS=";"
for pin in $PIN_LIST; do
    IFS=":"
    read -r project rev <<< "$pin"
    xmlstarlet ed --omit-decl -L \
        -d "/manifest/project[@name=\"$project\"]/@revision" \
        -i "/manifest/project[@name=\"$project\"]/@revision" -t attr -n "revision" -v "$rev" \
        -i "/manifest/project[@name=\"$project\"]" -t attr -n "revision" -v "$rev" \
        "$MANIFEST_FILE"
    IFS=";"
done
)

# Remove the current project from the manifest if we have it checked out
if [ -n "$CURRENT_PROJECT" ]; then
    xmlstarlet ed --omit-decl -L \
        -d "/manifest/project[@name=\"$CURRENT_PROJECT\"]" \
        "$MANIFEST_FILE"
fi

repo manifest

# Try to clean up the repos in case they are messed up, but this returns an
# error code if the repos don't exist, which the subsequent repo sync will fix.
repo forall -c 'git reset --hard ; git clean -fdx' || true

repo sync -d --force-sync

if [ -n "$CURRENT_PROJECT" ]; then
    rm -f "$CURRENT_PROJECT"
    ln -s "$LOCAL_REPO" "$CURRENT_PROJECT"
fi

repo manifest -r