Upload changed RPMs/SRPMs to Nexus
[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 x86_dir="$repo_dir/$release_path/rpms/x86_64"
24 sources_dir="$repo_dir/$release_path/rpms/Sources"
25 nexus_repo_url="$ALT_NEXUS_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 dir to move duplicate RPMs/SRPMs to avoid re-upload
30 mkdir "$results_dir/repo/duplicates"
31 mkdir "$results_dir/src_repo/duplicates"
32
33 #List all RPMs available in Nexus and move the duplicates
34 for artifact in \
35   `ls $results_dir/repo`
36     do
37         if curl --head --fail $nexus_repo_url/$release_path/rpms/x86_64/$artifact
38         then
39             mv $results_dir/repo/$artifact $results_dir/repo/duplicates/
40         fi
41     done
42
43 #List all SRPMs available in Nexus and move the duplicates
44 for artifact in \
45   `ls $results_dir/src_repo`
46     do
47         if curl --head --fail $nexus_repo_url/$release_path/rpms/Sources/$artifact
48         then
49             mv $results_dir/src_repo/$artifact $results_dir/src_repo/duplicates/
50         fi
51     done
52
53 mkdir -p "$x86_dir"
54 mkdir -p "$sources_dir"
55
56 cp "$results_dir/repo/"*.rpm "$x86_dir"
57 cp "$results_dir/src_repo/"*.rpm "$sources_dir"
58
59 echo "-----> Upload RPMs to Nexus"
60 lftools deploy nexus "$nexus_repo_url" "$repo_dir"
61
62 set +x  # Disable trace since we no longer need it.
63 echo "RPMs location: <a href=\"$nexus_repo_url\">$nexus_repo_url</a>"