Merge "Migrate current Sonar jobs to Sonarcloud"
[ci-management.git] / jjb / shell / ta-rpm-deploy.sh
1 #!/bin/bash
2 # SPDX-License-Identifier: EPL-1.0
3 ##############################################################################
4 # Copyright (c) 2017 The Linux Foundation and others.
5 #
6 # All rights reserved. This program and the accompanying materials
7 # are made available under the terms of the Eclipse Public License v1.0
8 # which accompanies this distribution, and is available at
9 # http://www.eclipse.org/legal/epl-v10.html
10 ##############################################################################
11
12 echo "---> ta-rpm-deploy.sh"
13
14 # Ensure we fail the job if any steps fail.
15 set -eu -o pipefail
16
17 set -x  # Trace commands for this script to make debugging easier.
18
19 NEXUS_REPO=rpm.snapshots
20 release_path=TA/release-1
21
22 repo_dir="$WORKSPACE/work/nexus/$NEXUS_REPO"
23 arch_dir="$repo_dir/$release_path/rpms/$(uname -m)"
24 sources_dir="$repo_dir/$release_path/rpms/Sources"
25 nexus_repo_url="$RPM_REPO_URL/repository/$NEXUS_REPO"
26 results_dir="$WORKSPACE/work/results"
27 repo_name=`echo $WORKSPACE | awk -F '/' '{print $4}' | cut -d '-' -f2- | sed 's|\(.*\)-.*|\1|'`
28
29 #Creating dirs to move duplicate RPMs/SRPMs to avoid re-upload and copy the changed RPMs/SRPMs
30 rm -rf "$results_dir/repo/duplicates" "$results_dir/src_repo/duplicates"
31 mkdir "$results_dir/repo/duplicates"
32 mkdir "$results_dir/src_repo/duplicates"
33 mkdir -p "$arch_dir"
34 mkdir -p "$sources_dir"
35
36 #List all RPMs available in Nexus, move the duplicates and copy the changed ones
37 for artifact in \
38   `ls $results_dir/repo/*.rpm`
39     do
40         if curl -L --head --fail $nexus_repo_url/$release_path/rpms/$(uname -m)/$(basename $artifact)
41         then
42             echo "RPM - $(basename $artifact) already available in Nexus"
43             mv $results_dir/repo/$(basename $artifact) $results_dir/repo/duplicates/
44         else
45             echo "RPM - $(basename $artifact) is not available in Nexus. Will be uploaded"
46             cp $results_dir/repo/$(basename $artifact) $arch_dir
47         fi
48     done
49
50 #List all Source RPMs available in Nexus, move the duplicates and copy the changed ones
51 for artifact in \
52   `ls $results_dir/src_repo/*.rpm`
53     do
54         if curl -L --head --fail $nexus_repo_url/$release_path/rpms/Sources/$(basename $artifact)
55         then
56             echo "Source RPM - $(basename $artifact) already available in Nexus"
57             mv $results_dir/src_repo/$(basename $artifact) $results_dir/src_repo/duplicates/
58         else
59             echo "Source RPM - $(basename $artifact) is not available in Nexus. Will be uploaded"
60             cp $results_dir/src_repo/$(basename $artifact) $sources_dir
61         fi
62     done
63
64 echo "-----> Upload RPMs to Nexus"
65 lftools deploy nexus "$nexus_repo_url" "$repo_dir"
66
67 set +x  # Disable trace since we no longer need it.
68 echo "RPMs location: <a href=\"$nexus_repo_url\">$nexus_repo_url</a>"