Skip to content

Commit

Permalink
[incubator-kie-issues#828] Create zip files for source code
Browse files Browse the repository at this point in the history
Add bash script that creates zip files with sources as required by Apache
  • Loading branch information
cimbalek committed May 23, 2024
1 parent 111bfb3 commit 086b284
Showing 1 changed file with 91 additions and 0 deletions.
91 changes: 91 additions & 0 deletions .ci/jenkins/scripts/bash/zip-sources-all.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
#!/bin/bash

# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

### MANDATORY VARIABLES DEFINITION - UNCOMMENT FOR LOCAL USE ###
### In Jenkins these VARIABLES are set as jenkins job parameters ###

#VERSION="10.0.0"
#BRANCH_DEFAULT="main"
#REPO_ORGANIZATION="apache"
#
## Configuration in format "repository_name;branch(if-override-needed)"
## - eg.not all repositories have main branch
#REPOSITORIES="incubator-kie-drools
#incubator-kie-kogito-runtimes
#incubator-kie-kogito-apps
#incubator-kie-kogito-images
#incubator-kie-optaplanner
#incubator-kie-tools
#incubator-kie-sandbox-quarkus-accelerator"

function zip_sources() {
SOURCES_DIRECTORY_NAME="sources"

while read line; do
BRANCH=${BRANCH_DEFAULT}
#get rid of carriage return character if present
line="$(echo $line | sed 's#\r##g')"

#Clone
echo "Clone $( echo $line | awk -F';' '{ print $1 }' | sed 's\incubator-\\g' )"
REPO_NAME=$( echo $line | awk -F';' '{print $1 }' )
REPO_DIRECTORY=${SOURCES_DIRECTORY_NAME}/${REPO_NAME}
#Leaving branch specifying functionality here in case we need to specify branch for any repo in the future
REPO_BRANCH=$( echo $line | awk -F';' '{print $2}' )
if [[ ! -z ${REPO_BRANCH} ]]; then
BRANCH=$REPO_BRANCH
fi
git clone --branch ${BRANCH} --depth 1 "https://github.com/${REPO_ORGANIZATION}/${REPO_NAME}.git" ${REPO_DIRECTORY}
STATE=$?
if [[ ${STATE} != 0 ]]; then
echo "Clonning of ${REPO_NAME} was NOT successfull. Failing"
exit 1
fi

#Remove unnecessary dirs
pushd $REPO_DIRECTORY
CURRENT_DIRECTORY=$(pwd)
echo "Current directory is ${CURRENT_DIRECTORY}"
echo "Before .git removal"
ls -lha
echo "Searching for .git directory"
if [[ -d '.git' ]]; then
echo ".git directory found, deleting..."
rm -rf ".git"
fi
echo "After .git removal"
ls -lha
popd

done <<< $REPOSITORIES

#Creating ZIP
pushd ${SOURCES_DIRECTORY_NAME}
ZIP_FILE_NAME="incubator-kie-${VERSION}-sources.zip"
echo "Creating ${ZIP_FILE_NAME}"
zip -ry ${ZIP_FILE_NAME} *
if [[ ! -f ${ZIP_FILE_NAME} ]]; then
echo "${ZIP_FILE_NAME} has not been created."
exit 2
fi
ls -lha ${ZIP_FILE_NAME}
popd
}

zip_sources

0 comments on commit 086b284

Please sign in to comment.