You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@archiva.apache.org by ma...@apache.org on 2018/11/04 14:31:27 UTC

[archiva] 01/04: Adding git site build changes for archiva-docs

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

martin_s pushed a commit to branch feature/site-git-migration
in repository https://gitbox.apache.org/repos/asf/archiva.git

commit d29ac49e8068689b5f8458f7886167d9e8fa179c
Author: Martin Stockhammer <ma...@apache.org>
AuthorDate: Sun Nov 4 13:33:23 2018 +0100

    Adding git site build changes for archiva-docs
---
 archiva-docs/checkoutSite.sh             | 135 +++++++++++++++++++++++++++++++
 archiva-docs/git-sparse-checkout-pattern |   1 +
 archiva-docs/pom.xml                     |  66 ++++++++++++++-
 3 files changed, 200 insertions(+), 2 deletions(-)

diff --git a/archiva-docs/checkoutSite.sh b/archiva-docs/checkoutSite.sh
new file mode 100755
index 0000000..5e582bd
--- /dev/null
+++ b/archiva-docs/checkoutSite.sh
@@ -0,0 +1,135 @@
+#!/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.
+#
+#  Author: Martin Stockhammer <ma...@apache.org>
+#  Date:   2018-11-03
+#
+# This script runs a sparse git clone of a remote repository and
+# initializes the git configuration.
+#
+# It is mainly used for site content creation, because the main archiva-web-content repository
+# is rather large and we don't want to checkout the complete data.
+#
+
+SITE_DIR=".site-content"
+GIT_REMOTE=""
+
+GIT_USER=$(git config user.name)
+GIT_EMAIL=$(git config user.email)
+
+GIT_PATTERN_FILE="git-sparse-checkout-pattern"
+GIT_PATTERN_DEST=".git/info/sparse-checkout"
+
+MY_PWD=$(pwd)
+
+CLONE=1
+FORCE=1
+MODULE_DIR="${MY_PWD}"
+PATTERN=""
+while [ ! -z "$1" ]; do
+  case "$1" in
+    -f) 
+      FORCE=0
+      shift
+      ;;
+    -d)
+      shift
+      SITE_DIR="$1"
+      shift
+      ;;
+    -p)
+      shift
+      if [ -z "${PATTERN}" ]; then
+        PATTERN="${1}"
+      else
+        PATTERN="${PATTERN}\n${1}"
+      fi
+      shift
+      ;;
+    -m)
+      shift
+      MODULE_DIR="$1"
+      shift
+      ;;
+    *)
+      GIT_REMOTE="$1"
+      shift
+      ;; 
+  esac
+done
+
+print_usage() {
+  echo "checkoutRepo [-m MODULE_DIR] [-d SITE_DIR]  [-f] GIT_URL"
+  echo " -m: The module directory where the pattern file can be found and the site dir will be created."
+  echo " -d SITE_DIR: Use the given directory for checkout"
+  echo " -f: Force clone, even if directory exists"
+}
+
+if [ ! -f "${MODULE_DIR}/pom.xml" ]; then
+  echo "Looks like the working directory is not a valid dir. No pom.xml found."
+  exit 1
+fi
+
+cd "${MODULE_DIR}" || { echo "Could not change to module directory ${MODULE_DIR}"; exit 1; }
+
+if [ -z "$GIT_REMOTE" ]; then
+  print_usage
+  exit 1
+fi
+
+if [ "${GIT_REMOTE:0:8}" == "scm:git:" ]; then
+  GIT_REMOTE="${GIT_REMOTE:8}"
+fi
+
+
+if [ -d "${SITE_DIR}" ]; then
+  if [ ! -d "${SITE_DIR}/.git" ]; then
+    echo "Directory ${SITE_DIR} exist already, but is not a git clone. Aborting."
+    exit 1
+  elif [ "$FORCE" -eq 0 ]; then
+    CLONE=0
+  fi
+else
+  CLONE=0
+fi
+
+if [ $CLONE -eq 0 ]; then
+  git clone "${GIT_REMOTE}" "${SITE_DIR}" --no-checkout
+  if [ $? -ne 0 ]; then
+    echo "Git clone failed"
+    exit 1
+  fi
+fi
+
+cd "${SITE_DIR}" || { echo "Could not change to site dir ${SITE_DIR}"; exit 1; }
+
+git config core.sparsecheckout true
+git config user.name "${GIT_USER}"
+git config user.email "${GIT_EMAIL}"
+
+if [ ! -z "${PATTERN}" ]; then
+    echo -e "${PATTERN}" >"${GIT_PATTERN_DEST}"
+elif [ -f "../${GIT_PATTERN_FILE}" ]; then
+  cp "../${GIT_PATTERN_FILE}" "${GIT_PATTERN_DEST}"
+fi
+
+git checkout --
+
+cd "${MY_PWD}"
+
diff --git a/archiva-docs/git-sparse-checkout-pattern b/archiva-docs/git-sparse-checkout-pattern
new file mode 100644
index 0000000..2f88269
--- /dev/null
+++ b/archiva-docs/git-sparse-checkout-pattern
@@ -0,0 +1 @@
+/docs
diff --git a/archiva-docs/pom.xml b/archiva-docs/pom.xml
index 59d935b..f7d70cf 100644
--- a/archiva-docs/pom.xml
+++ b/archiva-docs/pom.xml
@@ -34,6 +34,8 @@
     <scmPubCheckoutDirectory>${basedir}/.site-content</scmPubCheckoutDirectory>
     <maven.build.timestamp.format>yyyy-MM-dd</maven.build.timestamp.format>
     <releaseDate>${maven.build.timestamp}</releaseDate>
