[Releng] update publish.sh
Change-Id: I211761ae1eab01144f9d99d0f9546e60e8aa9fff
Signed-off-by: Patrick <Patrick.Tessier@cea.fr>
diff --git a/releng/scripts/publish.sh b/releng/scripts/publish.sh
index f1d174f..8d34943 100755
--- a/releng/scripts/publish.sh
+++ b/releng/scripts/publish.sh
@@ -1,173 +1,246 @@
-#!/bin/sh
-alias ll="ls -la"
+#!/bin/bash
-########### Parameters Check ###########
-if [[ -v $PROMOTED_JOB_NAME ]] || [[ -v $PROMOTED_JOB_NUMBER ]] || [[ -v $MILESTONE ]] || [[ -v $RELEASE_NUMBER ]] || [[ -v $OVERRIDE ]] ; then
- echo "The script must set to the following parameters:
- - PROMOTED_JOB_NAME, found: $PROMOTED_JOB_NAME,
- - PROMOTED_JOB_NUMBER, found: $PROMOTED_JOB_NUMBER,
- - MILESTONE, found: $MILESTONE,
- - RELEASE_NUMBER, found: $RELEASE_NUMBER,
- - OVERRIDE, found: $OVERRIDE"
-
- exit 1;
-fi
+###############################################################################
+# Copyright (c) 2012-2021 CEA LIST and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Eclipse Public License 2.0
+# which accompanies this distribution, and is available at
+# https://www.eclipse.org/legal/epl-2.0/
+#
+# SPDX-License-Identifier: EPL-2.0
+#
+# Contributors:
+# Nicolas Bros (Mia-Software) - Initial API and implementation
+# Quentin Le Menez (CEA LIST) - Support for the new Papyrus architecture
+# Ansgar Radermacher - Adaptation to Papyrus relatives/components
+# Pauline Deville - Adapt to the new architecture
+#
+###############################################################################
+
+sshGenie="genie.papyrus"
+sshRemote="projects-storage.eclipse.org"
+SSH=ssh
+SCP=scp
+
+UPDATE_SITES_DIR=/home/data/httpd/download.eclipse.org/modeling/mdt/papyrus/components/$componentName
+PAPYRUS_CMPDWL=https://download.eclipse.org/modeling/mdt/papyrus/components/
+
+# enable the job defined parameters
+#env >/dev/null
########### Set Access Rights ###########
-# This function sets the acess rights to allow all memebers of the group to edit the files
+# This function sets the access rights to allow all members of the group to edit the files
function setAccessRights() {
- chmod -R 775 "$1"
- chgrp -hR modeling.mdt.papyrus "$1"
+ $SSH $sshGenie@$sshRemote chmod -R 775 "$1"
+ $SSH $sshGenie@$sshRemote chgrp -hR modeling.mdt.papyrus "$1"
}
-########### Parameters Initialization ###########
+########### Get Zip ###########
+# This function fetches and test the zip
+function getZip() {
+ _zipName=$1
+ _jenkinsBaseURL=$2
-#The specific localization
-remoteRoot="/home/data/httpd/download.eclipse.org"
-requirementsRoot="modeling/mdt/papyrus/components/requirements"
+ [[ "$_zipName" =~ ^.*?\.zip$ ]] || { echo "incorrect parameter: zipName"; exit 1; }
-if [[ "$MILESTONE" == "-R" ]] ; then
- destination=$remoteRoot/$requirementsRoot/release-$RELEASE_NUMBER
- destinationUpdateSite=$destination
-else
- destination=$remoteRoot/$requirementsRoot/milestones-$RELEASE_NUMBER
- destinationUpdateSite=$destination/$RELEASE_NUMBER$MILESTONE
-fi
-echo $destinationUpdateSite
+ # Use the Jenkins REST API
+ # see https://www.jenkins.io/doc/book/using/remote-access-api/
+ wget --no-check-certificate "$_jenkinsBaseURL/${_zipName}"
+ if [ ! -f "$_zipName" ]; then echo "ERROR: $_zipName (from Jenkins) not found"; exit -2; fi
+ echo "[$(date +%Y%m%d-%H%M)] Testing zip integrity"
+ unzip -t "$_zipName"
+}
-jobArtifacts=$HOME/.jenkins/jobs/$PROMOTED_JOB_NAME/builds/$PROMOTED_JOB_NUMBER/archive
-if [ ! -d $jobArtifacts ] ; then
- echo "No artifact folder was found under the specified $jobArtifacts path"
- exit 1
-fi
-
-echo "$jobArtifacts contains the following :"
-ls $jobArtifacts
-
-if [ -d $destination ] ; then
- if [ -d $destinationUpdateSite ] ; then
- if $OVERRIDE ; then
- echo "Removing previous artifacts"
- rm -rf $destinationUpdateSite
- else
- echo "The milestone already exists. You might want to change the suffix or delete the previous one."
- exit 1
- fi
+########### Clean Composites ###########
+# This function cleans local job composite if necessary
+function cleancompositesandreadme () {
+ if [ -f compositeArtifacts.xml ] ; then
+ rm -f compositeArtifacts.xml
fi
+ if [ -f compositeContent.xml ] ; then
+ rm -f compositeContent.xml
+ fi
+ if [ -f readme.md ] ; then
+ rm -f readme.md
+ fi
+}
+
+# ============================== USER PARAMETERS ==============================
+echo "-------------------- check parameters --------------------"
+if [[ ! ("$buildId" =~ ^[0-9]+$ || "$buildId" < 1) && (! $buildId =~ "lastSuccessfulBuild") ]]; then
+ echo "buildId (CI build from which to publish the plug-ins) must be a integer (only digits) or lastSuccessfulBuild"
+ echo "Canceled."; exit 1
fi
+echo "-------------------- initialized parameters --------------------"
+echo "componentName: $componentName"
+echo "buildId: $buildId"
+echo "version: $version"
+echo "buildJob: $buildJob"
+echo "eclipseTarget: $eclipseTarget"
+echo "overwrite: $overwrite"
+echo "publishRCP: $publishRCP"
+echo "publishP2: $publishP2"
-########### Publish Artifacts ###########
-#Go to the artifact directory
-cd $jobArtifacts
+# from now on, display executed commands
+set -x
-# Check the availability of the artifacts to promote before creating anything
-if [ ! -f Papyrus-Requirements.zip ] ; then
- echo "There is no Papyrus-Requirements.zip here."
- pwd
- ll
- exit 1
-fi
-if [ ! -d repository ] ; then
- echo "There is no repository directory here."
- pwd
- ll
- exit 1
+dirBefore=$(pwd)
+echo "[$DATE] creating working dir"
+workingDir=$(mktemp -d)
+cd "$workingDir"
+
+
+if [ "$publishRCP" = "y" ]; then
+# ========================== fetch zip of all RCPs ================================
+ echo fetching RCPs
+ ciURL="https://ci.eclipse.org/papyrus/job/$buildJob/$buildId/artifact/products/*zip*"
+ zipName="products.zip"
+ getZip "$zipName" "$ciURL"
+ if [ ! -f "$zipName" ]; then
+ echo "ERROR: $zipName (from CI server) not found";
+ exit -2;
+ fi
+ ls -la
+
+# ============================== publish RCPs =====================================
+ rcpDir=$UPDATE_SITES_DIR/releases/$version/rcps
+ if [ -d "$rcpDir" ]; then
+ if [ "$overwrite" != "y" ]; then
+ echo "The RCP already exists under: ${rcpDir}, canceling job."; exit 1
+ fi
+ echo "Overwrite set to true, replacing published rcp."
+ fi
+ $SSH $sshGenie@$sshRemote rm -fr "$rcpDir"
+
+ echo "publishing RCPs (version='$version') to directory '$rcpDir'"
+ $SSH $sshGenie@$sshRemote mkdir -p "$rcpDir"
+ $SCP $zipName $sshGenie@$sshRemote:/$rcpDir
+ $SSH $sshGenie@$sshRemote unzip -o "$rcpDir/$zipName" -d "$rcpDir"
+ $SSH $sshGenie@$sshRemote rm -f "$rcpDir/$zipName"
+ rm -f $zipName
fi
-echo "Promoting the Job to $destinationUpdateSite"
+if [ "$publishP2" = "y" ]; then
+# ============================ fetch update site ==================================
+ p2Dir=$UPDATE_SITES_DIR/releases/$version/p2
+ if [ -d "$p2Dir" ]; then
+ if [ "$overwrite" != "y" ]; then
+ echo "The update site already exists under: ${p2Dir}, canceling job."; exit 1
+ fi
+ echo "Overwrite set to true, replacing published p2."
+ fi
+ $SSH $sshGenie@$sshRemote rm -fr "$p2Dir"
-#No error if exists, makes parent directories as needed
-echo "creating $destinationUpdateSite"
-mkdir -p $destinationUpdateSite
+ echo fetching update-site
+ ciURL="https://ci.eclipse.org/papyrus/job/$buildJob/$buildId/artifact/repository/*zip*/"
+ zipName="updatesite.zip"
+ getZip "$zipName" "$ciURL"
+ if [ ! -f "$zipName" ]; then
+ echo "ERROR: $zipName (from CI server) not found";
+ exit -2;
+ fi
+ ls -la
-if [ ! -d $destinationUpdateSite ] ; then
- echo "The destination folder could not be created. Please look why in the logs."
- exit 1
+# ============================== PUBLISH update site ==============================
+ echo "publishing version='$version' to the repository directory '$p2Dir'..."
+ $SSH $sshGenie@$sshRemote mkdir -p "$p2Dir"
+ $SCP $zipName $sshGenie@$sshRemote:/$p2Dir
+ $SSH $sshGenie@$sshRemote unzip -o "$p2Dir/$zipName" -d "$p2Dir"
+ $SSH $sshGenie@$sshRemote mv "$p2Dir/repository/*" "$p2Dir"
+ $SSH $sshGenie@$sshRemote rmdir "$p2Dir/repository/"
+ $SSH $sshGenie@$sshRemote rm -f "$p2Dir/$zipName"
+ rm -f $zipName
fi
-#Copy the contents onto the server folder
-echo "copying the zip into $destinationUpdateSite"
-cp Papyrus-Requirements.zip $destinationUpdateSite
+# Create eclipse target directory
+eclipseTargetDir=$UPDATE_SITES_DIR/$eclipseTarget
+$SSH $sshGenie@$sshRemote mkdir -p "$eclipseTargetDir"
+# Clean generated files
+cleancompositesandreadme
-echo "copying the p2 repository folder into $destinationUpdateSite"
-cp -r repository $destinationUpdateSite
+# Create the composite files
+if [ "$publishP2" = "y" ]; then
+ newTimeStamp=$(date +%s000)
+ p2relativeDir="location=\"../releases/${version}/p2\"/>"
+ compArt=$eclipseTargetDir/compositeArtifacts.xml
-
-# create the composite update site
-newTimeStamp=$(date +%s000)
-
-cat > "$destinationUpdateSite/compositeArtifacts.xml" <<EOF
-<?xml version="1.0" encoding="UTF-8"?>
-<repository name="Papyrus" type="org.eclipse.equinox.internal.p2.artifact.repository.CompositeArtifactRepository" version="1.0.0">
- <properties size="1">
- <property name="p2.timestamp" value="${newTimeStamp}"/>
- </properties>
- <children size="1">
- <child location="repository"/>
- </children>
-</repository>
-EOF
-
-cat > "$destinationUpdateSite/compositeContent.xml" <<EOF
-<?xml version="1.0" encoding="UTF-8"?>
-<repository name="Papyrus" type="org.eclipse.equinox.internal.p2.metadata.repository.CompositeMetadataRepository" version="1.0.0">
- <properties size="1">
- <property name="p2.timestamp" value="${newTimeStamp}"/>
- </properties>
- <children size="1">
- <child location="repository"/>
- </children>
-</repository>
-EOF
-
-
-if [[ "$MILESTONE" != "-R" ]] ; then
-
-# create the composite update site for the update site root folder
-updateSiteChildren=$(($(find $destinationUpdateSite/.. -maxdepth 1 -type d -print | wc -l)-1))
-
-# Update the releaseRoot composites
-cat > "$destinationUpdateSite/../compositeContent.xml" <<EOF
-<?xml version="1.0" encoding="UTF-8"?>
-<repository name="Papyrus" type="org.eclipse.equinox.internal.p2.artifact.repository.CompositeArtifactRepository" version="1.0.0">
- <properties size="1">
- <property name="p2.timestamp" value="${newTimeStamp}"/>
- </properties>
- <children size="${updateSiteChildren}">$(
- for folder in $destinationUpdateSite/../*; do
- if [[ -d ${folder} ]] ; then
- printf "\n <child location='$(basename ${folder})'/>"
- fi
+ if [ -f $compArt ]; then
+ # If there are existing composites, count existing children and add their location to an array
+ childCount=$(($($SSH $sshGenie@$sshRemote grep -s "child location" $compArt | wc -l)+1))
+ childArray=($($SSH $sshGenie@$sshRemote grep -s "location=" $compArt | sed -s "s/<child //" | sed "s/'/\"/g"))
+ # Detect already present directories and decrement if necessary
+ for child in "${childArray[@]}" ; do
+ if [ "$child" = "$p2relativeDir" ]; then
+ alreadyExists=true
+ ((childCount=childCount-1))
+ fi
done
+ else
+ # New composite, hence there are only one child
+ childCount=1
+ childArray=()
+ fi
+ cat > compositeArtifacts.xml <<EOF
+<?xml version="1.0" encoding="UTF-8"?>
+<repository name="Papyrus-$componentName" type="org.eclipse.equinox.internal.p2.artifact.repository.CompositeArtifactRepository" version="1.0.0">
+ <properties size="1">
+ <property name="p2.timestamp" value="${newTimeStamp}"/>
+ </properties>
+ <children size="${childCount}">$(
+ for child in "${childArray[@]}" ; do
+ printf "\n <child $child"
+ done
+ )$(
+ if [[ -z ${alreadyExists+x} ]] ; then
+ printf "\n <child $p2relativeDir"
+ fi
)
</children>
</repository>
EOF
+ $SCP compositeArtifacts.xml $sshGenie@$sshRemote:$eclipseTargetDir/compositeArtifacts.xml
-cat > "$destinationUpdateSite/../compositeArtifacts.xml" <<EOF
+ compCont=$eclipseTargetDir/compositeContent.xml
+ if [ -f $compCont ]; then
+ # The children and their location should be the same as the compositeArtifacts
+ :
+ else
+ # The children and their location should be the same as the compositeArtifacts
+ :
+ fi
+ cat > compositeContent.xml <<EOF
<?xml version="1.0" encoding="UTF-8"?>
-<repository name="Papyrus" type="org.eclipse.equinox.internal.p2.metadata.repository.CompositeMetadataRepository" version="1.0.0">
+<repository name="Papyrus-$componentName" type="org.eclipse.equinox.internal.p2.metadata.repository.CompositeMetadataRepository" version="1.0.0">
<properties size="1">
<property name="p2.timestamp" value="${newTimeStamp}"/>
</properties>
- <children size="${updateSiteChildren}">$(
- for folder in $destinationUpdateSite/../*; do
- if [[ -d ${folder} ]] ; then
- printf "\n <child location='$(basename ${folder})'/>"
- fi
+ <children size="${childCount}">$(
+ for child in "${childArray[@]}" ; do
+ printf "\n <child $child"
done
+ )$(
+ if [[ -z ${alreadyExists+x} ]] ; then
+ printf "\n <child $p2relativeDir"
+ fi
)
</children>
</repository>
EOF
-
-echo "Set access right -R: $destinationUpdateSite/.."
-setAccessRights "$destinationUpdateSite/.."
+ $SCP compositeContent.xml $sshGenie@$sshRemote:$eclipseTargetDir/compositeContent.xml
fi
-echo "Set access right -R: $destinationUpdateSite"
-setAccessRights $destinationUpdateSite
+echo "# Welcome to the $eclipseTarget release of $componentName
+## P2 repository
+If there is an update site associated to this release, it can be found in the **p2** folder at:
+$PAPYRUS_CMPDWL/$componentName/releases/$version
-echo "publishing done."
+## RCP files
+If there are RCP files associated to this release, they can be found in the **rcps** folder at:
+$PAPYRUS_CMPDWL/$componentName/releases/$version" > readme.md
+$SCP readme.md $sshGenie@$sshRemote:$eclipseTargetDir
+
+setAccessRights "$UPDATE_SITES_DIR"
+echo "publishing done."
\ No newline at end of file