Browse Source

Update tamarin handler with the last production version

develop
Philippe Caseiro 1 year ago
parent
commit
8e1b590f61
1 changed files with 76 additions and 13 deletions
  1. 76
    13
      handlers/build-package-with-tamarin

+ 76
- 13
handlers/build-package-with-tamarin View File

@@ -1,7 +1,6 @@
1 1
 #!/usr/bin/env bash
2 2
 
3 3
 set -e
4
-#set -x
5 4
 
6 5
 # build-package-from-git - Job handler for Marang
7 6
 # Author: Willam Petit <wpetit@cadoles.com>
@@ -52,7 +51,7 @@ mkdir -p "$workdir/dist"
52 51
 # Extract project info
53 52
 project_name=$(get_payload_opt ".repository.name" | tr '[:upper:]' '[:lower:]')
54 53
 repo_url=$(get_payload_opt ".repository.clone_url")
55
-commit=$(get_payload_opt ".commits | .[0] | .id")
54
+commit=$(get_payload_opt ".ref")
56 55
 
57 56
 # Fetch project sources
58 57
 GIT_SSL_NO_VERIFY=true git clone "$repo_url" "$project_name"
@@ -82,17 +81,81 @@ git submodule update
82 81
 
83 82
 echo "Building package..."
84 83
 
85
-# Build package with Tamarin for specified distrib
86
-"$TAMARIN_PATH/package" -p "$workdir/$project_name" -d "$workdir/dist" -i "$DISTRIB"
87
-
88
-# Copy debian packages to destination directory if arguments is specified
89
-if [ ! -z $OUTPUT_DIR ]; then
90
-  DEST_DIR="$OUTPUT_DIR/$LIMIT_TO_BRANCH/$project_name"
91
-  mkdir -p "$DEST_DIR"
92
-  echo "Copying packages to $DEST_DIR/..."
93
-  cp $workdir/dist/*.deb "$DEST_DIR/"
94
-else
95
-  echo "No output directory specified."
84
+# Build on package per version
85
+set +e
86
+COMMIT_TAGS=$(git describe --exact-match --abbrev=0) #git tag -l --contains HEAD | grep "^pkg")
87
+set -e
88
+if [[ -z ${COMMIT_TAGS} ]]
89
+then
90
+   echo "Nothing to build :"
91
+   echo "   - No build build tags on last commit"
92
+   clean_workspace
93
+   exit
96 94
 fi
97 95
 
96
+for tag in ${COMMIT_TAGS}
97
+do
98
+   PACKAGE_ENV=$(echo ${tag} | cut -d '/' -f 2)
99
+   PACKAGE_DISTRIB=$(echo ${tag} | cut -d '/' -f 3)
100
+   PKGVERSION=$(echo ${tag} | cut -d '/' -f 4)
101
+
102
+   # Setting package version
103
+   [[ -z ${PKGVERSION} ]] && PKGVERSION="NO-VERSION"
104
+
105
+   cd ${workdir}/${project_name}
106
+   tamarinrc="${workdir}/${project_name}/.tamarinrc"
107
+   [[ ! -f ${tamarinrc} ]] && touch ${tamarinrc}
108
+   set +e
109
+   grep -q "^project_version=.*" ${tamarinrc}
110
+   if [[ ${?} -eq 0 ]]
111
+   then
112
+      sed -i -e "s/^project_version=.*/project_version=${PKGVERSION}/" ${workdir}/${project_name}/.tamarinrc
113
+   else
114
+      echo "project_version=${PKGVERSION}" > ${tamarinrc}
115
+   fi
116
+   
117
+   if [[ ${PACKAGE_ENV} =~ ^(staging|stable) ]]
118
+   then
119
+      grep -q "^no_version_suffix=.*" ${tamarinrc}
120
+      if [[ ${?} -eq 0 ]]
121
+      then
122
+         sed -i -e "s/no_version_suffix=.*/no_version_suffix=yes/" ${tamarinrc}
123
+      else
124
+      	 echo "no_version_suffix=yes" >> ${tamarinrc}
125
+      fi
126
+   fi
127
+   set -e
128
+
129
+   # Build package with Tamarin for specified distrib
130
+   echo
131
+   echo "Building package with $TAMARIN_PATH/package (${tag})"
132
+   echo
133
+   "$TAMARIN_PATH/package" "$workdir/$project_name" -o "$workdir/dist" -b "$DISTRIB"
134
+
135
+  # Copy debian packages to destination directory if arguments is specified
136
+   if [ ! -z $OUTPUT_DIR ]; then
137
+      DEST_DIR="$OUTPUT_DIR/$LIMIT_TO_BRANCH/$project_name"
138
+      mkdir -p "$DEST_DIR"
139
+      echo "Copying packages to $DEST_DIR/..."
140
+      cp $workdir/dist/*.deb "$DEST_DIR/"
141
+   else
142
+     echo "No output directory specified."
143
+   fi
144
+
145
+   # Deploy packages automatically based on tags
146
+  
147
+   # Check that the package environment matches the expected ones
148
+   if [[ "$PACKAGE_ENV" =~ ^(dev|staging|stable)$ ]]; then
149
+      echo
150
+      echo "Pushing packages to matching '$PACKAGE_ENV' repository ..."
151
+      echo
152
+      ssh aptly@vulcain.cadoles.com mkdir -p "/home/aptly/packages/$PACKAGE_ENV/$LIMIT_TO_BRANCH"
153
+      scp -r $workdir/dist/*.deb "aptly@vulcain.cadoles.com:/home/aptly/packages/$PACKAGE_ENV/$LIMIT_TO_BRANCH/"
154
+      echo "Cleaning builded package"
155
+      rm -rf $workdir/dist/*
156
+   else
157
+      echo "Packaging tag prefix 'pkg' found but the environment token does not match any of 'dev', 'staging' or 'stable'. Ignoring..."
158
+   fi
159
+done
160
+
98 161
 clean_workspace

Loading…
Cancel
Save