+    <!-- The git repository, where the site content is placed -->
+    <siteRepositoryUrl>scm:git:https://gitbox.apache.org/repos/asf/archiva-web-content-INVALID.git</siteRepositoryUrl>
   </properties>
 
   <build>
@@ -55,10 +57,25 @@
     </pluginManagement>
     <plugins>
       <plugin>
+        <!--
+        SCM Publish plugin.
+             We deactivated the deletion, because the patterns for ignorePathsToDelete does only use the file/directory names
+             not the relative paths.
+             Site plugin is deploying into the subdirectory docs/${project.version} the publish plugin is copying from
+             target directly.
+        -->
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-scm-publish-plugin</artifactId>
         <configuration>
-          <checkinComment>Apache Archiva Versionned docs for ${project.version}</checkinComment>
+          <checkinComment>Apache Archiva Versioned docs for ${project.version}</checkinComment>
+          <skipDeletedFiles>true</skipDeletedFiles>
+          <content>${project.build.directory}/staging</content>
+          <tryUpdate>true</tryUpdate>
+<!--
+          <ignorePathsToDelete>
+            <path>%regex[^(?!docs/).*$]</path>
+          </ignorePathsToDelete>
+-->
         </configuration>
         <executions>
           <execution>
@@ -75,6 +92,7 @@
         <artifactId>maven-site-plugin</artifactId>
         <configuration>
           <skipDeploy>true</skipDeploy>
+          <stagingDirectory>${project.build.directory}/staging/docs/${project.version}/</stagingDirectory>
         </configuration>
         <executions>
           <execution>
@@ -155,8 +173,52 @@
   <distributionManagement>
     <site>
       <id>apache.website</id>
-      <url>scm:svn:https://svn.apache.org/repos/asf/archiva/site-content/docs/${project.version}</url>
+      <url>${siteRepositoryUrl}</url>
     </site>
   </distributionManagement>
 
+  <profiles>
+    <!--
+    This runs a sparse git checkout for the web site content repository that contains only the doc directory.
+    The profile is activated only, if the checkout directory does not exist.
+    The executor runs a shell script.
+    -->
+    <profile>
+      <id>site-checkout</id>
+      <activation>
+        <file>
+          <missing>${scmPubCheckoutDirectory}</missing>
+        </file>
+      </activation>
+      <build>
+        <plugins>
+          <plugin>
+            <groupId>org.codehaus.mojo</groupId>
+            <artifactId>exec-maven-plugin</artifactId>
+            <version>1.6.0</version>
+            <executions>
+              <execution>
+                <id>prepare-checkout</id>
+                <phase>pre-site</phase>
+                <goals>
+                  <goal>exec</goal>
+                </goals>
+                <configuration>
+                  <executable>checkoutSite.sh</executable>
+                  <workingDirectory>${project.basedir}</workingDirectory>
+                  <arguments>
+                    <argument>-d</argument>
+                    <argument>${scmPubCheckoutDirectory}</argument>
+                    <argument>${siteRepositoryUrl}</argument>
+                  </arguments>
+                </configuration>
+              </execution>
+            </executions>
+          </plugin>
+        </plugins>
+      </build>
+    </profile>
+  </profiles>
+
+
 </project>