-
Notifications
You must be signed in to change notification settings - Fork 59
/
sync.sh
executable file
·164 lines (142 loc) · 5.84 KB
/
sync.sh
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#!/bin/bash -e
#
# Copyright (c) 2021-2022 Red Hat, Inc.
# This program and the accompanying materials are made
# available under the terms of the Eclipse Public License 2.0
# which is available at https://www.eclipse.org/legal/epl-2.0/
#
# SPDX-License-Identifier: EPL-2.0
#
# Contributors:
# Red Hat, Inc. - initial API and implementation
#
# convert che-dashboard upstream to devspaces-dashboard downstream using yq, sed, and deleting files
SCRIPTS_DIR=$(cd "$(dirname "$0")"; pwd)
# defaults
CSV_VERSION=3.y.0 # csv 3.y.0
DS_VERSION=${CSV_VERSION%.*} # tag 3.y
GET_YARN=1
usage () {
echo "
Usage: $0 -v [DS CSV_VERSION] [-s /path/to/sources] [-t /path/to/generated]
Example: $0 -v 3.y.0 -s ${HOME}/projects/dashboard -t /tmp/dashboard"
#echo "Options:
# --no-vendor # don't rebuild the vendor folder"
exit
}
if [[ $# -lt 6 ]]; then usage; fi
while [[ "$#" -gt 0 ]]; do
case $1 in
# for CSV_VERSION = 2.2.0, get DS_VERSION = 2.2
'-v') CSV_VERSION="$2"; DS_VERSION="${CSV_VERSION%.*}"; shift 1;;
# paths to use for input and ouput
'-s') SOURCEDIR="$2"; SOURCEDIR="${SOURCEDIR%/}"; shift 1;;
'-t') TARGETDIR="$2"; TARGETDIR="${TARGETDIR%/}"; shift 1;;
'--no-yarn') GET_YARN=0;;
'--help'|'-h') usage;;
# optional tag overrides
esac
shift 1
done
if [ "${CSV_VERSION}" == "3.y.0" ]; then usage; fi
# step one - build the builder image
BUILDER=$(command -v podman || true)
if [[ ! -x $BUILDER ]]; then
echo "[WARNING] podman is not installed, trying with docker"
BUILDER=$(command -v docker || true)
if [[ ! -x $BUILDER ]]; then
echo "[ERROR] must install docker or podman. Abort!"; exit 1
fi
fi
# global / generic changes
echo ".github/
.git/
.gitattributes
packages/dashboard-frontend/assets/branding/
packages/devfile-registry/air-gap/index.json
samples/index.json
build/scripts/
build/dockerfiles/brew.Dockerfile
container.yaml
/content_sets.*
/cvp.yml
/cvp-owners.yml
get-source*.sh
/README.adoc
" > /tmp/rsync-excludes
echo "Rsync ${SOURCEDIR} to ${TARGETDIR}"
rm -fr ${TARGETDIR}/node_modules/
rm -fr ${TARGETDIR}/**/node_modules/
rm -fr ${TARGETDIR}/.yarn/
rsync -azrlt --checksum --exclude-from /tmp/rsync-excludes --delete ${SOURCEDIR}/ ${TARGETDIR}/
rm -f /tmp/rsync-excludes
# get job-config.json
SCRIPTS_BRANCH="$(git rev-parse --abbrev-ref HEAD 2>/dev/null || true)"
if [[ $SCRIPTS_BRANCH != "devspaces-3."*"-rhel-8" ]]; then SCRIPTS_BRANCH="devspaces-3-rhel-8"; fi
configjson=$(curl -sSLo- https://raw.githubusercontent.com/redhat-developer/devspaces/${SCRIPTS_BRANCH}/dependencies/job-config.json)
### Prepare airgap samples
SRC_SAMPLES_JSON="${TARGETDIR}/samples/index.json"
SAMPLES_OUTPUT_DIR="${TARGETDIR}/packages/devfile-registry/air-gap"
# Set the correct tree in the samples index.json
sed -i "s|tree/devspaces-[0-9.]-rhel-8|tree/${SCRIPTS_BRANCH}|g" "${SRC_SAMPLES_JSON}"
# Copy new samples
rm -rf "${SAMPLES_OUTPUT_DIR}"
. "${TARGETDIR}/scripts/airgap.sh" -i "${SRC_SAMPLES_JSON}" -o "${SAMPLES_OUTPUT_DIR}"
# get yarn version + download it for use in Brew; cannot use `npm i -g yarn` downstream so must install it this way
if [[ $GET_YARN -eq 1 ]]; then
YARN_VERSION=$(echo "${configjson}" | jq -r --arg DS_VERSION "${DS_VERSION}" '.Other["YARN_VERSION"][$DS_VERSION]');
YARN_TARGET_DIR=${TARGETDIR}/.yarn/releases
echo "Install Yarn $YARN_VERSION into $YARN_TARGET_DIR ... "
mkdir -p "${YARN_TARGET_DIR}"
curl -sSL "https://github.com/yarnpkg/yarn/releases/download/v${YARN_VERSION}/yarn-${YARN_VERSION}.js" -o "${YARN_TARGET_DIR}/yarn-${YARN_VERSION}.js"
chmod +x "${YARN_TARGET_DIR}/yarn-${YARN_VERSION}.js"
fi
sed_in_place() {
SHORT_UNAME=$(uname -s)
if [ "$(uname)" == "Darwin" ]; then
sed -i '' "$@"
elif [ "${SHORT_UNAME:0:5}" == "Linux" ]; then
sed -i "$@"
fi
}
sed_in_place -r \
`# Update DevSpaces version for Dockerfile` \
-e "s/version=.*/version=\"$DS_VERSION\" \\\/" \
"${TARGETDIR}"/build/dockerfiles/brew.Dockerfile
echo "Converted brew.Dockerfile"
# apply DS branding styles
cp -f ${TARGETDIR}/packages/dashboard-frontend/assets/branding/branding{-devspaces,}.css
# process product.json template to apply DS branding
SHA_CHE=$(cd ${SOURCEDIR}; git rev-parse --short=4 HEAD)
VER_CHE=$(jq -r .version package.json)
if [[ $VER_CHE =~ ^([0-9]+)\.([0-9]+)\.([0-9]+)-(SNAPSHOT|next) ]]; then # reduce the z digit, remove the snapshot suffix
XX=${BASH_REMATCH[1]}
YY=${BASH_REMATCH[2]}
ZZ=${BASH_REMATCH[3]}
let ZZ=ZZ-1 || ZZ=0; if [[ $ZZ -lt 0 ]]; then ZZ=0; fi # if result of a let == 0, bash returns 1
VER_CHE="${XX}.${YY}.${ZZ}"
fi
echo "Using: VER_CHE = $VER_CHE (SHA_CHE = $SHA_CHE)"
# update version in package.json
jq --arg VER_CHE "${VER_CHE}" '.version=$VER_CHE' package.json > package.json1; mv package.json1 package.json
SHA_DS=$(cd ${TARGETDIR}; git rev-parse --short=4 HEAD)
echo "Using: DS_VERSION = $DS_VERSION (SHA_DS = $SHA_DS)"
DS_SHAs="${DS_VERSION} @ ${SHA_DS} #${BUILD_NUMBER} :: Eclipse Che Dashboard ${VER_CHE} @ ${SHA_CHE}"
DS_DOCS_BASEURL="https://docs.redhat.com/en/documentation/red_hat_openshift_dev_spaces/${DS_VERSION}"
sed -r \
-e "s|@@devspaces.version@@|${DS_SHAs}|g" \
-e "s#@@devspaces.docs.baseurl@@#${DS_DOCS_BASEURL}#g" \
${TARGETDIR}/packages/dashboard-frontend/assets/branding/product.json.template > ${TARGETDIR}/packages/dashboard-frontend/assets/branding/product.json
# shellcheck disable=SC2086
# https://issues.redhat.com/browse/CRW-3292 - remove -next suffix
while IFS= read -r -d '' d; do
if [[ $(grep -E "version.*-next" ${d}) ]]; then
sed -r -e 's|("version": "[0-9.]+)-next"|\1"|' -i "${d}"
echo "Updated version in ${d}"
fi
done < <(find ${TARGETDIR}/ -name "*.json" -type f -print0)
# TODO: Remove this script and yarn 1 files once we have migrated to Konflux
# Update to use yarn 1 for brew:
"${TARGETDIR}"/scripts/yarn/change_package_manager.sh
# ensure shell scripts are executable
find ${TARGETDIR}/ -name "*.sh" -exec chmod +x {} \;