| #!/bin/bash |
| |
| ############################################################################### |
| # 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 access rights to allow all members of the group to edit the files |
| function setAccessRights() { |
| $SSH $sshGenie@$sshRemote chmod -R 775 "$1" |
| $SSH $sshGenie@$sshRemote chgrp -hR modeling.mdt.papyrus "$1" |
| } |
| |
| ########### Get Zip ########### |
| # This function fetches and test the zip |
| function getZip() { |
| _zipName=$1 |
| _jenkinsBaseURL=$2 |
| |
| [[ "$_zipName" =~ ^.*?\.zip$ ]] || { echo "incorrect parameter: zipName"; exit 1; } |
| |
| # 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" |
| } |
| |
| ########### 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" |
| |
| # from now on, display executed commands |
| set -x |
| |
| 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 |
| |
| 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" |
| |
| 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 |
| |
| # ============================== 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 |
| |
| # Create eclipse target directory |
| eclipseTargetDir=$UPDATE_SITES_DIR/$eclipseTarget |
| $SSH $sshGenie@$sshRemote mkdir -p "$eclipseTargetDir" |
| # Clean generated files |
| cleancompositesandreadme |
| |
| # Create the composite files |
| if [ "$publishP2" = "y" ]; then |
| newTimeStamp=$(date +%s000) |
| p2relativeDir="location=\"../releases/${version}/p2\"/>" |
| compArt=$eclipseTargetDir/compositeArtifacts.xml |
| |
| 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 |
| |
| 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-$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="${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 compositeContent.xml $sshGenie@$sshRemote:$eclipseTargetDir/compositeContent.xml |
| |
| fi |
| |
| 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 |
| |
| ## 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." |