You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kie.apache.org by mc...@apache.org on 2024/07/02 11:11:23 UTC

(incubator-kie-kogito-pipelines) branch main updated: [incubator-kie-issues#828] Create zip files for source code (#1202)

This is an automated email from the ASF dual-hosted git repository.

mcimbalek pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-kie-kogito-pipelines.git


The following commit(s) were added to refs/heads/main by this push:
     new 56fd3f0e [incubator-kie-issues#828] Create zip files for source code (#1202)
56fd3f0e is described below

commit 56fd3f0e49c3da0350aa1e2a36360afe36c082b2
Author: Martin Cimbalek <ci...@gmail.com>
AuthorDate: Tue Jul 2 13:11:19 2024 +0200

    [incubator-kie-issues#828] Create zip files for source code (#1202)
    
    * [incubator-kie-issues#828] Create zip files for source code
    
    Add bash script that creates zip files with sources as required by Apache
    
    * [incubator-kie.issues#828] Add job definition for zip sources job
    
    * Adjust parameters description
    
    Co-authored-by: Jan Stastny <st...@gmail.com>
    
    ---------
    
    Co-authored-by: Jan Stastny <st...@gmail.com>
---
 .ci/jenkins/Jenkinsfile.zip.sources |  55 +++++++++++++++++++
 .ci/jenkins/dsl/jobs.groovy         |  38 +++++++++++++
 tools/zip-sources-all.sh            | 103 ++++++++++++++++++++++++++++++++++++
 3 files changed, 196 insertions(+)

diff --git a/.ci/jenkins/Jenkinsfile.zip.sources b/.ci/jenkins/Jenkinsfile.zip.sources
new file mode 100644
index 00000000..011835fc
--- /dev/null
+++ b/.ci/jenkins/Jenkinsfile.zip.sources
@@ -0,0 +1,55 @@
+import org.jenkinsci.plugins.workflow.libs.Library
+
+@Library('jenkins-pipeline-shared-libraries')_
+
+pipeline {
+    agent {
+        label util.avoidFaultyNodes()
+    }
+
+    environment {
+        SOURCES_FILE_NAME = "${SOURCES_FILE_NAME_TEMPLATE}.zip"
+        SIGNATURE_FILE_NAME = "${SOURCES_FILE_NAME_TEMPLATE}.asc"
+    }
+
+    options {
+        timeout(time: 120, unit: 'MINUTES')
+    }
+
+    stages {
+        stage('Create sources ZIP') {
+            steps {
+                sh "tools/zip-sources-all.sh ${SOURCES_FILE_NAME}"
+                archiveArtifacts artifacts: "**/${SOURCES_FILE_NAME}"
+            }
+        }
+//        stage('Sign and upload the sources.zip') {
+//            steps {
+//                script {
+//                    // TODO: Uncomment (and adjust) when we have required credentials available
+//                    release.gpgImportKeyFromFileWithPassword(getReleaseGpgSignKeyCredsId(), getReleaseGpgSignPassphraseCredsId())
+//                    release.gpgSignFileDetachedSignatureWithPassword(SOURCES_FILE_NAME, SIGNATURE_FILE_NAME, getReleaseGpgSignPassphraseCredsId())
+//                    release.svnUploadFileToRepository(getReleaseSvnRepository(), getReleaseSvnCredsId(), TARGET_VERSION, SOURCES_FILE_NAME, SIGNATURE_FILE_NAME)
+//                }
+//                archiveArtifacts artifacts: "**/${SIGNATURE_FILE_NAME}"
+//            }
+//        }
+    }
+}
+
+
+String getReleaseGpgSignKeyCredsId() {
+    return env.RELEASE_GPG_SIGN_KEY_CREDS_ID
+}
+
+String getReleaseGpgSignPassphraseCredsId() {
+    return env.RELEASE_GPG_SIGN_PASSPHRASE_CREDS_ID
+}
+
+String getReleaseSvnRepository() {
+    return env.RELEASE_SVN_REPOSITORY
+}
+
+String getReleaseSvnCredsId() {
+    return env.RELEASE_SVN_CREDS_ID
+}
\ No newline at end of file
diff --git a/.ci/jenkins/dsl/jobs.groovy b/.ci/jenkins/dsl/jobs.groovy
index 3a850001..ba61db30 100644
--- a/.ci/jenkins/dsl/jobs.groovy
+++ b/.ci/jenkins/dsl/jobs.groovy
@@ -67,6 +67,9 @@ if (isMainStream()) {
 // Release
 setupReleaseArtifactsJob()
 setupReleaseCloudJob()
+if (isMainStream()) {
+    setupZipSourcesJob()
+}
 
 Utils.isMainBranch(this) && KogitoJobTemplate.createBranchMultibranchPipelineJob(this, 'kogito-ci-build-image', "${jenkins_path}/Jenkinsfile.build-kogito-ci-image")
 
@@ -333,3 +336,38 @@ void setupReleaseCloudJob() {
         }
     }
 }
+
+void setupZipSourcesJob() {
+    def jobParams = JobParamsUtils.getBasicJobParams(this, 'zip-and-upload-sources', JobType.TOOLS, "${jenkins_path}/Jenkinsfile.zip.sources", 'Zip sources and upload them into artifactory')
+    jobParams.env.putAll([
+            JENKINS_EMAIL_CREDS_ID: "${JENKINS_EMAIL_CREDS_ID}",
+
+            GIT_BRANCH_NAME: "${GIT_BRANCH}",
+            GIT_AUTHOR: "${GIT_AUTHOR_NAME}",
+
+            IMAGE_REGISTRY_CREDENTIALS: "${CLOUD_IMAGE_REGISTRY_CREDENTIALS}",
+
+            RELEASE_GPG_SIGN_KEY_CREDS_ID: Utils.getReleaseGpgSignKeyCredentialsId(this),
+            RELEASE_GPG_SIGN_PASSPHRASE_CREDS_ID: Utils.getReleaseGpgSignPassphraseCredentialsId(this),
+            RELEASE_SVN_REPOSITORY: Utils.getReleaseSvnCredentialsId(this),
+            RELEASE_SVN_CREDS_ID: Utils.getReleaseSvnStagingRepository(this)
+            ])
+
+    KogitoJobTemplate.createPipelineJob(this, jobParams)?.with {
+        parameters {
+            textParam('SOURCES_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''',
+                    'Configuration of sources repositories to pack. Format: "repository_name;branch(if-override-needed)" -eg. we want to override default sources branch for some repositories.')
+            stringParam('TARGET_VERSION', '10.0.0', 'Version of the resulting artifact which will be mentioned in the artifact name')
+            stringParam('SOURCES_DEFAULT_BRANCH', 'main', 'Branch to check out sources from. Can be overridden in REPOSITORIES definition')
+            stringParam('SOURCES_FILE_NAME_TEMPLATE', 'incubator-kie-${TARGET_VERSION}-sources', 'Filename pattern for the resulting sources archive. Can be parameterized by job parameters or env variables.')
+        }
+    }
+
+}
\ No newline at end of file
diff --git a/tools/zip-sources-all.sh b/tools/zip-sources-all.sh
new file mode 100755
index 00000000..d84f0778
--- /dev/null
+++ b/tools/zip-sources-all.sh
@@ -0,0 +1,103 @@
+#!/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 ###
+
+#TARGET_VERSION="10.0.0"
+#SOURCES_DEFAULT_BRANCH="main"
+#GIT_AUTHOR="apache"
+#
+## Configuration in format "repository_name;branch(if-override-needed)"
+## - eg.not all repositories have main branch
+#SOURCES_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"
+  OUTPUT_DIR="sources-out"
+
+  if [ -d ${SOURCES_DIRECTORY_NAME} ]; then
+    echo "Directory '${SOURCES_DIRECTORY_NAME}' already exists. Deleting..."
+    rm -rf ${SOURCES_DIRECTORY_NAME}
+  fi
+
+  if [ -d ${OUTPUT_DIR} ]; then
+    echo "Directory '${OUTPUT_DIR}' already exists. Deleting..."
+    rm -rf ${OUTPUT_DIR}
+  fi
+
+  while read line; do
+    BRANCH=${SOURCES_DEFAULT_BRANCH}
+    #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/${GIT_AUTHOR}/${REPO_NAME}.git" ${REPO_DIRECTORY}
+    STATE=$?
+    if [[ ${STATE} != 0 ]]; then
+      echo "Cloning ${REPO_NAME} was NOT successful. 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 <<< $SOURCES_REPOSITORIES
+
+  #Creating ZIP
+  pushd ${SOURCES_DIRECTORY_NAME}
+  ZIP_FILE_NAME=$1
+  echo "Creating ${ZIP_FILE_NAME}"
+  mkdir "../${OUTPUT_DIR}"
+  zip -ry "../${OUTPUT_DIR}/${ZIP_FILE_NAME}" *
+  if [[ ! -f "../${OUTPUT_DIR}/${ZIP_FILE_NAME}" ]]; then
+    echo "${ZIP_FILE_NAME} has not been created."
+    exit 2
+  fi
+  ls ../${OUTPUT_DIR}/${ZIP_FILE_NAME}
+  popd
+}
+
+zip_sources $1


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org